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.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Instance Method Summary collapse
- #eval(text, tag) ⇒ Object
- #find_action(method, path) ⇒ Object
-
#initialize(tag = TAG) ⇒ Controller
constructor
A new instance of Controller.
- #parse(text, tag = TAG) ⇒ Object
- #valid? ⇒ Boolean
Methods included from Cloneable
Methods included from Parser
included, #parse_option, #parse_templates
Constructor Details
#initialize(tag = TAG) ⇒ Controller
Returns a new instance of Controller.
8 9 10 11 12 |
# File 'lib/cabbage_doc/controller.rb', line 8 def initialize(tag = TAG) @actions = [] @visibility = VISIBILITY.first @tag = tag 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 |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
6 7 8 |
# File 'lib/cabbage_doc/controller.rb', line 6 def tag @tag 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, tag) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cabbage_doc/controller.rb', line 35 def eval(text, tag) 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, tag) end.compact end |
#find_action(method, path) ⇒ Object
29 30 31 32 33 |
# File 'lib/cabbage_doc/controller.rb', line 29 def find_action(method, path) @actions.detect do |action| action.method == method && action.path == path end end |
#parse(text, tag = TAG) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cabbage_doc/controller.rb', line 14 def parse(text, tag = TAG) @label, @path, @klass, @visibility, @tag = parse_label_path_class_visibility_and_tag(text, tag) return false unless @label && @klass @name = compose_name(klass) @actions = parse_actions(text) unless template? valid? end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/cabbage_doc/controller.rb', line 25 def valid? @name && (actions? || template?) end |