module DataMapper::Aspects::Utils
Public Class Methods
included(base)
click to toggle source
# File lib/datamapper/aspects/utils.rb, line 6 def self.included(base) def base.default_sequence_name "#{DataMapper::Inflector.pluralize(self.to_s)}_#{self.serial.name}_seq" end def base.next_id(sequence = default_sequence_name) repository.adapter.select("select nextval('#{sequence}')").first end def base.select_options all(order: [:updated_at.desc]).map do |object| { label: object.name, value: object.send(self.serial.name) } end end end
Public Instance Methods
attributes_json()
click to toggle source
# File lib/datamapper/aspects/utils.rb, line 26 def attributes_json @attributes_json ||= Oj.dump(self.attributes, mode: :compat) end
changed?(property)
click to toggle source
# File lib/datamapper/aspects/utils.rb, line 22 def changed?(property) dirty_attribute_names.include?(property) end
Private Instance Methods
dirty_attribute_names()
click to toggle source
# File lib/datamapper/aspects/utils.rb, line 32 def dirty_attribute_names dirty_attributes.keys.map { |p| p.name } end