Class: Minicontext::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/minicontext/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#memoizedObject (readonly)

Returns the value of attribute memoized.



3
4
5
# File 'lib/minicontext/environment.rb', line 3

def memoized
  @memoized
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/minicontext/environment.rb', line 3

def request
  @request
end

#responseObject

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

Returns:

  • (Boolean)


33
34
35
# File 'lib/minicontext/environment.rb', line 33

def short_circuit?
  Halt === @response
end