Sha256: cbc87cdafa509b28e3ba3db2bbf4f7bb0b27e7ef33d646b2c81d2e751e029478

Contents?: true

Size: 900 Bytes

Versions: 7

Compression:

Stored size: 900 Bytes

Contents

# encoding: utf-8

module DataMapper
  module Aspects
    module Utils
      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

      def changed?(property)
        dirty_attribute_names.include?(property)
      end

      def attributes_json
        @attributes_json ||= Oj.dump(self.attributes, mode: :compat)
      end

      private

      def dirty_attribute_names
        dirty_attributes.keys.map { |p| p.name }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dm-aspects-0.1.0 lib/datamapper/aspects/utils.rb
dm-aspects-0.0.6 lib/datamapper/aspects/utils.rb
dm-aspects-0.0.5 lib/datamapper/aspects/utils.rb
dm-aspects-0.0.4 lib/datamapper/aspects/utils.rb
dm-aspects-0.0.3 lib/datamapper/aspects/utils.rb
dm-aspects-0.0.2 lib/datamapper/aspects/utils.rb
dm-aspects-0.0.1 lib/datamapper/aspects/utils.rb