Module: Served::Resource::Requestable

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/served/resource/requestable.rb

Defined Under Namespace

Modules: ClassMethods Classes: HandlerRequired

Constant Summary collapse

HEADERS =
{ 'Content-type' => 'application/json', 'Accept' => 'application/json' }.freeze

Instance Method Summary collapse

Instance Method Details

#destroy(params = {}) ⇒ Boolean|self

Destroys the record on the service. Acts on status code If code is a 204 (no content) it will simply return true otherwise it will parse the response and reloads the instance

Returns:

  • (Boolean|self)

    Returns true or instance



159
160
161
162
163
164
# File 'lib/served/resource/requestable.rb', line 159

def destroy(params = {})
  result = delete(params)
  return result if result.is_a?(TrueClass)

  reload_with_attributes(result)
end

#reload(params = {}) ⇒ self

Reloads the resource using attributes from the service

Returns:

  • (self)

    self



149
150
151
152
# File 'lib/served/resource/requestable.rb', line 149

def reload(params = {})
  reload_with_attributes(get(params))
  self
end

#saveBoolean

Saves the record to the service. Will call POST if the record does not have an id, otherwise will call PUT to update the record

Returns:

  • (Boolean)

    returns true or false depending on save success



142
143
144
# File 'lib/served/resource/requestable.rb', line 142

def save
  id ? reload_with_attributes(put) : reload_with_attributes(post)
end