Class: Minicontext::Environment
- Inherits:
-
Object
- Object
- Minicontext::Environment
- Defined in:
- lib/minicontext/environment.rb
Instance Attribute Summary collapse
-
#memoized ⇒ Object
readonly
Returns the value of attribute memoized.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #action(&block) ⇒ Object
- #bind(val) ⇒ Object
- #call(context, &block) ⇒ Object
- #fetch(name) ⇒ Object
- #halt(*args) ⇒ Object
-
#initialize(request, response = nil) ⇒ Environment
constructor
A new instance of Environment.
- #short_circuit? ⇒ Boolean
Constructor Details
#initialize(request, response = nil) ⇒ Environment
Returns a new instance of Environment.
5 6 7 8 9 |
# File 'lib/minicontext/environment.rb', line 5 def initialize(request, response = nil) @request = request @response = response @memoized = {} end |
Instance Attribute Details
#memoized ⇒ Object (readonly)
Returns the value of attribute memoized.
3 4 5 |
# File 'lib/minicontext/environment.rb', line 3 def memoized @memoized end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/minicontext/environment.rb', line 3 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/minicontext/environment.rb', line 3 def response @response end |
Instance Method Details
#action(&block) ⇒ Object
29 30 31 |
# File 'lib/minicontext/environment.rb', line 29 def action(&block) instance_eval(&block) end |
#bind(val) ⇒ Object
11 12 13 |
# File 'lib/minicontext/environment.rb', line 11 def bind(val) dup.tap { |env| env.response = val } end |
#call(context, &block) ⇒ Object
37 38 39 40 41 |
# File 'lib/minicontext/environment.rb', line 37 def call(context, &block) @context = context bind(short_circuit? ? @response : action(&block)) end |
#fetch(name) ⇒ Object
25 26 27 |
# File 'lib/minicontext/environment.rb', line 25 def fetch(name) (f = @context.lookup(name)) && f.(self).response end |
#halt(*args) ⇒ Object
21 22 23 |
# File 'lib/minicontext/environment.rb', line 21 def halt(*args) Halt.new(*args) end |
#short_circuit? ⇒ Boolean
33 34 35 |
# File 'lib/minicontext/environment.rb', line 33 def short_circuit? Halt === @response end |