Class: DynamicModel::FieldManager

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_model/field_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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={})
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/dynamic_model/field_manager.rb', line 3

def options
  @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_classObject



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