Class: Gambiarra::View
- Inherits:
-
Object
- Object
- Gambiarra::View
- Defined in:
- lib/gambiarra/view.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.descendants ⇒ Object
readonly
Returns the value of attribute descendants.
-
.parent ⇒ Object
Returns the value of attribute parent.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .inherited(subclass) ⇒ Object
- .questions(question_data) ⇒ Object
- .render(view) ⇒ Object
- .respond(**params) ⇒ Object
- .set_path(value) ⇒ Object
Instance Method Summary collapse
- #ensure_param(param_name, &block) ⇒ Object
- #go_to(path, **params) ⇒ Object
-
#initialize(**params) ⇒ View
constructor
A new instance of View.
- #output(object) ⇒ Object
Constructor Details
#initialize(**params) ⇒ View
Returns a new instance of View.
42 43 44 |
# File 'lib/gambiarra/view.rb', line 42 def initialize(**params) @params = params end |
Class Attribute Details
.descendants ⇒ Object (readonly)
Returns the value of attribute descendants.
8 9 10 |
# File 'lib/gambiarra/view.rb', line 8 def descendants @descendants end |
.parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/gambiarra/view.rb', line 9 def parent @parent end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/gambiarra/view.rb', line 5 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/gambiarra/view.rb', line 5 def path @path end |
Class Method Details
.inherited(subclass) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/gambiarra/view.rb', line 11 def inherited(subclass) @descendants ||= {} subclass.parent = self new_descendant = { subclass.to_s.split('::').last.to_sym => subclass } @descendants.merge!(new_descendant) parent&.descendants&.merge!(new_descendant) @questions ||= {} subclass.instance_variable_set(:@questions, @questions.deep_dup) end |
.questions(question_data) ⇒ Object
21 22 23 24 |
# File 'lib/gambiarra/view.rb', line 21 def questions(question_data) @questions.merge!(question_data) @questions.compact! end |
.render(view) ⇒ Object
37 38 39 |
# File 'lib/gambiarra/view.rb', line 37 def render(view) view.render end |
.respond(**params) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/gambiarra/view.rb', line 30 def respond(**params) remaining_questions = @questions.slice(*(@questions.keys - params.keys)) return { questions: remaining_questions, **params } if remaining_questions.any? view = new(**params) { content: render(view), **params } end |
.set_path(value) ⇒ Object
26 27 28 |
# File 'lib/gambiarra/view.rb', line 26 def set_path(value) @params[:path] = value end |
Instance Method Details
#ensure_param(param_name, &block) ⇒ Object
54 55 56 |
# File 'lib/gambiarra/view.rb', line 54 def ensure_param(param_name, &block) @params[param_name] = block.call if @params[param_name].nil? end |
#go_to(path, **params) ⇒ Object
50 51 52 |
# File 'lib/gambiarra/view.rb', line 50 def go_to(path, **params) # App.router.set_next(path, **params) and return end |
#output(object) ⇒ Object
46 47 48 |
# File 'lib/gambiarra/view.rb', line 46 def output(object) self.class.output(object) end |