Class: ApiSketch::Model::Resource

Inherits:
Base
  • Object
show all
Defined in:
lib/api_sketch/model/resource.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ApiSketch::Model::Base

Instance Attribute Details

#actionObject

Returns the value of attribute action.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def action
  @action
end

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def format
  @format
end

#headersObject

Returns the value of attribute headers.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def headers
  @headers
end

#http_methodObject

Returns the value of attribute http_method.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def http_method
  @http_method
end

#namespaceObject

Returns the value of attribute namespace.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def namespace
  @namespace
end

#parametersObject

Returns the value of attribute parameters.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def parameters
  @parameters
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def path
  @path
end

#responsesObject

Returns the value of attribute responses.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def responses
  @responses
end

#sample_callObject

Returns the value of attribute sample_call.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def sample_call
  @sample_call
end

#sample_responseObject

Returns the value of attribute sample_response.



3
4
5
# File 'lib/api_sketch/model/resource.rb', line 3

def sample_response
  @sample_response
end

Class Method Details

.add(resource) ⇒ Object



19
20
21
22
# File 'lib/api_sketch/model/resource.rb', line 19

def add(resource)
  @resources ||= []
  @resources << resource
end

.allObject



34
35
36
# File 'lib/api_sketch/model/resource.rb', line 34

def all
  @resources ||= []
end

.countObject



54
55
56
# File 'lib/api_sketch/model/resource.rb', line 54

def count
  self.all.count
end

.create(attributes) ⇒ Object



12
13
14
15
16
17
# File 'lib/api_sketch/model/resource.rb', line 12

def create(attributes)
  res = self.new(attributes)
  res.send(:run_validations!)
  self.add(res)
  res
end

.find(id) ⇒ Object



38
39
40
# File 'lib/api_sketch/model/resource.rb', line 38

def find(id)
  self.all.find { |res| res.id == id }
end

.find_by_http_method_and_path(http_method, path) ⇒ Object



42
43
44
# File 'lib/api_sketch/model/resource.rb', line 42

def find_by_http_method_and_path(http_method, path)
  self.all.find { |res| res.http_method == http_method && res.path == path }
end

.firstObject



46
47
48
# File 'lib/api_sketch/model/resource.rb', line 46

def first
  self.all.first
end

.lastObject



50
51
52
# File 'lib/api_sketch/model/resource.rb', line 50

def last
  self.all.last
end

.reload!(definitions_dir) ⇒ Object



28
29
30
31
32
# File 'lib/api_sketch/model/resource.rb', line 28

def reload!(definitions_dir)
  ApiSketch::Model::SharedBlock.reset!
  self.reset!
  ApiSketch::DSL.new(definitions_dir).init!
end

.reset!Object



24
25
26
# File 'lib/api_sketch/model/resource.rb', line 24

def reset!
  @resources = []
end

Instance Method Details

#idObject

TODO: update this method to provide better id that is used as part of filename



6
7
8
# File 'lib/api_sketch/model/resource.rb', line 6

def id
  [self.namespace, self.action].reject { |v| v.nil? || v == "" }.join("/")
end