Class: SSH::Allow::Rule
- Inherits:
-
Object
- Object
- SSH::Allow::Rule
- Defined in:
- lib/ssh/allow/rule.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #args(arg_text) ⇒ Object
-
#initialize(cmds) ⇒ Rule
constructor
A new instance of Rule.
- #match_arguments?(arg_list) ⇒ Boolean
- #match_command?(name) ⇒ Boolean
- #match_options?(opt_list) ⇒ Boolean
- #opts(opt_text) ⇒ Object
Constructor Details
#initialize(cmds) ⇒ Rule
Returns a new instance of Rule.
6 7 8 9 10 |
# File 'lib/ssh/allow/rule.rb', line 6 def initialize(cmds) @command = [cmds].flatten @options = [:none] @arguments = [:none] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/ssh/allow/rule.rb', line 4 def arguments @arguments end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
4 5 6 |
# File 'lib/ssh/allow/rule.rb', line 4 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/ssh/allow/rule.rb', line 4 def @options end |
Class Method Details
.allow(*cmds, &block) ⇒ Object
62 63 64 |
# File 'lib/ssh/allow/rule.rb', line 62 def allow(*cmds, &block) create(Rule::Allow.new(cmds.flatten), &block) end |
.create(rule, &block) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/ssh/allow/rule.rb', line 70 def create(rule, &block) begin rule.instance_eval(&block) if block_given? rule rescue Exception => e false end end |
Instance Method Details
#args(arg_text) ⇒ Object
17 18 19 20 |
# File 'lib/ssh/allow/rule.rb', line 17 def args(arg_text) arg_text = Regexp.new(arg_text) if arg_text.is_a?(String) push(:arguments, arg_text) end |
#match_arguments?(arg_list) ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/ssh/allow/rule.rb', line 35 def match_arguments?(arg_list) return arg_list.empty? if none?(arguments) return true if any?(arguments) return false if arguments.size != arg_list.size arg_list.inject(true) { |match, arg| match && match_one_argument?(arg) } end |
#match_command?(name) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/ssh/allow/rule.rb', line 22 def match_command?(name) return false if none?(command) return true if any?(command) command.include?(name) end |
#match_options?(opt_list) ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/ssh/allow/rule.rb', line 28 def (opt_list) return opt_list.empty? if none?() return true if any?() return false if .size != opt_list.size opt_list.inject(true) { |match, opt| match && .include?(opt) } end |
#opts(opt_text) ⇒ Object
12 13 14 15 |
# File 'lib/ssh/allow/rule.rb', line 12 def opts(opt_text) opt_text.gsub!(/^--?/, '') if opt_text.is_a?(String) push(:options, opt_text) end |