Class: Newsletter::Piece
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Newsletter::Piece
- Defined in:
- app/models/newsletter/piece.rb
Instance Attribute Summary collapse
-
#field_values_attributes ⇒ Object
Returns the value of attribute field_values_attributes.
Instance Method Summary collapse
-
#fields ⇒ Object
returns a pieces fields.
-
#locals ⇒ Object
returns locals to be used in its Newsletter::Element design.
-
#method_missing(*args) ⇒ Object
respond for its named methods for its element’s template these values will be in its locals hash.
-
#respond_to?(my_method, use_private = false) ⇒ Boolean
whether it can respond to a ‘method’ in its locals hash.
-
#save(*args) ⇒ Object
:nodoc override save for transaction to set its field values.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
respond for its named methods for its element’s template these values will be in its locals hash
64 65 66 67 68 69 70 |
# File 'app/models/newsletter/piece.rb', line 64 def method_missing(*args) if args.length == 1 and locals.has_key?(args[0].to_sym) locals[args[0].to_sym] else super end end |
Instance Attribute Details
#field_values_attributes ⇒ Object
Returns the value of attribute field_values_attributes.
25 26 27 |
# File 'app/models/newsletter/piece.rb', line 25 def field_values_attributes @field_values_attributes end |
Instance Method Details
#fields ⇒ Object
returns a pieces fields
43 44 45 |
# File 'app/models/newsletter/piece.rb', line 43 def fields element.try(:fields).try(:uniq) || [] end |
#locals ⇒ Object
returns locals to be used in its Newsletter::Element design
33 34 35 36 37 38 39 40 |
# File 'app/models/newsletter/piece.rb', line 33 def locals return @locals if @locals.present? @locals = Hash.new fields.each do |field| @locals[field.name.to_sym] = field.value_for_piece(self) end @locals end |
#respond_to?(my_method, use_private = false) ⇒ Boolean
whether it can respond to a ‘method’ in its locals hash
53 54 55 56 57 58 59 60 |
# File 'app/models/newsletter/piece.rb', line 53 def respond_to?(my_method,use_private=false) return true if super if locals.keys.include?(my_method.to_sym) true else false end end |
#save(*args) ⇒ Object
:nodoc override save for transaction to set its field values
73 74 75 76 77 78 |
# File 'app/models/newsletter/piece.rb', line 73 def save(*args) transaction do set_field_values super end end |