Class: ActiveAgent::ActionPrompt::Collector

Inherits:
Object
  • Object
show all
Includes:
AbstractController::Collector
Defined in:
lib/active_agent/action_prompt/collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, &block) ⇒ Collector

Returns a new instance of Collector.



13
14
15
16
17
# File 'lib/active_agent/action_prompt/collector.rb', line 13

def initialize(context, &block)
  @context = context
  @responses = []
  @default_render = block
end

Instance Attribute Details

#responsesObject (readonly)

Returns the value of attribute responses.



11
12
13
# File 'lib/active_agent/action_prompt/collector.rb', line 11

def responses
  @responses
end

Instance Method Details

#any(*args, &block) ⇒ Object Also known as: all

Raises:

  • (ArgumentError)


19
20
21
22
23
# File 'lib/active_agent/action_prompt/collector.rb', line 19

def any(*args, &block)
  options = args.extract_options!
  raise ArgumentError, "You have to supply at least one format" if args.empty?
  args.each { |type| send(type, options.dup, &block) }
end

#custom(mime, options = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/active_agent/action_prompt/collector.rb', line 26

def custom(mime, options = {})
  options.reverse_merge!(content_type: mime.to_s)
  @context.formats = [mime.to_sym]
  options[:body] = block_given? ? yield : @default_render.call
  @responses << options
end