Module: Conduit::Core::Action::InstanceMethods

Extended by:
Forwardable
Defined in:
lib/conduit/core/action.rb

Instance Method Summary collapse

Instance Method Details

#initialize(**options) ⇒ Object



80
81
82
83
# File 'lib/conduit/core/action.rb', line 80

def initialize(**options)
  @options = options
  validate!(options)
end

#performObject

Entry method. The class will use use this to trigger the request.

Override to customize.



127
128
129
130
131
132
133
# File 'lib/conduit/core/action.rb', line 127

def perform
  response = request(body: view, method: :post)
  parser   = parser_class.new(response.body)

  Conduit::ApiResponse.new(raw_response: response,
    parser: parser)
end

#viewObject

Return the rendered view



116
117
118
119
120
# File 'lib/conduit/core/action.rb', line 116

def view
  tpl = self.class.name.demodulize
    .underscore.downcase
  render(tpl)
end

#view_contextObject

Object used for passing data to the view Only keys listed in attributes will be used.



100
101
102
103
104
# File 'lib/conduit/core/action.rb', line 100

def view_context
  OpenStruct.new(@options.select do |k, v|
    attributes.include?(k)
  end)
end

#view_pathObject

Location where the view files can be found Default to lib/conduit/drivers/<drivername>/views Can be overriden per class.



110
111
112
# File 'lib/conduit/core/action.rb', line 110

def view_path
  File.join(File.dirname(action_path), 'views')
end