Class: MerbAdmin::AbstractModel
- Defined in:
- lib/abstract_model.rb,
lib/generic_support.rb,
lib/datamapper_support.rb
Defined Under Namespace
Modules: DatamapperSupport, GenericSupport
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Class Method Summary collapse
-
.all ⇒ Object
Returns all models for a given Merb app.
-
.lookup(model_name) ⇒ Object
Given a symbol
model_name, finds the corresponding model class.
Instance Method Summary collapse
-
#initialize(model) ⇒ AbstractModel
constructor
A new instance of AbstractModel.
Constructor Details
#initialize(model) ⇒ AbstractModel
Returns a new instance of AbstractModel.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/abstract_model.rb', line 34 def initialize(model) model = self.class.lookup(model.camel_case.to_sym) unless model.is_a?(Class) @model = model self.extend(GenericSupport) case Merb.orm when :datamapper self.extend(DatamapperSupport) else raise "MerbAdmin does not currently support the #{Merb.orm} ORM" end end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
32 33 34 |
# File 'lib/abstract_model.rb', line 32 def model @model end |
Class Method Details
.all ⇒ Object
Returns all models for a given Merb app
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/abstract_model.rb', line 7 def self.all return @models if @models @models ||= [] case Merb.orm when :datamapper DataMapper::Resource.descendants.each do |m| # Remove DataMapperSessionStore because it's included by default next if m == Merb::DataMapperSessionStore if Merb.const_defined?(:DataMapperSessionStore) model = lookup(m.to_s.to_sym) @models << new(model) if model end @models.sort!{|a, b| a.model.to_s <=> b.model.to_s} else raise "MerbAdmin does not currently support the #{Merb.orm} ORM" end end |
.lookup(model_name) ⇒ Object
Given a symbol model_name, finds the corresponding model class
25 26 27 28 29 30 |
# File 'lib/abstract_model.rb', line 25 def self.lookup(model_name) model = const_get(model_name) raise "could not find model #{model_name}" if model.nil? return model if model.include?(DataMapper::Resource) nil end |