Class: RademadeAdmin::Model::Configuration::Fields

Inherits:
Object
  • Object
show all
Defined in:
lib/rademade_admin/model/configuration/fields.rb

Direct Known Subclasses

FieldsLabels, FormFields, ListFields

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments) ⇒ Object



32
33
34
# File 'lib/rademade_admin/model/configuration/fields.rb', line 32

def method_missing(name, *arguments)
  @fields << field_class.new(name.to_sym, *arguments)
end

Instance Method Details

#allObject



28
29
30
# File 'lib/rademade_admin/model/configuration/fields.rb', line 28

def all
  @fields
end

#configure(*options, &block) ⇒ Object



36
37
38
# File 'lib/rademade_admin/model/configuration/fields.rb', line 36

def configure(*options, &block)
  block_given? ? instance_eval(&block) : _init_from_options(*options)
end

#find(name) {|field| ... } ⇒ Object

Yields:

  • (field)


7
8
9
10
11
12
13
# File 'lib/rademade_admin/model/configuration/fields.rb', line 7

def find(name)
  name = name.to_sym
  field = @fields.select { |field| field.name == name }.first
  return nil if field.nil?
  yield(field) if block_given?
  field
end

#find_with_index(name) {|found_field, found_index| ... } ⇒ Object

Yields:

  • (found_field, found_index)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rademade_admin/model/configuration/fields.rb', line 15

def find_with_index(name)
  found_field, found_index = nil, nil
  @fields.each_with_index do |field, index|
    if field.name == name
      found_field, found_index = field, index
      break
    end
  end
  return nil if found_field.nil?
  yield(found_field, found_index) if block_given?
  { :field => found_field, :index => found_index }
end