Class: Jerakia::Lookup
- Inherits:
-
Object
- Object
- Jerakia::Lookup
- Defined in:
- lib/jerakia/lookup.rb,
lib/jerakia/plugins/lookup/confine.rb
Defined Under Namespace
Modules: Plugin Classes: PluginFactory
Instance Attribute Summary collapse
-
#datasource(source, opts = {}) ⇒ Object
readonly
Returns the value of attribute datasource.
-
#lookuptype ⇒ Object
readonly
Returns the value of attribute lookuptype.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_filters ⇒ Object
readonly
Returns the value of attribute output_filters.
-
#pluginfactory ⇒ Object
readonly
Returns the value of attribute pluginfactory.
-
#proceed ⇒ Object
readonly
Returns the value of attribute proceed.
-
#request ⇒ Object
Returns the value of attribute request.
-
#scope_object ⇒ Object
readonly
Returns the value of attribute scope_object.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
- #confine(key = nil, match) ⇒ Object
-
#continue ⇒ Object
lookup function: continue Will cause Jerakia to continue to the next lookup in the policy which is the default behaviour.
- #exclude(key = nil, match) ⇒ Object
- #get_matches(key, match) ⇒ Object
-
#initialize(name, opts, req, scope, &block) ⇒ Lookup
constructor
A new instance of Lookup.
-
#invalidate ⇒ Object
lookup function: invalidate Setting invalidate will mean this lookup will be skipped in the policy.
- #output_filter(name, opts = {}) ⇒ Object
- #plugin ⇒ Object
- #plugin_load(plugin) ⇒ Object
- #proceed? ⇒ Boolean
- #run ⇒ Object
-
#scope ⇒ Object
If set, Jerakia will pass each Jerakia::Response object to an output filter plugin.
-
#stop ⇒ Object
lookup function: stop Enabling stop sets @proceed to false, which will cause Jerakia not to load any more lookups in the policy if this lookup is deemed as valid.
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, opts, req, scope, &block) ⇒ Lookup
Returns a new instance of Lookup.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jerakia/lookup.rb', line 17 def initialize(name,opts,req,scope,&block) @name=name @request=req @valid=true @scope_object=scope @output_filters=[] @proceed=true @pluginfactory = Jerakia::Lookup::PluginFactory.new if opts[:use] Array(opts[:use]).flatten.each do |plugin| plugin_load(plugin) end end instance_eval &block end |
Instance Attribute Details
#datasource(source, opts = {}) ⇒ Object (readonly)
Returns the value of attribute datasource.
8 9 10 |
# File 'lib/jerakia/lookup.rb', line 8 def datasource @datasource end |
#lookuptype ⇒ Object (readonly)
Returns the value of attribute lookuptype.
10 11 12 |
# File 'lib/jerakia/lookup.rb', line 10 def lookuptype @lookuptype end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/jerakia/lookup.rb', line 13 def name @name end |
#output_filters ⇒ Object (readonly)
Returns the value of attribute output_filters.
12 13 14 |
# File 'lib/jerakia/lookup.rb', line 12 def output_filters @output_filters end |
#pluginfactory ⇒ Object (readonly)
Returns the value of attribute pluginfactory.
15 16 17 |
# File 'lib/jerakia/lookup.rb', line 15 def pluginfactory @pluginfactory end |
#proceed ⇒ Object (readonly)
Returns the value of attribute proceed.
14 15 16 |
# File 'lib/jerakia/lookup.rb', line 14 def proceed @proceed end |
#request ⇒ Object
Returns the value of attribute request.
7 8 9 |
# File 'lib/jerakia/lookup.rb', line 7 def request @request end |
#scope_object ⇒ Object (readonly)
Returns the value of attribute scope_object.
11 12 13 |
# File 'lib/jerakia/lookup.rb', line 11 def scope_object @scope_object end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
9 10 11 |
# File 'lib/jerakia/lookup.rb', line 9 def valid @valid end |
Instance Method Details
#confine(key = nil, match) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/jerakia/lookup.rb', line 103 def confine(key=nil,match) if key invalidate unless get_matches(key,match).size > 0 else invalidate end end |
#continue ⇒ Object
lookup function: continue Will cause Jerakia to continue to the next lookup in the policy which is the default behaviour
83 84 85 |
# File 'lib/jerakia/lookup.rb', line 83 def continue @proceed = true end |
#exclude(key = nil, match) ⇒ Object
111 112 113 114 115 |
# File 'lib/jerakia/lookup.rb', line 111 def exclude(key=nil,match) if key invalidate if get_matches(key,match).size > 0 end end |
#get_matches(key, match) ⇒ Object
99 100 101 |
# File 'lib/jerakia/lookup.rb', line 99 def get_matches(key,match) matches = Array(match).select { |m| key[Regexp.new(m)] == key} end |
#invalidate ⇒ Object
lookup function: invalidate Setting invalidate will mean this lookup will be skipped in the policy
90 91 92 |
# File 'lib/jerakia/lookup.rb', line 90 def invalidate @valid=false end |
#output_filter(name, opts = {}) ⇒ Object
59 60 61 |
# File 'lib/jerakia/lookup.rb', line 59 def output_filter(name,opts={}) @output_filters << { :name => name, :opts => opts } end |
#plugin ⇒ Object
42 43 44 |
# File 'lib/jerakia/lookup.rb', line 42 def plugin @pluginfactory end |
#plugin_load(plugin) ⇒ Object
37 38 39 40 |
# File 'lib/jerakia/lookup.rb', line 37 def plugin_load(plugin) Jerakia.log.debug("Loading plugin #{plugin}") @pluginfactory.register(plugin, Jerakia::Lookup::Plugin.new(self)) end |
#proceed? ⇒ Boolean
63 64 65 |
# File 'lib/jerakia/lookup.rb', line 63 def proceed? @proceed end |
#run ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/jerakia/lookup.rb', line 118 def run Jerakia.log.verbose("lookup: #{@name} key: #{@request.key} namespace: #{@request.namespace.join('/')}") @datasource.run response=@datasource.response @output_filters.each do |filter| response.filter! filter[:name], filter[:opts] end return response end |
#scope ⇒ Object
If set, Jerakia will pass each Jerakia::Response object to an output filter plugin
54 55 56 |
# File 'lib/jerakia/lookup.rb', line 54 def scope @scope_object.value end |
#stop ⇒ Object
lookup function: stop Enabling stop sets @proceed to false, which will cause Jerakia not to load any more lookups in the policy if this lookup is deemed as valid. If the lookup is invalidated than Jerakia will progress to the next lookup. This is useful in conjuction with the confine plugin where we want to segregate some lookups but not worry about excluding from later lookups
75 76 77 |
# File 'lib/jerakia/lookup.rb', line 75 def stop @proceed = false end |
#valid? ⇒ Boolean
94 95 96 |
# File 'lib/jerakia/lookup.rb', line 94 def valid? return @valid end |