Class: Jerakia::Policy
Direct Known Subclasses
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#lookup_proceed ⇒ Object
readonly
Returns the value of attribute lookup_proceed.
-
#lookups ⇒ Object
Returns the value of attribute lookups.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Attributes inherited from Launcher
Instance Method Summary collapse
- #clone_request ⇒ Object
- #fire! ⇒ Object
-
#initialize(name, opts, &block) ⇒ Policy
constructor
A new instance of Policy.
- #lookup(name, opts = {}, &block) ⇒ Object
Methods inherited from Launcher
Constructor Details
#initialize(name, opts, &block) ⇒ Policy
Returns a new instance of Policy.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jerakia/policy.rb', line 12 def initialize(name, opts, &block) @lookups=[] @routes={} @answer=Jerakia::Answer.new(request.lookup_type) @scope=Jerakia::Scope.new @lookup_proceed = true begin instance_eval &block rescue => e Jerakia.fatal "Error processing policy file", e end end |
Instance Attribute Details
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
8 9 10 |
# File 'lib/jerakia/policy.rb', line 8 def answer @answer end |
#lookup_proceed ⇒ Object (readonly)
Returns the value of attribute lookup_proceed.
10 11 12 |
# File 'lib/jerakia/policy.rb', line 10 def lookup_proceed @lookup_proceed end |
#lookups ⇒ Object
Returns the value of attribute lookups.
6 7 8 |
# File 'lib/jerakia/policy.rb', line 6 def lookups @lookups end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
7 8 9 |
# File 'lib/jerakia/policy.rb', line 7 def routes @routes end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
9 10 11 |
# File 'lib/jerakia/policy.rb', line 9 def scope @scope end |
Instance Method Details
#clone_request ⇒ Object
25 26 27 |
# File 'lib/jerakia/policy.rb', line 25 def clone_request Marshal.load(Marshal.dump(request)) end |
#fire! ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jerakia/policy.rb', line 42 def fire! @lookups.each do |l| responses = l.run responses.entries.each do |res| case request.lookup_type when :first @answer.payload ||= res[:value] @answer.datatype ||= res[:datatype] when :cascade @answer.payload << res[:value] end end if request.lookup_type == :cascade && @answer.payload.is_a?(Array) && request.merge == :array @answer.flatten_payload! end if request.lookup_type == :cascade && @answer.payload.is_a?(Array) && request.merge == :hash @answer.merge_payload! end end end |
#lookup(name, opts = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jerakia/policy.rb', line 30 def lookup(name,opts={},&block) # We specifically clone the request object to allow plugins to modify the # request payload for the scope of this lookup only. # lookup = Jerakia::Lookup.new(name,opts,clone_request,scope,&block) Jerakia.log.debug("Proceed to next lookup #{lookup.proceed?}") @lookups << lookup if lookup.valid? and @lookup_proceed @lookup_proceed = false if !lookup.proceed? and lookup.valid? end |