Class: ActionAI::Preview

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
lib/action_ai/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.



31
32
33
# File 'lib/action_ai/preview.rb', line 31

def initialize(params = {})
  @params = params
end

Instance Attribute Details

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/action_ai/preview.rb', line 55

def action_exists?(action)
  actions.include?(action)
end

.actionsObject

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

.allObject

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)
  message = preview.public_send(action)
  message
end

.exists?(preview) ⇒ Boolean

Returns true if the preview exists.

Returns:

  • (Boolean)


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_nameObject

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