Class: RequestToFixture

Inherits:
Service show all
Defined in:
app/service_adaptors/request_to_fixture.rb

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary collapse

Attributes inherited from Service

#group, #name, #priority, #request, #service_id, #status, #task, #url

Instance Method Summary collapse

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate

Constructor Details

#initialize(config) ⇒ RequestToFixture

Returns a new instance of RequestToFixture


15
16
17
# File 'app/service_adaptors/request_to_fixture.rb', line 15

def initialize(config)
  super(config)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file


10
11
12
# File 'app/service_adaptors/request_to_fixture.rb', line 10

def file
  @file
end

Instance Method Details

#cleanup(string) ⇒ Object

removes lines that only contain three dashes. These mess up our fixtures.


63
64
65
# File 'app/service_adaptors/request_to_fixture.rb', line 63

def cleanup(string)
  string.gsub!(/^--- $/, "")
end

#dump_proper(data, string, type) ⇒ Object


47
48
49
50
51
52
53
54
55
56
# File 'app/service_adaptors/request_to_fixture.rb', line 47

def dump_proper(data, string, type)
  values = {}
  data.attributes.each do |var, val|
    values[var] = val
  end
  fixture = {}
  fixture[type + '_' + data.id.to_s] = values
  string << YAML.dump(fixture)
  
end

#dump_referent_values(request, string) ⇒ Object


39
40
41
42
43
44
45
# File 'app/service_adaptors/request_to_fixture.rb', line 39

def dump_referent_values(request, string)
  referent_values = request.referent.referent_values.sort_by{|rv| rv.id}
    referent_values.each do |rv|
      dump_proper(rv, string, 'referent_value')
    end
    put_cutline(string)
end

#dump_request(request, string) ⇒ Object


31
32
33
34
35
36
37
# File 'app/service_adaptors/request_to_fixture.rb', line 31

def dump_request(request, string)
  #YAML.dump(request, fh)
  dump_proper(request, string, 'request')
  put_cutline(string)
  dump_proper(request.referent, string, 'referent')
  put_cutline(string)
end

#handle(request) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
# File 'app/service_adaptors/request_to_fixture.rb', line 19

def handle(request)
  final_string = ''
  fh = File.open(@file, 'a')
  dump_request(request, final_string)
  dump_referent_values(request, final_string)    
  
  cleanup(final_string)
  fh.puts final_string
  fh.close
  return request.dispatched(self, true)
end

#put_cutline(string) ⇒ Object


58
59
60
# File 'app/service_adaptors/request_to_fixture.rb', line 58

def put_cutline(string)
  string << "\n-------------CUT HERE----------------\n"
end

#service_types_generatedObject


12
13
# File 'app/service_adaptors/request_to_fixture.rb', line 12

def service_types_generated  
end