Class: ActionViewPreview::Base
- Inherits:
-
Object
- Object
- ActionViewPreview::Base
- Extended by:
- ActiveSupport::DescendantsTracker
- Defined in:
- lib/action_view_preview/base.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.all ⇒ Object
Returns all preview classes.
- .call(view_action, params = {}) ⇒ Object
-
.exists?(preview) ⇒ Boolean
Returns
true
if the preview exists. -
.find(preview) ⇒ Object
Find a preview by its underscored class name.
-
.preview_name ⇒ Object
Returns the underscored name of the preview without the suffix.
-
.view_exists?(view) ⇒ Boolean
Returns
true
if the view exists. -
.views ⇒ Object
Returns all of the available views.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/action_view_preview/base.rb', line 7 def initialize(params = {}) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/action_view_preview/base.rb', line 5 def params @params end |
Class Method Details
.all ⇒ Object
Returns all preview classes
19 20 21 22 |
# File 'lib/action_view_preview/base.rb', line 19 def all load_previews if descendants.empty? descendants end |
.call(view_action, params = {}) ⇒ Object
13 14 15 16 |
# File 'lib/action_view_preview/base.rb', line 13 def call(view_action, params = {}) preview = new(params) preview.public_send(view_action) end |
.exists?(preview) ⇒ Boolean
Returns true
if the preview exists
45 46 47 |
# File 'lib/action_view_preview/base.rb', line 45 def exists?(preview) all.any? { |p| p.preview_name == preview } end |
.find(preview) ⇒ Object
Find a preview by its underscored class name
40 41 42 |
# File 'lib/action_view_preview/base.rb', line 40 def find(preview) all.find { |p| p.preview_name == preview } end |
.preview_name ⇒ Object
Returns the underscored name of the preview without the suffix
35 36 37 |
# File 'lib/action_view_preview/base.rb', line 35 def preview_name name.delete_suffix("Preview").underscore end |
.view_exists?(view) ⇒ Boolean
Returns true
if the view exists.
30 31 32 |
# File 'lib/action_view_preview/base.rb', line 30 def view_exists?(view) views.include?(view) end |
.views ⇒ Object
Returns all of the available views
25 26 27 |
# File 'lib/action_view_preview/base.rb', line 25 def views public_instance_methods(false).map(&:to_s).sort end |