Class: DynamicModel::FieldManager
- Inherits:
-
Object
- Object
- DynamicModel::FieldManager
- Defined in:
- lib/dynamic_model/field_manager.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #add_field(name, type, opts = {}) ⇒ Object
- #field_class ⇒ Object
- #get_field_by_name(field_name) ⇒ Object
-
#initialize(options = {}) ⇒ FieldManager
constructor
A new instance of FieldManager.
Constructor Details
#initialize(options = {}) ⇒ FieldManager
Returns a new instance of FieldManager.
5 6 7 |
# File 'lib/dynamic_model/field_manager.rb', line 5 def initialize(={}) @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/dynamic_model/field_manager.rb', line 3 def @options end |
Instance Method Details
#add_field(name, type, opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dynamic_model/field_manager.rb', line 13 def add_field(name, type, opts={}) is_multivalue = opts[:multivalue] || false is_versioned = opts[:versioned] || false field = field_class.new( name: name, type_id: FieldType.get_id_by_name(type), multivalue: is_multivalue, versioned: is_versioned, ) res = field.save res end |
#field_class ⇒ Object
9 10 11 |
# File 'lib/dynamic_model/field_manager.rb', line 9 def field_class @field_class ||= @options[:field_class] end |
#get_field_by_name(field_name) ⇒ Object
28 29 30 |
# File 'lib/dynamic_model/field_manager.rb', line 28 def get_field_by_name(field_name) field_class.where(name: field_name).first end |