Class: ActiveAgent::Preview

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
lib/active_agent/preview.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#paramsObject (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

.allObject

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.

Returns:

  • (Boolean)


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_nameObject

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.

Returns:

  • (Boolean)


91
92
93
# File 'lib/active_agent/preview.rb', line 91

def prompt_exists?(prompt)
  prompts.include?(prompt)
end

.promptsObject

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