Class: Reduxco::Reduxer
- Inherits:
-
Object
- Object
- Reduxco::Reduxer
- Defined in:
- lib/reduxco/reduxer.rb
Overview
The primary public facing Reduxco class.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns a reference to the enclosing Context.
Instance Method Summary collapse
-
#call(refname = :app, &block) ⇒ Object
(also: #[], #reduce)
Retrieves the value of the given refname.
-
#dup ⇒ Object
Acts as a copy constructor, giving a new Reduxer instantiated with the same arguments as this one.
-
#initialize(*args) ⇒ Reduxer
constructor
When given one or more maps of callables, instantiates with the given callable maps.
Constructor Details
#initialize(*args) ⇒ Reduxer
When given one or more maps of callables, instantiates with the given callable maps.
When the first argument is a Context, it instantiates with a new Context that has the same callable maps.
12 13 14 15 16 17 18 19 |
# File 'lib/reduxco/reduxer.rb', line 12 def initialize(*args) case args.first when Context @context = args.first.dup else @context = Context.new(*args) end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns a reference to the enclosing Context. This is typically not needed, and its use is more often than not related to a client design mistake.
24 25 26 |
# File 'lib/reduxco/reduxer.rb', line 24 def context @context end |
Instance Method Details
#call(refname = :app, &block) ⇒ Object Also known as: [], reduce
Retrieves the value of the given refname. Both final and intermediate values are cached, so multiple calls have low overhead.
28 29 30 |
# File 'lib/reduxco/reduxer.rb', line 28 def call(refname=:app, &block) @context.call(refname, &block) end |
#dup ⇒ Object
Acts as a copy constructor, giving a new Reduxer instantiated with the same arguments as this one.
36 37 38 |
# File 'lib/reduxco/reduxer.rb', line 36 def dup self.class.new(@context) end |