Class: Coupdoeil::Popover
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- Coupdoeil::Popover
show all
- Includes:
- AbstractController::Caching, AbstractController::Callbacks, AbstractController::Helpers, AbstractController::Logger, AbstractController::Rendering, AbstractController::Translation, ActionController::Cookies, ActionController::Helpers, ActionView::Layouts, ActionView::Rendering, LazyLoading
- Defined in:
- app/models/coupdoeil/popover.rb,
app/models/coupdoeil/popover/setup.rb,
app/models/coupdoeil/popover/option.rb,
app/models/coupdoeil/popover/registry.rb,
app/models/coupdoeil/popover/options_set.rb,
app/models/coupdoeil/popover/lazy_loading.rb,
app/models/coupdoeil/popover/option/cache.rb,
app/models/coupdoeil/popover/option/offset.rb,
app/models/coupdoeil/popover/option/loading.rb,
app/models/coupdoeil/popover/option/trigger.rb,
app/models/coupdoeil/popover/option/animation.rb,
app/models/coupdoeil/popover/option/placement.rb,
app/models/coupdoeil/popover/option/opening_delay.rb
Defined Under Namespace
Modules: LazyLoading
Classes: Option, OptionsSet, Registry, Setup
Constant Summary
collapse
- DoubleRenderError =
Class.new(::AbstractController::DoubleRenderError)
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#lazy_loading!, #lazy_loading?, #loader_template
Constructor Details
#initialize(raw_params, context_controller) ⇒ Popover
Returns a new instance of Popover.
115
116
117
118
119
|
# File 'app/models/coupdoeil/popover.rb', line 115
def initialize(raw_params, context_controller)
super()
@raw_params = raw_params
@context_controller = context_controller
end
|
Class Attribute Details
.registry ⇒ Object
Returns the value of attribute registry.
61
62
63
|
# File 'app/models/coupdoeil/popover.rb', line 61
def registry
@registry
end
|
Instance Attribute Details
#context_controller ⇒ Object
Returns the value of attribute context_controller.
109
110
111
|
# File 'app/models/coupdoeil/popover.rb', line 109
def context_controller
@context_controller
end
|
Class Method Details
.default_options ⇒ Object
72
|
# File 'app/models/coupdoeil/popover.rb', line 72
def default_options(...) = default_options_for(DEFAULT_OPTIONS_KEY, ...)
|
.default_options_for(*action_names, **option_values) ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'app/models/coupdoeil/popover.rb', line 74
def default_options_for(*action_names, **option_values)
if option_values.blank?
@default_options_by_method[action_names.first] || default_options
else
action_names.each do |action_name|
options = @default_options_by_method[action_name] || default_options
@default_options_by_method[action_name] = options.merge(OptionsSet.new(option_values))
end
end
end
|
.inherited(subclass) ⇒ Object
66
67
68
69
70
|
# File 'app/models/coupdoeil/popover.rb', line 66
def inherited(subclass)
super
Coupdoeil::Popover.registry.register(subclass.popover_resource_name, subclass)
subclass.instance_variable_set(:@default_options_by_method, @default_options_by_method.dup)
end
|
.method_missing(method_name, *args) ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'app/models/coupdoeil/popover.rb', line 85
def method_missing(method_name, *args, &)
return super unless action_methods.include?(method_name.name)
action_methods.each do |action_name|
define_singleton_method(action_name) { setup_class.new(self).with_type(action_name) }
end
public_send(method_name)
end
|
.popover_resource_name ⇒ Object
63
|
# File 'app/models/coupdoeil/popover.rb', line 63
def popover_resource_name = @popover_resource_name ||= name.delete_suffix("Popover").underscore
|
.respond_to_missing?(method, include_all = false) ⇒ Boolean
94
95
96
|
# File 'app/models/coupdoeil/popover.rb', line 94
def respond_to_missing?(method, include_all = false)
action_methods.include?(method.name) || super
end
|
.setup_class ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'app/models/coupdoeil/popover.rb', line 98
def setup_class
@setup_class ||= begin
setup_klass = Class.new(Setup)
action_methods.each do |action_name|
setup_klass.define_method(action_name) { with_type(action_name) }
end
setup_klass
end
end
|
.with ⇒ Object
64
|
# File 'app/models/coupdoeil/popover.rb', line 64
def with(...) = setup_class.new(self).with_params(...)
|
Instance Method Details
#controller ⇒ Object
130
|
# File 'app/models/coupdoeil/popover.rb', line 130
def controller = context_controller
|
#instrument_render(method_name, &block) ⇒ Object
144
145
146
|
# File 'app/models/coupdoeil/popover.rb', line 144
def instrument_render(method_name, &block)
ActiveSupport::Notifications.instrument("render_popover.coupdoeil", &block)
end
|
#params ⇒ HashWithIndifferentAccess
Returns the deserialized popover params that were given to ‘.with`.
156
157
158
159
160
161
162
163
164
165
|
# File 'app/models/coupdoeil/popover.rb', line 156
def params
@params ||=
if @raw_params&.is_a?(String)
parsed_params = JSON.parse(@raw_params)
parsed_params = Coupdoeil::Params.deserialize(parsed_params).sole
parsed_params.with_indifferent_access
else
@raw_params.with_indifferent_access
end
end
|
#process(method_name) ⇒ Object
148
149
150
151
152
153
|
# File 'app/models/coupdoeil/popover.rb', line 148
def process(method_name, ...)
instrument_render(method_name) do
super
response_body || render(action_name)
end
end
|
#render ⇒ Object
137
138
139
140
141
142
|
# File 'app/models/coupdoeil/popover.rb', line 137
def render(...)
return super unless response_body
raise DoubleRenderError, "Render was called multiple times in this action. \
Also note that render does not terminate execution of the action."
end
|