Class: Banalize::Runner
- Inherits:
-
Object
- Object
- Banalize::Runner
- Defined in:
- lib/banalize/runner.rb,
lib/banalize/exception.rb
Overview
Executing policy checks against bash file(s). Class instance is single bach file to check and single policy. Result of the check is returned in ‘@result` instance variable (and attr_accessor).
Instance attributes
-
‘@bash` - PATH to bash file
-
‘@policy` - [Hash] Policy configuration hash, key :klass contains
name of the class for Ruby policy. If Hash does not have :klass key, it's not a Ruby, execute it as shell policy.
-
‘@result` - Currenty returns only Boolean (true - check OK/false
check fail). This can change later.
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#bash ⇒ Object
Returns the value of attribute bash.
-
#policy ⇒ Object
Returns the value of attribute policy.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(bash, policy) ⇒ Runner
constructor
Create new instance of policy check runner and execute it.
-
#ruby ⇒ Object
Execute ruby check.
-
#shell ⇒ Object
Execute shell check.
Constructor Details
#initialize(bash, policy) ⇒ Runner
Create new instance of policy check runner and execute it. Result of the check is returned in @result attribute.
58 59 60 61 62 63 64 65 66 |
# File 'lib/banalize/runner.rb', line 58 def initialize bash,policy @bash, @policy, @result = bash, policy, nil if @policy.has_key? :klass ruby else shell end end |
Instance Attribute Details
#bash ⇒ Object
Returns the value of attribute bash.
68 69 70 |
# File 'lib/banalize/runner.rb', line 68 def bash @bash end |
#policy ⇒ Object
Returns the value of attribute policy.
68 69 70 |
# File 'lib/banalize/runner.rb', line 68 def policy @policy end |
#result ⇒ Object
Returns the value of attribute result.
68 69 70 |
# File 'lib/banalize/runner.rb', line 68 def result @result end |
Instance Method Details
#ruby ⇒ Object
Execute ruby check
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/banalize/runner.rb', line 73 def ruby object = policy[:klass].constantize.new(bash) # Policy executed by default unless it explicitly deactivated res = object.default[:active] == false ? true : object.run @result = { :status => res ? true : false, :messages => Errors.to_s(object.errors.) } end |
#shell ⇒ Object
Execute shell check
88 89 90 91 92 93 94 |
# File 'lib/banalize/runner.rb', line 88 def shell err = %x{ #{policy[:path]} #{bash} } @result = { :status => ($?.exitstatus == 0), :messages => err } end |