Module: MerbAdmin::AbstractModel::DatamapperSupport
- Defined in:
- lib/datamapper_support.rb
Defined Under Namespace
Modules: InstanceMethods
Instance Method Summary collapse
- #associations ⇒ Object
- #belongs_to_associations ⇒ Object
- #count(options = {}) ⇒ Object
- #find(id) ⇒ Object
- #find_all(options = {}) ⇒ Object
- #has_many_associations ⇒ Object
- #has_one_associations ⇒ Object
- #new(params = {}) ⇒ Object
- #properties ⇒ Object
Instance Method Details
#associations ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/datamapper_support.rb', line 38 def associations model.relationships.to_a.map do |name, relationship| { :name => name, :pretty_name => name.to_s.gsub('_', ' '), :type => association_type_lookup(relationship), :parent_model => relationship.parent_model, :parent_key => relationship.parent_key.map{|r| r.name}, :child_model => relationship.child_model, :child_key => relationship.child_key.map{|r| r.name}, :remote_relationship => relationship.[:remote_relationship_name], :near_relationship => relationship.[:near_relationship_name], } end end |
#belongs_to_associations ⇒ Object
32 33 34 35 36 |
# File 'lib/datamapper_support.rb', line 32 def belongs_to_associations associations.select do |association| association[:type] == :belongs_to end end |
#count(options = {}) ⇒ Object
4 5 6 |
# File 'lib/datamapper_support.rb', line 4 def count( = {}) model.count() end |
#find(id) ⇒ Object
12 13 14 |
# File 'lib/datamapper_support.rb', line 12 def find(id) model.get(id).extend(InstanceMethods) end |
#find_all(options = {}) ⇒ Object
8 9 10 |
# File 'lib/datamapper_support.rb', line 8 def find_all( = {}) model.all() end |
#has_many_associations ⇒ Object
20 21 22 23 24 |
# File 'lib/datamapper_support.rb', line 20 def has_many_associations associations.select do |association| association[:type] == :has_many end end |
#has_one_associations ⇒ Object
26 27 28 29 30 |
# File 'lib/datamapper_support.rb', line 26 def has_one_associations associations.select do |association| association[:type] == :has_one end end |
#new(params = {}) ⇒ Object
16 17 18 |
# File 'lib/datamapper_support.rb', line 16 def new(params = {}) model.new(params).extend(InstanceMethods) end |
#properties ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/datamapper_support.rb', line 54 def properties model.properties.map do |property| { :name => property.name, :pretty_name => property.field.gsub('_', ' '), :type => type_lookup(property), :length => property.length, :nullable? => property.nullable?, :serial? => property.serial?, :key? => property.key?, :flag_map => property.type.respond_to?(:flag_map) ? property.type.flag_map : nil, } end end |