Class: CabbageDoc::Controller
- Inherits:
-
Object
- Object
- CabbageDoc::Controller
- Defined in:
- lib/cabbage_doc/controller.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Instance Method Summary collapse
- #eval(text) ⇒ Object
- #find_action(method, path) ⇒ Object
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #parse(text) ⇒ Object
- #valid? ⇒ Boolean
Methods included from Cloneable
Methods included from Parser
included, #parse_option, #parse_templates
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
8 9 10 11 |
# File 'lib/cabbage_doc/controller.rb', line 8 def initialize @actions = [] @visibility = VISIBILITY.first end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def actions @actions end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def klass @klass end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def path @path end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def visibility @visibility end |
Instance Method Details
#eval(text) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cabbage_doc/controller.rb', line 34 def eval(text) return [self] unless template? templates = [] templates += parse_templates(@path) templates += parse_templates(@label) return [] unless templates.any? count = templates.first[:values].count (1..count).map do |i| template_text = text.dup templates.each do |template| template_text.gsub!(template[:text], template[:values].shift.to_s) end self.class.parse(template_text) end.compact end |
#find_action(method, path) ⇒ Object
28 29 30 31 32 |
# File 'lib/cabbage_doc/controller.rb', line 28 def find_action(method, path) @actions.detect do |action| action.method == method && action.path == path end end |
#parse(text) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cabbage_doc/controller.rb', line 13 def parse(text) @label, @path, @klass, @visibility = parse_label_path_class_and_visibility(text) return false unless @label && @klass @name = compose_name(klass) @actions = parse_actions(text) unless template? valid? end |
#valid? ⇒ Boolean
24 25 26 |
# File 'lib/cabbage_doc/controller.rb', line 24 def valid? @name && (actions? || template?) end |