Module: Transit::Model::Base
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/transit/model/base.rb
Instance Method Summary collapse
- #context_named(n) ⇒ Object
-
#delivers?(opt) ⇒ Boolean
Convenience method to determine the particular options this model delivers.
-
#ensure_text_context ⇒ Object
Each model should pre-build at least one context for its main body content.
- #process_context_attributes=(hash) ⇒ Object
Instance Method Details
#context_named(n) ⇒ Object
25 26 27 |
# File 'lib/transit/model/base.rb', line 25 def context_named(n) self.contexts.by_name(n).first end |
#delivers?(opt) ⇒ Boolean
Convenience method to determine the particular options this model delivers
33 34 35 |
# File 'lib/transit/model/base.rb', line 33 def delivers?(opt) self.class..include?(opt.to_s) end |
#ensure_text_context ⇒ Object
Each model should pre-build at least one context for its main body content
40 41 42 43 |
# File 'lib/transit/model/base.rb', line 40 def ensure_text_context return true unless self.contexts.size == 0 self.contexts.build({ :name => 'Body Copy' }, Text) end |
#process_context_attributes=(hash) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/transit/model/base.rb', line 45 def process_context_attributes=(hash) hash.each_pair do |pos, attrs| attrs.stringify_keys! field = self.contexts.all.detect{ |cf| cf.id.to_s == attrs['id'] } || self.contexts.build({ }, attrs['_type'].classify.constantize) field.attributes = attrs end end |