Class: EacRubyUtils::ActsAsImmutable::BaseAccessor
- Inherits:
-
Object
- Object
- EacRubyUtils::ActsAsImmutable::BaseAccessor
show all
- Defined in:
- lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb
Constant Summary
collapse
- FILTER_GET_METHOD_NAME_FORMAT =
'%s_get_filter'
- FILTER_SET_METHOD_NAME_FORMAT =
'%s_set_filter'
Instance Method Summary
collapse
Instance Method Details
#duplicate_object(object) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb', line 15
def duplicate_object(object)
accessor_new_value = yield(immutable_value_get(object))
new_values = object.send(:immutable_values_get).merge(name => accessor_new_value)
r = object.class.new(*object.immutable_constructor_args)
r.send(:immutable_values_set, new_values)
r
end
|
#immutable_value_get(object) ⇒ Object
23
24
25
|
# File 'lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb', line 23
def immutable_value_get(object)
object.send(:immutable_values_get)[name]
end
|
#immutable_value_get_filtered(object) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb', line 29
def immutable_value_get_filtered(object)
r = immutable_value_get(object)
if object.respond_to?(immutable_value_get_filtered_method_name, true)
r = object.send(immutable_value_get_filtered_method_name, r)
end
r
end
|
#immutable_value_get_filtered_method_name ⇒ Symbol
38
39
40
|
# File 'lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb', line 38
def immutable_value_get_filtered_method_name
format(FILTER_GET_METHOD_NAME_FORMAT, name)
end
|
#immutable_value_set_filtered(object, value) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb', line 44
def immutable_value_set_filtered(object, value)
if object.respond_to?(immutable_value_set_filtered_method_name, true)
value = object.send(immutable_value_set_filtered_method_name, value)
end
immutable_value_set(object, value)
end
|
#immutable_value_set_filtered_method_name ⇒ Symbol
52
53
54
|
# File 'lib/eac_ruby_utils/acts_as_immutable/base_accessor.rb', line 52
def immutable_value_set_filtered_method_name
format(FILTER_SET_METHOD_NAME_FORMAT, name)
end
|