Class: FakeApi::FakeApiData
- Inherits:
-
Object
- Object
- FakeApi::FakeApiData
- Defined in:
- lib/fake_api/data.rb
Instance Attribute Summary collapse
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Class Method Summary collapse
Instance Method Summary collapse
- #create_list(something, amount) ⇒ Object
- #delete(path) ⇒ Object
- #factory(name, &block) ⇒ Object
- #get(path) ⇒ Object
-
#initialize ⇒ FakeApiData
constructor
A new instance of FakeApiData.
- #object(something) ⇒ Object (also: #create, #build)
- #patch(path) ⇒ Object
- #post(path) ⇒ Object
- #put(path) ⇒ Object
- #response_or_value(e) ⇒ Object
- #route(request_method, route:, &block) ⇒ Object
Constructor Details
#initialize ⇒ FakeApiData
Returns a new instance of FakeApiData.
10 11 12 13 |
# File 'lib/fake_api/data.rb', line 10 def initialize @responses = {} @routes = {} end |
Instance Attribute Details
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
4 5 6 |
# File 'lib/fake_api/data.rb', line 4 def responses @responses end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
4 5 6 |
# File 'lib/fake_api/data.rb', line 4 def routes @routes end |
Class Method Details
.instance ⇒ Object
6 7 8 |
# File 'lib/fake_api/data.rb', line 6 def FakeApiData.instance @@instance ||= FakeApiData.new end |
Instance Method Details
#create_list(something, amount) ⇒ Object
52 53 54 55 56 |
# File 'lib/fake_api/data.rb', line 52 def create_list(something, amount) result = [] amount.times { result << response_or_value(something) } result end |
#delete(path) ⇒ Object
42 43 44 |
# File 'lib/fake_api/data.rb', line 42 def delete(path) route("DELETE", route: path) end |
#factory(name, &block) ⇒ Object
15 16 17 18 |
# File 'lib/fake_api/data.rb', line 15 def factory(name, &block) response = Factory.new(name: name, value: block) @responses[name] = response end |
#get(path) ⇒ Object
26 27 28 |
# File 'lib/fake_api/data.rb', line 26 def get(path) route("GET", route: path) end |
#object(something) ⇒ Object Also known as: create, build
46 47 48 |
# File 'lib/fake_api/data.rb', line 46 def object(something) response_or_value(something) end |
#patch(path) ⇒ Object
38 39 40 |
# File 'lib/fake_api/data.rb', line 38 def patch(path) route("PATCH", route: path) end |
#post(path) ⇒ Object
30 31 32 |
# File 'lib/fake_api/data.rb', line 30 def post(path) route("POST", route: path) end |
#put(path) ⇒ Object
34 35 36 |
# File 'lib/fake_api/data.rb', line 34 def put(path) route("PUT", route: path) end |
#response_or_value(e) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fake_api/data.rb', line 58 def response_or_value(e) if e.is_a?(Symbol) if response = FakeApiData.instance.responses[e] response.value.call else nil end else e end end |