Module: Eipiai::SingularResource

Defined in:
lib/eipiai/resources/singular.rb

Overview

SingularResource

The singular resource is the basis for a resource representing a single object.

It provides basic GET, PUT and DELETE support.

It is the singular version of the ‘CollectionResource` resource.

Instance Method Summary collapse

Instance Method Details

#allowed_methodsObject



19
20
21
# File 'lib/eipiai/resources/singular.rb', line 19

def allowed_methods
  %w(GET POST PUT DELETE)
end

#create_pathObject



27
28
29
# File 'lib/eipiai/resources/singular.rb', line 27

def create_path
  request.uri.path
end

#delete_resourceObject



31
32
33
34
35
36
# File 'lib/eipiai/resources/singular.rb', line 31

def delete_resource
  object.destroy
  @object = nil

  true
end

#from_jsonObject



38
39
40
# File 'lib/eipiai/resources/singular.rb', line 38

def from_json
  request.put? ? put_from_json : post_from_json
end

#resource_exists?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/eipiai/resources/singular.rb', line 23

def resource_exists?
  object.present?
end