Class: Maintain::Backend::DataMapper

Inherits:
Base
  • Object
show all
Defined in:
lib/maintain/backend/data_mapper.rb

Instance Attribute Summary

Attributes inherited from Base

#maintainer

Instance Method Summary collapse

Instance Method Details

#aggregate(maintainee, name, attribute, states) ⇒ Object



4
5
6
7
# File 'lib/maintain/backend/data_mapper.rb', line 4

def aggregate(maintainee, name, attribute, states)
  # named_scope will handle the array of states as "IN" in SQL
  state(maintainee, name, attribute, states)
end

#read(instance, attribute) ⇒ Object



9
10
11
# File 'lib/maintain/backend/data_mapper.rb', line 9

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

#state(maintainee, name, attribute, value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/maintain/backend/data_mapper.rb', line 13

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

#write(instance, attribute, value) ⇒ Object



22
23
24
25
26
# File 'lib/maintain/backend/data_mapper.rb', line 22

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