Class: Changes::CreateOrUpdate

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_fields/changes/create_or_update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, field_name, field_type, record) ⇒ CreateOrUpdate

Returns a new instance of CreateOrUpdate.



5
6
7
8
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 5

def initialize(value, field_name, field_type, record)
  @value, @field_name, @field_type, @record = value, field_name, field_type, record
  @attribute = find_or_build_attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



3
4
5
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 3

def attribute
  @attribute
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



3
4
5
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 3

def field_name
  @field_name
end

#field_typeObject (readonly)

Returns the value of attribute field_type.



3
4
5
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 3

def field_type
  @field_type
end

#recordObject (readonly)

Returns the value of attribute record.



3
4
5
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 3

def record
  @record
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 3

def value
  @value
end

Instance Method Details

#saveObject



10
11
12
13
# File 'lib/dynamic_fields/changes/create_or_update.rb', line 10

def save
  attribute.value = value
  record.public_send("#{field_name}_attribute=", attribute)
end