Class: EOTS::EmailKind
- Inherits:
-
Object
- Object
- EOTS::EmailKind
- Defined in:
- app/models/eots/email_kind.rb
Constant Summary collapse
- AlreadyDefinedError =
Class.new(RuntimeError)
- FieldNotFoundError =
Class.new(RuntimeError)
- NotFoundError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_field(field_name, label, field_options) ⇒ Object
- #body_fields ⇒ Object
- #footer_fields ⇒ Object
- #footers ⇒ Object
- #form_fields ⇒ Object
- #header_fields ⇒ Object
- #headers ⇒ Object
- #html_footers ⇒ Object
- #html_headers ⇒ Object
-
#initialize(name, parent, options = {}) ⇒ EmailKind
constructor
A new instance of EmailKind.
Constructor Details
#initialize(name, parent, options = {}) ⇒ EmailKind
Returns a new instance of EmailKind.
18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/eots/email_kind.rb', line 18 def initialize(name, parent, ={}) @name = name.to_s opts = .dup @fields = {} (EOTS::STANDARD_FIELDS + EOTS::NON_FIELD_ITEMS).each do |field| instance_variable_set("@#{field}".to_sym, opts.delete(field)) end @options = opts # what's left @parent = parent end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
7 8 9 |
# File 'app/models/eots/email_kind.rb', line 7 def fields @fields end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'app/models/eots/email_kind.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'app/models/eots/email_kind.rb', line 7 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'app/models/eots/email_kind.rb', line 7 def parent @parent end |
Instance Method Details
#add_field(field_name, label, field_options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/eots/email_kind.rb', line 29 def add_field(field_name, label, ) field_name = field_name.to_s if @fields[field_name] raise(EOTS::Field::AlreadyDefinedError, "Field #{field_name} is already defined on email kind #{self.name}") end @form_fields = nil # invalidate it... can't reach down to children tho :-( # also return the new field, in case caller wants to do something with it @fields[field_name] = EOTS::Field.new(field_name, label, ) end |
#body_fields ⇒ Object
40 41 42 |
# File 'app/models/eots/email_kind.rb', line 40 def body_fields form_fields[:body] end |
#footer_fields ⇒ Object
44 45 46 |
# File 'app/models/eots/email_kind.rb', line 44 def form_fields[:footer] end |
#footers ⇒ Object
48 49 50 51 |
# File 'app/models/eots/email_kind.rb', line 48 def below = @parent ? @parent. : [] ([] + below).compact end |
#form_fields ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/eots/email_kind.rb', line 53 def form_fields unless @form_fields @form_fields = @parent ? @parent.form_fields : { header: [], body: [], footer: [] } mine = fields.values.group_by &:section @form_fields[:header] += mine[:header] if mine[:header] @form_fields[:body] += mine[:body] if mine[:body] @form_fields[:footer] = mine[:footer] + @form_fields[:footer] if mine[:footer] end @form_fields.dup # dup so children don't add stuff end |
#header_fields ⇒ Object
64 65 66 |
# File 'app/models/eots/email_kind.rb', line 64 def header_fields form_fields[:header] end |
#headers ⇒ Object
68 69 70 71 |
# File 'app/models/eots/email_kind.rb', line 68 def headers above = @parent ? @parent.headers : [] (above << header).compact end |
#html_footers ⇒ Object
73 74 75 |
# File 'app/models/eots/email_kind.rb', line 73 def wrap_in_html_paragraphs() end |
#html_headers ⇒ Object
77 78 79 |
# File 'app/models/eots/email_kind.rb', line 77 def html_headers wrap_in_html_paragraphs(headers) end |