Class: Workarea::Content::Fieldset

Inherits:
Object
  • Object
show all
Includes:
AssetLookup
Defined in:
app/models/workarea/content/fieldset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AssetLookup

#find_asset_id_by_file_name

Constructor Details

#initialize(name) ⇒ Fieldset

Returns a new instance of Fieldset.



9
10
11
12
# File 'app/models/workarea/content/fieldset.rb', line 9

def initialize(name)
  @name = name
  @fields = []
end

Instance Attribute Details

#field_suffixObject

Returns the value of attribute field_suffix.



7
8
9
# File 'app/models/workarea/content/fieldset.rb', line 7

def field_suffix
  @field_suffix
end

#fieldsObject (readonly)

Returns the value of attribute fields.



6
7
8
# File 'app/models/workarea/content/fieldset.rb', line 6

def fields
  @fields
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'app/models/workarea/content/fieldset.rb', line 7

def name
  @name
end

Instance Method Details

#field(name, type, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/workarea/content/fieldset.rb', line 14

def field(name, type, options = {})
  name = [name, field_suffix].join if field_suffix.present?

  klass = if type.is_a?(Class)
            type
          else
            "Workarea::Content::Fields::#{type.to_s.camelize}".constantize
          end

  if existing = @fields.detect { |f| f.name == name }
    existing.options.merge!(options)
  else
    @fields << klass.new(name, options)
  end
end