Class: Jerakia::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/jerakia/launcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLauncher

Returns a new instance of Launcher.



13
14
15
16
17
18
19
20
# File 'lib/jerakia/launcher.rb', line 13

def initialize
  @policies = {}
  policy_files.each do |policy_file|
    policy = Jerakia::Dsl::Policy.evaluate_file(policy_file)
    raise Jerakia::PolicyError, "Policy #{policy.name} declared twice" if @policies[policy.name]
    @policies[policy.name] = policy
  end
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



10
11
12
# File 'lib/jerakia/launcher.rb', line 10

def answer
  @answer
end

#policiesObject (readonly)

Returns the value of attribute policies.



11
12
13
# File 'lib/jerakia/launcher.rb', line 11

def policies
  @policies
end

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/jerakia/launcher.rb', line 9

def request
  @request
end

Class Method Details

.evaluate(&block) ⇒ Object



34
35
36
# File 'lib/jerakia/launcher.rb', line 34

def self.evaluate(&block)
  Jerakia::Dsl::Policy.evaluate(&block)
end

Instance Method Details

#invoke_from_fileObject



38
39
40
41
42
43
44
45
# File 'lib/jerakia/launcher.rb', line 38

def invoke_from_file
  policy_name = request.policy.to_s
  Jerakia.log.debug "Invoked lookup for #{request.key} using policy #{policy_name}"
  filename = File.join(Jerakia.config.policydir, "#{policy_name}.rb")
  policy = Jerakia::Dsl::Policy.evaluate_file(filename, request)
  policy.execute
  @answer = policy.answer
end

#policy_dirObject



26
27
28
# File 'lib/jerakia/launcher.rb', line 26

def policy_dir
  Jerakia.config.policydir
end

#policy_exists?(policy) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/jerakia/launcher.rb', line 22

def policy_exists?(policy)
  @policies.has_key?(policy.to_sym)
end

#policy_filesObject



30
31
32
# File 'lib/jerakia/launcher.rb', line 30

def policy_files
  Dir[File.join(policy_dir, '*.rb')]
end