Module: Poisol::StubInstance
- Included in:
- StubBuilder
- Defined in:
- lib/poisol/stub/stub_builder_instance.rb
Instance Method Summary collapse
- #by(input_hash) ⇒ Object
- #for(input_hash) ⇒ Object
- #get_assignment_value(actual_field_value, input_value) ⇒ Object
- #has(input_hash) ⇒ Object
- #init_request ⇒ Object
- #init_response ⇒ Object
- #initialize ⇒ Object
- #is_empty ⇒ Object
- #remove_array_field_calls ⇒ Object
- #set_dumb_response(response_file) ⇒ Object
- #status(input) ⇒ Object
Instance Method Details
#by(input_hash) ⇒ Object
47 48 49 50 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 47 def by input_hash @request.body.deep_merge! input_hash self end |
#for(input_hash) ⇒ Object
63 64 65 66 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 63 def for input_hash @request.query.deep_merge! input_hash.stringify_keys self end |
#get_assignment_value(actual_field_value, input_value) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 38 def get_assignment_value actual_field_value, input_value if actual_field_value.class.to_s == "Hash" input_value = {} if input_value.blank? actual_field_value.deep_merge(input_value.stringify_keys) else input_value end end |
#has(input_hash) ⇒ Object
52 53 54 55 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 52 def has input_hash @response.body.deep_merge! input_hash.stringify_keys self end |
#init_request ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 9 def init_request @request = Request.new @request.type = stub_config.request.type @request.path = stub_config.request.url.deep_dup @request.query = stub_config.request.query_explicit ? {} : stub_config.request.query.deep_dup @request.body = stub_config.request.body_explicit ? {} : stub_config.request.body.deep_dup end |
#init_response ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 17 def init_response @response = Response.new if stub_config.response.is_column_array or stub_config.response.is_row_array @response.body = [stub_config.response.body.deep_dup] else @response.body = stub_config.response.body.deep_dup end @response.status = 200 @response.header = {'Content-Type' => 'application/json'} if (stub_config.response.header) @response.header.merge! stub_config.response.header end end |
#initialize ⇒ Object
3 4 5 6 7 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 3 def initialize init_request init_response @called_methods = [] end |
#is_empty ⇒ Object
57 58 59 60 61 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 57 def is_empty @response.body = (stub_config.response.is_column_array or stub_config.response.is_row_array) ? [] : {} @is_response_dumped = true self end |
#remove_array_field_calls ⇒ Object
73 74 75 76 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 73 def remove_array_field_calls method_of_array_fileds_of_array = self.methods.select { |method_name| method_name.to_s.start_with? "with_" } @called_methods = @called_methods - method_of_array_fileds_of_array end |
#set_dumb_response(response_file) ⇒ Object
32 33 34 35 36 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 32 def set_dumb_response response_file @response.body = Parse.json_file_to_hash(response_file) @is_response_dumped = true self end |
#status(input) ⇒ Object
68 69 70 71 |
# File 'lib/poisol/stub/stub_builder_instance.rb', line 68 def status input @response.status = input self end |