Class: XmlConv::Util::Transaction
- Inherits:
-
Object
- Object
- XmlConv::Util::Transaction
- Includes:
- ODBA::Persistable
- Defined in:
- lib/xmlconv/util/transaction.rb
Constant Summary collapse
- ODBA_SERIALIZABLE =
['@postprocs', '@responses', '@arguments']
- ODBA_PREFETCH =
true
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#commit_time ⇒ Object
readonly
Returns the value of attribute commit_time.
-
#debug_recipients ⇒ Object
Returns the value of attribute debug_recipients.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#error ⇒ Object
Returns the value of attribute error.
-
#error_recipients ⇒ Object
Returns the value of attribute error_recipients.
-
#input ⇒ Object
Returns the value of attribute input.
-
#input_model ⇒ Object
readonly
Returns the value of attribute input_model.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#output_model ⇒ Object
readonly
Returns the value of attribute output_model.
-
#partner ⇒ Object
Returns the value of attribute partner.
-
#postprocs ⇒ Object
Returns the value of attribute postprocs.
-
#reader ⇒ Object
Returns the value of attribute reader.
-
#response ⇒ Object
Returns the value of attribute response.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#writer ⇒ Object
Returns the value of attribute writer.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #invoice_ids ⇒ Object
- #notify ⇒ Object
- #odba_store ⇒ Object
- #postprocess ⇒ Object
- #respond(delivery, response) ⇒ Object
- #responses ⇒ Object
- #status ⇒ Object
- #status=(status) ⇒ Object
- #status_comparable ⇒ Object
- #update_status ⇒ Object
- #uri ⇒ Object
- #uri_comparable ⇒ Object
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
22 23 24 |
# File 'lib/xmlconv/util/transaction.rb', line 22 def initialize @postprocs = [] end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def arguments @arguments end |
#commit_time ⇒ Object (readonly)
Returns the value of attribute commit_time.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def commit_time @commit_time end |
#debug_recipients ⇒ Object
Returns the value of attribute debug_recipients.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def debug_recipients @debug_recipients end |
#destination ⇒ Object
Returns the value of attribute destination.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def destination @destination end |
#domain ⇒ Object
Returns the value of attribute domain.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def domain @domain end |
#error ⇒ Object
Returns the value of attribute error.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def error @error end |
#error_recipients ⇒ Object
Returns the value of attribute error_recipients.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def error_recipients @error_recipients end |
#input ⇒ Object
Returns the value of attribute input.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def input @input end |
#input_model ⇒ Object (readonly)
Returns the value of attribute input_model.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def input_model @input_model end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def model @model end |
#origin ⇒ Object
Returns the value of attribute origin.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def origin @origin end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def output @output end |
#output_model ⇒ Object (readonly)
Returns the value of attribute output_model.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def output_model @output_model end |
#partner ⇒ Object
Returns the value of attribute partner.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def partner @partner end |
#postprocs ⇒ Object
Returns the value of attribute postprocs.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def postprocs @postprocs end |
#reader ⇒ Object
Returns the value of attribute reader.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def reader @reader end |
#response ⇒ Object
Returns the value of attribute response.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def response @response end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
20 21 22 |
# File 'lib/xmlconv/util/transaction.rb', line 20 def start_time @start_time end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def transaction_id @transaction_id end |
#writer ⇒ Object
Returns the value of attribute writer.
16 17 18 |
# File 'lib/xmlconv/util/transaction.rb', line 16 def writer @writer end |
Instance Method Details
#execute ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xmlconv/util/transaction.rb', line 25 def execute reader_instance = Conversion.const_get(@reader) writer_instance = Conversion.const_get(@writer) @start_time = Time.now input_model = reader_instance.parse(@input) @arguments ||= [] @model = reader_instance.convert(input_model, *@arguments) output_model = writer_instance.convert(@model, *@arguments) @output = output_model.is_a?(Array) ? output_model.join("\n").to_s : output_model.to_s @destination.deliver(output_model) @commit_time = Time.now @output ensure @destination.forget_credentials! end |
#invoice_ids ⇒ Object
40 41 42 43 44 |
# File 'lib/xmlconv/util/transaction.rb', line 40 def invoice_ids @model.invoices.collect do |inv| inv.invoice_id.last.to_s.gsub /^0+/, '' end end |
#notify ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/xmlconv/util/transaction.rb', line 45 def notify recipients = [@debug_recipients] subject = 'XmlConv2 - Debug-Notification' if(@error) recipients.push(@error_recipients) subject = 'XmlConv2 - Error-Notification' end recipients.flatten! recipients.compact! recipients.uniq! return if(recipients.empty?) body = "Date: \#{@start_time.strftime(\"%d.%m.%Y\")}\nTime: \#{@start_time.strftime(\"%H:%M:%S\")}\nStatus: \#{status}\nError: \#{@error}\nLink: http://\#{@domain}/de/transaction/transaction_id/\#{@transaction_id}\n\nInput:\n# input start\n\#{@input}\n# input end\n\nOutput:\n# output start\n\#{@output}\n# output end\n EOS\n Util::Mail.notify recipients, subject, body\nend\n" |
#odba_store ⇒ Object
75 76 77 78 79 |
# File 'lib/xmlconv/util/transaction.rb', line 75 def odba_store @input.extend(ODBA::Persistable) if(@input) @output.extend(ODBA::Persistable) if(@output) super end |
#postprocess ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/xmlconv/util/transaction.rb', line 80 def postprocess if(@postprocs.respond_to?(:each)) @postprocs.each { |klass, *args| next if args.empty? args.push(self) PostProcess.const_get(klass).send(*args) } end end |
#respond(delivery, response) ⇒ Object
89 90 91 |
# File 'lib/xmlconv/util/transaction.rb', line 89 def respond delivery, response responses[delivery] = response end |
#responses ⇒ Object
98 99 100 |
# File 'lib/xmlconv/util/transaction.rb', line 98 def responses @responses ||= [] end |
#status ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/xmlconv/util/transaction.rb', line 101 def status if(@error) :error elsif(@model.nil? || @model.empty?) :empty elsif(@destination.respond_to?(:status)) @destination.status end end |
#status=(status) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/xmlconv/util/transaction.rb', line 110 def status=(status) if @destination.respond_to?(:status=) @destination.status = status @destination.odba_store @destination.status end end |
#status_comparable ⇒ Object
117 118 119 120 121 |
# File 'lib/xmlconv/util/transaction.rb', line 117 def status_comparable if(@destination.respond_to?(:status_comparable)) @destination.status_comparable end end |
#update_status ⇒ Object
122 123 124 125 126 |
# File 'lib/xmlconv/util/transaction.rb', line 122 def update_status if(@destination.respond_to?(:update_status)) @destination.update_status end end |
#uri ⇒ Object
127 128 129 |
# File 'lib/xmlconv/util/transaction.rb', line 127 def uri @destination.uri if(@destination.respond_to?(:uri)) end |
#uri_comparable ⇒ Object
130 131 132 |
# File 'lib/xmlconv/util/transaction.rb', line 130 def uri_comparable self.uri.to_s end |