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.
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 |
# File 'lib/cabbage_doc/controller.rb', line 8 def initialize @actions = [] 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 |
Instance Method Details
#eval(text) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cabbage_doc/controller.rb', line 33 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
27 28 29 30 31 |
# File 'lib/cabbage_doc/controller.rb', line 27 def find_action(method, path) @actions.detect do |action| action.method == method && action.path == path end end |
#parse(text) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cabbage_doc/controller.rb', line 12 def parse(text) @label, @path, @klass = parse_label_path_and_class(text) return false unless @label && @klass @name = compose_name(klass) @actions = parse_actions(text) unless template? valid? end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/cabbage_doc/controller.rb', line 23 def valid? @name && (actions? || template?) end |