Class: Smith::ACLParser
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- Smith::ACLParser
- Defined in:
- lib/smith/acl_parser.rb
Instance Method Summary collapse
-
#class_name ⇒ Object
Returns the first class in the list, or :main.
- #fully_qualified_classes ⇒ Object
- #go(ruby) ⇒ Object
-
#in_class(name) ⇒ Object
Adds name to the class stack, for the duration of the block.
-
#initialize ⇒ ACLParser
constructor
A new instance of ACLParser.
-
#process_class(exp) ⇒ Object
Process Class method.
- #process_module(exp) ⇒ Object
-
#process_until_empty(exp) ⇒ Object
Process each element of #exp in turn.
-
#reset ⇒ Object
Reset @classes data.
Constructor Details
#initialize ⇒ ACLParser
Returns a new instance of ACLParser.
12 13 14 15 16 17 |
# File 'lib/smith/acl_parser.rb', line 12 def initialize super() @class_stack = [] self.auto_shift_type = true self.reset end |
Instance Method Details
#class_name ⇒ Object
Returns the first class in the list, or :main
32 33 34 35 36 37 38 |
# File 'lib/smith/acl_parser.rb', line 32 def class_name if @class_stack.any? @class_stack.reverse else :main end end |
#fully_qualified_classes ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/smith/acl_parser.rb', line 45 def fully_qualified_classes @classes.delete(:main) @classes.inject([]) do |a, class_method| a.tap do |acc| acc << class_method end end end |
#go(ruby) ⇒ Object
19 20 21 22 |
# File 'lib/smith/acl_parser.rb', line 19 def go(ruby) @parser = RubyParser.new process(@parser.process(ruby)) end |
#in_class(name) ⇒ Object
Adds name to the class stack, for the duration of the block
25 26 27 28 29 |
# File 'lib/smith/acl_parser.rb', line 25 def in_class(name) @class_stack.unshift(name) yield @class_stack.shift end |
#process_class(exp) ⇒ Object
Process Class method
60 61 62 63 64 65 66 |
# File 'lib/smith/acl_parser.rb', line 60 def process_class(exp) in_class(exp.shift) do process_until_empty exp @classes << class_name end s() end |
#process_module(exp) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/smith/acl_parser.rb', line 68 def process_module(exp) in_class exp.shift do process_until_empty exp end s() end |
#process_until_empty(exp) ⇒ Object
Process each element of #exp in turn.
41 42 43 |
# File 'lib/smith/acl_parser.rb', line 41 def process_until_empty(exp) process(exp.shift) until exp.empty? end |
#reset ⇒ Object
Reset @classes data
55 56 57 |
# File 'lib/smith/acl_parser.rb', line 55 def reset @classes = Set.new end |