Class: Magicka::Aggregator
- Inherits:
-
Object
- Object
- Magicka::Aggregator
- Extended by:
- ClassMethods
- Defined in:
- lib/magicka/aggregator.rb,
lib/magicka/aggregator/class_methods.rb,
lib/magicka/aggregator/method_builder.rb
Overview
Class representing an element agregator, representing a model
Defined Under Namespace
Modules: ClassMethods Classes: MethodBuilder
Instance Attribute Summary collapse
-
#model ⇒ String
readonly
Model where the form elements will focus.
Class Method Summary collapse
-
.with_element(element_class, method_name = nil, template: nil) ⇒ Array<NilClass>
Configure an Aggregator adding a method to render an element.
Instance Method Summary collapse
-
#equal?(other) ⇒ TrueClass, FalseClass
(also: #==)
private
Checks if other aggragate is equal to this one.
-
#except(*types) ⇒ Object
Executes a block only when aggregator is not one of given types.
-
#initialize(renderer, model) ⇒ Aggregator
constructor
A new instance of Aggregator.
-
#only(*types) ⇒ Object
Executes a block only when aggregator is one of given types.
-
#with_model(model, base: self.model) {|Aggregator| ... } ⇒ Aggregator
Returns a new aggregator focusing on a new model.
Methods included from ClassMethods
Constructor Details
#initialize(renderer, model) ⇒ Aggregator
Returns a new instance of Aggregator.
40 41 42 43 |
# File 'lib/magicka/aggregator.rb', line 40 def initialize(renderer, model) @renderer = renderer @model = model end |
Instance Attribute Details
#model ⇒ String (readonly)
Model where the form elements will focus
16 17 18 |
# File 'lib/magicka/aggregator.rb', line 16 def model @model end |
Class Method Details
.with_element(element_class, method_name = nil, template: nil) ⇒ Array<NilClass>
Configure an Magicka::Aggregator adding a method to render an element
|
# File 'lib/magicka/aggregator.rb', line 23
|
Instance Method Details
#equal?(other) ⇒ TrueClass, FalseClass Also known as: ==
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.
Checks if other aggragate is equal to this one
89 90 91 92 93 94 |
# File 'lib/magicka/aggregator.rb', line 89 def equal?(other) return unless other.class == self.class other.renderer == renderer && other.model == model end |
#except(*types) ⇒ Object
Executes a block only when aggregator is not one of given types
77 78 79 80 81 |
# File 'lib/magicka/aggregator.rb', line 77 def except(*types) return if types.include?(self.class.type) yield end |
#only(*types) ⇒ Object
Executes a block only when aggregator is one of given types
66 67 68 69 70 |
# File 'lib/magicka/aggregator.rb', line 66 def only(*types) return unless types.include?(self.class.type) yield end |
#with_model(model, base: self.model) {|Aggregator| ... } ⇒ Aggregator
Returns a new aggregator focusing on a new model
The new model is an attribute of model
unless base is given
55 56 57 58 59 |
# File 'lib/magicka/aggregator.rb', line 55 def with_model(model, base: self.model) new_model = [base, model].compact.join('.') yield self.class.new(renderer, new_model) end |