Class: ActionAI::Preview
- Inherits:
-
Object
- Object
- ActionAI::Preview
- Extended by:
- ActiveSupport::DescendantsTracker
- Defined in:
- lib/action_ai/preview.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.action_exists?(action) ⇒ Boolean
Returns
trueif the action exists. -
.actions ⇒ Object
Returns all of the available action previews.
-
.all ⇒ Object
Returns all agent preview classes.
-
.call(action, params = {}) ⇒ Object
Returns the message object for the given action name.
-
.exists?(preview) ⇒ Boolean
Returns
trueif the preview exists. -
.find(preview) ⇒ Object
Find an agent preview by its underscored class name.
-
.preview_name ⇒ Object
Returns the underscored name of the agent preview without the suffix.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Preview
constructor
A new instance of Preview.
Constructor Details
#initialize(params = {}) ⇒ Preview
Returns a new instance of Preview.
31 32 33 |
# File 'lib/action_ai/preview.rb', line 31 def initialize(params = {}) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
29 30 31 |
# File 'lib/action_ai/preview.rb', line 29 def params @params end |
Class Method Details
.action_exists?(action) ⇒ Boolean
Returns true if the action exists.
55 56 57 |
# File 'lib/action_ai/preview.rb', line 55 def action_exists?(action) actions.include?(action) end |
.actions ⇒ Object
Returns all of the available action previews.
50 51 52 |
# File 'lib/action_ai/preview.rb', line 50 def actions public_instance_methods(false).map(&:to_s).sort end |
.all ⇒ Object
Returns all agent preview classes.
37 38 39 40 |
# File 'lib/action_ai/preview.rb', line 37 def all load_previews if descendants.empty? descendants.sort_by { it.name.titleize } end |
.call(action, params = {}) ⇒ Object
Returns the message object for the given action name.
43 44 45 46 47 |
# File 'lib/action_ai/preview.rb', line 43 def call(action, params = {}) preview = new(params) = preview.public_send(action) end |
.exists?(preview) ⇒ Boolean
Returns true if the preview exists.
60 61 62 |
# File 'lib/action_ai/preview.rb', line 60 def exists?(preview) all.any? { |p| p.preview_name == preview } end |
.find(preview) ⇒ Object
Find an agent preview by its underscored class name.
65 66 67 |
# File 'lib/action_ai/preview.rb', line 65 def find(preview) all.find { |p| p.preview_name == preview } end |
.preview_name ⇒ Object
Returns the underscored name of the agent preview without the suffix.
70 71 72 |
# File 'lib/action_ai/preview.rb', line 70 def preview_name name.delete_suffix("Preview").underscore end |