Sha256: 716f61bffe1104fd5af762e0487a1eec3030e6fa0f2f63ca85f67622c9e0995c

Contents?: true

Size: 871 Bytes

Versions: 20

Compression:

Stored size: 871 Bytes

Contents

module Maintain
  module Backend
    class DataMapper < Maintain::Backend::Base
      def aggregate(maintainee, name, attribute, states)
        # named_scope will handle the array of states as "IN" in SQL
        state(maintainee, name, attribute, states)
      end

      def read(instance, attribute)
        instance.attributes[attribute.to_s]
      end

      def state(maintainee, name, attribute, value)
        conditions = {:conditions => {attribute => value}}
        maintainee.class_eval <<-scope
          def self.#{name}
            all(#{conditions.inspect})
          end
        scope
      end

      def write(instance, attribute, value)
        property = instance.send(:properties)[attribute]
        instance.persisted_state = instance.persisted_state.set(property, value)
        instance.persisted_state.get(property)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
maintain-0.2.23 lib/maintain/backend/data_mapper.rb
maintain-0.2.22 lib/maintain/backend/data_mapper.rb
maintain-0.2.21 lib/maintain/backend/data_mapper.rb
maintain-0.2.20 lib/maintain/backend/data_mapper.rb
maintain-0.2.19 lib/maintain/backend/data_mapper.rb
maintain-0.2.18 lib/maintain/backend/data_mapper.rb
maintain-0.2.17 lib/maintain/backend/data_mapper.rb
maintain-0.2.16 lib/maintain/backend/data_mapper.rb
maintain-0.2.15 lib/maintain/backend/data_mapper.rb
maintain-0.2.14 lib/maintain/backend/data_mapper.rb
maintain-0.2.13 lib/maintain/backend/data_mapper.rb
maintain-0.2.12 lib/maintain/backend/data_mapper.rb
maintain-0.2.11 lib/maintain/backend/data_mapper.rb
maintain-0.2.10 lib/maintain/backend/data_mapper.rb
maintain-0.2.9 lib/maintain/backend/data_mapper.rb
maintain-0.2.8 lib/maintain/backend/data_mapper.rb
maintain-0.2.6 lib/maintain/backend/data_mapper.rb
maintain-0.2.5 lib/maintain/backend/data_mapper.rb
maintain-0.2.4 lib/maintain/backend/data_mapper.rb
maintain-0.2.2 lib/maintain/backend/data_mapper.rb