Class: ActiveAgent::Preview
- Inherits:
-
Object
- Object
- ActiveAgent::Preview
- Extended by:
- ActiveSupport::DescendantsTracker
- Defined in:
- lib/active_agent/preview.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.all ⇒ Object
Returns all agent preview classes.
-
.call(context, params = {}) ⇒ Object
Returns the prompt object for the given context.
-
.exists?(preview) ⇒ Boolean
Returns
true
if the preview exists. -
.find(preview) ⇒ Object
Find a agent preview by its underscored class name.
-
.preview_name ⇒ Object
Returns the underscored name of the agent preview without the suffix.
-
.prompt_exists?(prompt) ⇒ Boolean
Returns
true
if the prompt exists. -
.prompts ⇒ Object
Returns all of the available prompt previews.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Preview
constructor
A new instance of Preview.
Constructor Details
#initialize(params = {}) ⇒ Preview
Returns a new instance of Preview.
64 65 66 |
# File 'lib/active_agent/preview.rb', line 64 def initialize(params = {}) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
62 63 64 |
# File 'lib/active_agent/preview.rb', line 62 def params @params end |
Class Method Details
.all ⇒ Object
Returns all agent preview classes.
70 71 72 73 |
# File 'lib/active_agent/preview.rb', line 70 def all load_previews if descendants.empty? descendants.sort_by { |agent| agent.name.titleize } end |
.call(context, params = {}) ⇒ Object
Returns the prompt object for the given context. The registered preview interceptors will be informed so that they can transform the message as they would if the mail was actually being delivered.
78 79 80 81 82 83 |
# File 'lib/active_agent/preview.rb', line 78 def call(context, params = {}) preview = new(params) prompt = preview.public_send(context) inform_preview_interceptors(prompt) prompt end |
.exists?(preview) ⇒ Boolean
Returns true
if the preview exists.
96 97 98 |
# File 'lib/active_agent/preview.rb', line 96 def exists?(preview) all.any? { |p| p.preview_name == preview } end |
.find(preview) ⇒ Object
Find a agent preview by its underscored class name.
101 102 103 |
# File 'lib/active_agent/preview.rb', line 101 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.
106 107 108 |
# File 'lib/active_agent/preview.rb', line 106 def preview_name name.delete_suffix("Preview").underscore end |
.prompt_exists?(prompt) ⇒ Boolean
Returns true
if the prompt exists.
91 92 93 |
# File 'lib/active_agent/preview.rb', line 91 def prompt_exists?(prompt) prompts.include?(prompt) end |
.prompts ⇒ Object
Returns all of the available prompt previews.
86 87 88 |
# File 'lib/active_agent/preview.rb', line 86 def prompts public_instance_methods(false).map(&:to_s).sort end |