Class: ViewModels::Extensions::ModelReader::FilteredDelegationInstaller
- Inherits:
-
Object
- Object
- ViewModels::Extensions::ModelReader::FilteredDelegationInstaller
- Defined in:
- lib/view_models/extensions/model_reader.rb
Overview
The filtered delegation installer installs delegators on the target that are filtered.
Instance Attribute Summary (collapse)
-
- (Object) attributes
readonly
The attributes target, attributes, filters.
-
- (Object) filters
readonly
The attributes target, attributes, filters.
-
- (Object) target
readonly
The attributes target, attributes, filters.
Instance Method Summary (collapse)
-
- (Object) filtered_left_parentheses
Combines left parentheses and filters.
-
- (FilteredDelegationInstaller) initialize(target, options)
constructor
Initialize a new filtered delegation.
-
- (Object) install
Install a reader for each attribute.
-
- (Object) install_reader(attribute)
Install a reader for the given name with the given filters.
-
- (Object) left_parentheses
Generates an array of left parentheses with length <amount of filters>.
-
- (Object) reader_definition_for(attribute)
Defines a reader for the given model attribute and filtering through the given filters.
-
- (Object) right_parentheses
Generates the needed amount of parentheses to match the left parentheses.
Constructor Details
- (FilteredDelegationInstaller) initialize(target, options)
Initialize a new filtered delegation
76 77 78 |
# File 'lib/view_models/extensions/model_reader.rb', line 76 def initialize target, @target, @attributes, @filters = target, * end |
Instance Attribute Details
- (Object) attributes (readonly)
The attributes target, attributes, filters
70 71 72 |
# File 'lib/view_models/extensions/model_reader.rb', line 70 def attributes @attributes end |
- (Object) filters (readonly)
The attributes target, attributes, filters
70 71 72 |
# File 'lib/view_models/extensions/model_reader.rb', line 70 def filters @filters end |
- (Object) target (readonly)
The attributes target, attributes, filters
70 71 72 |
# File 'lib/view_models/extensions/model_reader.rb', line 70 def target @target end |
Instance Method Details
- (Object) filtered_left_parentheses
Combines left parentheses and filters.
106 107 108 |
# File 'lib/view_models/extensions/model_reader.rb', line 106 def filtered_left_parentheses filters.zip(left_parentheses).join end |
- (Object) install
Install a reader for each attribute
82 83 84 |
# File 'lib/view_models/extensions/model_reader.rb', line 82 def install attributes.each { |attribute| install_reader(attribute) } end |
- (Object) install_reader(attribute)
Install a reader for the given name with the given filters.
91 92 93 |
# File 'lib/view_models/extensions/model_reader.rb', line 91 def install_reader attribute target.class_eval reader_definition_for(attribute) end |
- (Object) left_parentheses
Generates an array of left parentheses with length <amount of filters>
121 122 123 |
# File 'lib/view_models/extensions/model_reader.rb', line 121 def left_parentheses ['('] * filters.size end |
- (Object) reader_definition_for(attribute)
The filters are applied from last to first element.
Defines a reader for the given model attribute and filtering through the given filters.
100 101 102 |
# File 'lib/view_models/extensions/model_reader.rb', line 100 def reader_definition_for attribute "def #{attribute}; #{filtered_left_parentheses}model.#{attribute}#{right_parentheses}; end" end |
- (Object) right_parentheses
Generates the needed amount of parentheses to match the left parentheses.
112 113 114 |
# File 'lib/view_models/extensions/model_reader.rb', line 112 def right_parentheses ')' * filters.size end |