Class: Conflow::Redis::FieldBuilder::FieldAccessor Private
- Inherits:
-
Module
- Object
- Module
- Conflow::Redis::FieldBuilder::FieldAccessor
- Defined in:
- lib/conflow/redis/field_builder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This dynamic module contains accessor methods for a field
Instance Method Summary collapse
-
#define_getter(field_name, klass) ⇒ Object
private
Defines getter method, which will return proper Conflow::Redis::Field.
-
#define_setter(field_name) ⇒ Object
private
Setter uses Field#overwrite method to replace contents of the field.
-
#initialize(field_name, klass, methods) ⇒ FieldAccessor
constructor
private
Creates new dynamic module with accessor methods for a field.
Constructor Details
#initialize(field_name, klass, methods) ⇒ FieldAccessor
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates new dynamic module with accessor methods for a field
11 12 13 14 15 16 |
# File 'lib/conflow/redis/field_builder.rb', line 11 def initialize(field_name, klass, methods) super() do define_getter(field_name, klass) if methods.include?(:getter) define_setter(field_name) if methods.include?(:setter) end end |
Instance Method Details
#define_getter(field_name, klass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines getter method, which will return proper Conflow::Redis::Field
19 20 21 22 23 24 25 26 |
# File 'lib/conflow/redis/field_builder.rb', line 19 def define_getter(field_name, klass) instance_var = "@#{field_name}" define_method(field_name) do instance_variable_get(instance_var) || instance_variable_set(instance_var, klass.new([key, field_name].join(":"))) end end |
#define_setter(field_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Setter uses Field#overwrite method to replace contents of the field
29 30 31 32 33 |
# File 'lib/conflow/redis/field_builder.rb', line 29 def define_setter(field_name) define_method("#{field_name}=") do |value| send(field_name).tap { |field| field.overwrite(value) } end end |