class Gambiarra::View
Attributes
descendants[R]
parent[RW]
params[R]
path[R]
Public Class Methods
inherited(subclass)
click to toggle source
# 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
new(**params)
click to toggle source
# File lib/gambiarra/view.rb, line 42 def initialize(**params) @params = params end
questions(question_data)
click to toggle source
# File lib/gambiarra/view.rb, line 21 def questions(question_data) @questions.merge!(question_data) @questions.compact! end
render(view)
click to toggle source
# File lib/gambiarra/view.rb, line 37 def render(view) view.render end
respond(**params)
click to toggle source
# 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)
click to toggle source
# File lib/gambiarra/view.rb, line 26 def set_path(value) @params[:path] = value end
Public Instance Methods
ensure_param(param_name, &block)
click to toggle source
# 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)
click to toggle source
# File lib/gambiarra/view.rb, line 50 def go_to(path, **params) # App.router.set_next(path, **params) and return end
output(object)
click to toggle source
# File lib/gambiarra/view.rb, line 46 def output(object) self.class.output(object) end