Class: StubRequests::DSL
- Defined in:
- lib/stub_requests/dsl.rb,
lib/stub_requests/dsl/define_method.rb,
lib/stub_requests/dsl/method_definition.rb
Overview
Module DSL takes the id of a registered service
Defined Under Namespace
Classes: DefineMethod, MethodDefinition
Instance Attribute Summary collapse
- #endpoints ⇒ Object readonly
- #receiver ⇒ Object readonly
- #service ⇒ Object readonly
Instance Method Summary collapse
-
#define_stubs ⇒ void
Defines stub methods for #endpoints in the #receiver.
-
#initialize(service_id, receiver: nil) ⇒ DSL
constructor
Initialize a new instance of DSL.
- #method_definitions ⇒ Object
-
#print_stubs ⇒ void
Prints stub methods for #endpoints to STDOUT.
Constructor Details
#initialize(service_id, receiver: nil) ⇒ DSL
Initialize a new instance of DSL
92 93 94 95 |
# File 'lib/stub_requests/dsl.rb', line 92 def initialize(service_id, receiver: nil) @endpoints = StubRequests::EndpointRegistry[service_id] @receiver = receiver end |
Instance Attribute Details
#endpoints ⇒ Object (readonly)
84 85 86 |
# File 'lib/stub_requests/dsl.rb', line 84 def endpoints @endpoints end |
#receiver ⇒ Object (readonly)
80 81 82 |
# File 'lib/stub_requests/dsl.rb', line 80 def receiver @receiver end |
#service ⇒ Object (readonly)
76 77 78 |
# File 'lib/stub_requests/dsl.rb', line 76 def service @service end |
Instance Method Details
#define_stubs ⇒ void
This method returns an undefined value.
Defines stub methods for #endpoints in the #receiver
103 104 105 106 107 108 109 |
# File 'lib/stub_requests/dsl.rb', line 103 def define_stubs receiver.send(:include, StubRequests::API) method_definitions.each do |method_definition| DefineMethod.new(method_definition, receiver).define end end |
#method_definitions ⇒ Object
123 124 125 126 127 |
# File 'lib/stub_requests/dsl.rb', line 123 def method_definitions @method_definitions ||= endpoints.map do |endpoint| MethodDefinition.new(endpoint.id, endpoint.route_params) end end |
#print_stubs ⇒ void
This method returns an undefined value.
Prints stub methods for #endpoints to STDOUT
117 118 119 120 121 |
# File 'lib/stub_requests/dsl.rb', line 117 def print_stubs method_definitions.each do |method_definition| puts("#{method_definition}\n\n") end end |