Class: FieldsField

Inherits:
Field
  • Object
show all
Defined in:
lib/yodel/models/core/fields/fields_field.rb

Constant Summary

Constants inherited from Field

Field::TYPES

Instance Attribute Summary

Attributes inherited from Field

#name, #options

Instance Method Summary collapse

Methods inherited from Field

#default_input_type, #display?, field_from_type, from_options, #include_in_search_keywords?, #index?, #inherited?, #initialize, #method_missing, #numeric?, #required?, #searchable?, #strip_nil?, #to_json, #to_str, #unique?, #validate

Constructor Details

This class inherits a constructor from Field

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Field

Instance Method Details

#from_json(hash, record) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/yodel/models/core/fields/fields_field.rb', line 14

def from_json(hash, record)
  # return {} unless hash.is_a?(Hash)
  #       hash.each_with_object({}) do |(name, options), fields|
  #         fields[name.to_s] = Field.from_options(name, options).options
  #       end
  fields_from_hash(hash, record)
end

#typecast(hash, record) ⇒ Object



2
3
4
# File 'lib/yodel/models/core/fields/fields_field.rb', line 2

def typecast(hash, record)
  ChangeSensitiveHash.new(record, name, fields_from_hash(hash, record))
end

#untypecast(hash, record) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/yodel/models/core/fields/fields_field.rb', line 6

def untypecast(hash, record)
  return {} unless hash.respond_to?(:to_hash)
  hash.to_hash.each_with_object({}) do |(name, field_obj), fields|
    next unless field_obj.is_a?(Field)
    fields[name.to_s] = field_obj.options
  end
end