Class: Jerakia::Policy
- Inherits:
-
Object
- Object
- Jerakia::Policy
- Defined in:
- lib/jerakia/policy.rb
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.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #clone_request ⇒ Object
- #fire! ⇒ Object
-
#initialize(name, opts = {}, req, &block) ⇒ Policy
constructor
A new instance of Policy.
- #lookup(name, opts = {}, &block) ⇒ Object
- #request ⇒ Object
Constructor Details
#initialize(name, opts = {}, req, &block) ⇒ Policy
Returns a new instance of Policy.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jerakia/policy.rb', line 14 def initialize(name, opts={}, req, &block) if req.use_schema and Jerakia.config[:enable_schema] schema_config = Jerakia.config[:schema] || {} @schema = Jerakia::Schema.new(req, schema_config) end @lookups=[] @routes={} @request=req @answer=Jerakia::Answer.new(req.lookup_type) @scope=Jerakia::Scope.new(req) @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.
9 10 11 |
# File 'lib/jerakia/policy.rb', line 9 def answer @answer end |
#lookup_proceed ⇒ Object (readonly)
Returns the value of attribute lookup_proceed.
11 12 13 |
# File 'lib/jerakia/policy.rb', line 11 def lookup_proceed @lookup_proceed end |
#lookups ⇒ Object
Returns the value of attribute lookups.
7 8 9 |
# File 'lib/jerakia/policy.rb', line 7 def lookups @lookups end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
8 9 10 |
# File 'lib/jerakia/policy.rb', line 8 def routes @routes end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
12 13 14 |
# File 'lib/jerakia/policy.rb', line 12 def schema @schema end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
10 11 12 |
# File 'lib/jerakia/policy.rb', line 10 def scope @scope end |
Instance Method Details
#clone_request ⇒ Object
38 39 40 |
# File 'lib/jerakia/policy.rb', line 38 def clone_request Marshal.load(Marshal.dump(request)) end |
#fire! ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jerakia/policy.rb', line 55 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) case request.merge when :array @answer.flatten_payload! when :hash,:deep_hash @answer.merge_payload!(request.merge) end end end end |
#lookup(name, opts = {}, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jerakia/policy.rb', line 43 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 |
#request ⇒ Object
34 35 36 |
# File 'lib/jerakia/policy.rb', line 34 def request @request end |