Class: Conduit::Request

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Concerns::Storage
Defined in:
app/models/conduit/request.rb

Instance Method Summary collapse

Instance Method Details

#contentObject

Overriding this method fixes an issue where content isn’t set until after the raw action is instantiated



34
35
36
# File 'app/models/conduit/request.rb', line 34

def content
  raw.view || super
end

#perform_requestObject

Perform the requested action for the specified driver



41
42
43
44
45
# File 'app/models/conduit/request.rb', line 41

def perform_request
  if response = raw.perform
    responses.create(content: response.body)
  end
end

#subscribersObject

Fetch a list of subscribers through the subscriptions association

NOTE: This is usually possible by default with a

has_many :through, but with polymorphic
association it gets more complicated.


68
69
70
# File 'app/models/conduit/request.rb', line 68

def subscribers
  subscriptions.map(&:subscriber)
end

#subscribers=(args) ⇒ Object

Allow creation of subscriptions through the subscribers virtual attribute.

NOTE: This is usually possible by default with a

has_many :through, but with polymorphic
association it gets more complicated.


54
55
56
57
58
59
# File 'app/models/conduit/request.rb', line 54

def subscribers=(args)
  args.map do |arg|
    next unless arg.class < ActiveRecord::Base
    subscriptions.build(subscriber: arg)
  end
end