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.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#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) ⇒ Policy
constructor
A new instance of Policy.
- #submit_lookup(lookup) ⇒ Object
Constructor Details
#initialize(name, opts = {}, req) ⇒ Policy
Returns a new instance of Policy.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jerakia/policy.rb', line 14 def initialize(name, opts={}, req) if req.use_schema and Jerakia.config[:enable_schema] schema_config = Jerakia.config[:schema] || {} @schema = Jerakia::Schema.new(req, schema_config) end @lookups=[] @request=req @answer=Jerakia::Answer.new(req.lookup_type) @scope=Jerakia::Scope.new(req) @lookup_proceed = true 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.
7 8 9 |
# File 'lib/jerakia/policy.rb', line 7 def lookups @lookups end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
12 13 14 |
# File 'lib/jerakia/policy.rb', line 12 def request @request end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
11 12 13 |
# File 'lib/jerakia/policy.rb', line 11 def schema @schema 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
29 30 31 32 |
# File 'lib/jerakia/policy.rb', line 29 def clone_request copy_request = request.clone return copy_request end |
#fire! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jerakia/policy.rb', line 40 def fire! response_entries = [] @lookups.each do |l| responses = l.run lookup_answers = responses.entries.map { |r| r } response_entries << lookup_answers if lookup_answers end response_entries.flatten.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 |
#submit_lookup(lookup) ⇒ Object
34 35 36 37 38 |
# File 'lib/jerakia/policy.rb', line 34 def submit_lookup(lookup) raise Jerakia::PolicyError, "Lookup #{lookup.name} has no datasource defined" unless lookup.get_datasource @lookups << lookup if lookup.valid? and @lookup_proceed @lookup_proceed = false if !lookup.proceed? and lookup.valid? end |