Module: Upmin::DataMapper::Model::ClassMethods

Defined in:
lib/upmin/data_mapper/model.rb

Instance Method Summary collapse

Instance Method Details

#associationsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/upmin/data_mapper/model.rb', line 42

def associations
  return @associations if defined?(@associations)

  all = []
  ignored = []
  model_class.relationships.each do |relationship|
    all << relationship.name

    # This may need dropped later if we find that it is more useful to show these.
    if relationship.is_a?(DataMapper::Associations::ManyToMany::Relationship)
      ignored << relationship.options[:through]
    end
  end

  return @associations = (all - ignored).uniq
end

#attribute_type(attribute) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/upmin/data_mapper/model.rb', line 28

def attribute_type(attribute)
  property = model_class.properties.select{ |p| p.name == attribute }.first
  type = property.class.to_s.demodulize.underscore.to_sym

  case type
  when :serial
    return :integer
  when :date_time
    return :datetime
  else
    return type
  end
end

#default_attributesObject



24
25
26
# File 'lib/upmin/data_mapper/model.rb', line 24

def default_attributes
  return model_class.properties.map(&:name)
end

#find(*args) ⇒ Object

NOTE - ANY method added here must be added to the bottom of Upmin::Model. This ensures that an instance of the class was created, which in turn ensures that the correct module was included in the class.



20
21
22
# File 'lib/upmin/data_mapper/model.rb', line 20

def find(*args)
  return model_class.get(*args)
end