Class: ApiSketch::Model::Resource
- Defined in:
- lib/api_sketch/model/resource.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#format ⇒ Object
Returns the value of attribute format.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#path ⇒ Object
Returns the value of attribute path.
-
#responses ⇒ Object
Returns the value of attribute responses.
-
#sample_call ⇒ Object
Returns the value of attribute sample_call.
-
#sample_response ⇒ Object
Returns the value of attribute sample_response.
Attributes inherited from Base
Class Method Summary collapse
- .add(resource) ⇒ Object
- .all ⇒ Object
- .count ⇒ Object
- .create(attributes) ⇒ Object
- .find(id) ⇒ Object
- .find_by_http_method_and_path(http_method, path) ⇒ Object
- .first ⇒ Object
- .last ⇒ Object
- .reload!(definitions_dir) ⇒ Object
- .reset! ⇒ Object
Instance Method Summary collapse
-
#id ⇒ Object
TODO: update this method to provide better id that is used as part of filename.
Methods inherited from Base
Constructor Details
This class inherits a constructor from ApiSketch::Model::Base
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def action @action end |
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def format @format end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def headers @headers end |
#http_method ⇒ Object
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 |
#namespace ⇒ Object
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def namespace @namespace end |
#parameters ⇒ Object
Returns the value of attribute parameters.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def parameters @parameters end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def path @path end |
#responses ⇒ Object
Returns the value of attribute responses.
3 4 5 |
# File 'lib/api_sketch/model/resource.rb', line 3 def responses @responses end |
#sample_call ⇒ Object
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_response ⇒ Object
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 |
.all ⇒ Object
34 35 36 |
# File 'lib/api_sketch/model/resource.rb', line 34 def all @resources ||= [] end |
.count ⇒ Object
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 |
.first ⇒ Object
46 47 48 |
# File 'lib/api_sketch/model/resource.rb', line 46 def first self.all.first end |
.last ⇒ Object
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
#id ⇒ Object
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 |