ass_ole-snippets-shared 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 695fcd6c1d95365a3592620312f61342185c0a28
|
4
|
+
data.tar.gz: 3dccb72013e0b28d8f3ea34bf3245ac279930f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59787df2957c0ffac5666a812c72d850ca8f1b7b77045bd5eba5acdbcac825060171f45f4449a65087fa1d425950ebb8726914e6505d767f8b0c3c350afca49c
|
7
|
+
data.tar.gz: 82558bf3c383d166f8aba8d1773f0d86835c0c64671f14ce44952c1cd0e97da6fe9341243ab21786a35a4fec027b0e31e548ed1c11cb1f6253924061898a866b
|
data/README.md
CHANGED
@@ -3,7 +3,35 @@ require 'ass_ole'
|
|
3
3
|
|
4
4
|
module AssOle
|
5
5
|
module Snippets
|
6
|
-
# Shared Ole snippets
|
6
|
+
# Shared Ole snippets.
|
7
|
+
#
|
8
|
+
# Object included snippets must +respond_to? ole_connector+ and returns
|
9
|
+
# 1C OLE connector or includes +AssOle+ runtime using: +like_ole_runtime+
|
10
|
+
# method defined in +ass_ole+ gem.
|
11
|
+
# @example
|
12
|
+
# require 'ass_ole'
|
13
|
+
# require 'ass_ole/snippets/shared'
|
14
|
+
# require 'ass_maintainer/info_base'
|
15
|
+
#
|
16
|
+
# # External connection runtime
|
17
|
+
# module ExternalRuntime
|
18
|
+
# is_ole_runtime :external
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# class Worker
|
22
|
+
# like_ole_runtime ExternalRuntime
|
23
|
+
# include AssOle::Snippets::Shared::Query
|
24
|
+
#
|
25
|
+
# def initialize(connection_string)
|
26
|
+
# ole_runtime_get.run AssMaintainer::InfoBase.new('ib_name', connection_string)
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def select(value)
|
30
|
+
# query('select &arg as arg', arg: value).Execute.Unload.Get(0).arg
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Worker.new('File="path"').select('Hello') #=> "Hello"
|
7
35
|
module Shared
|
8
36
|
# Snippet for serialize and deserilize 1C objects to xml
|
9
37
|
# @note In external runtime it will be cause of a fail in +InfoBase#rm!+
|
@@ -81,14 +109,37 @@ module AssOle
|
|
81
109
|
end
|
82
110
|
end
|
83
111
|
|
112
|
+
# @deprecated Use {InTransactionDo} instead
|
113
|
+
# @todo remove module in v1.0.0
|
84
114
|
# Do in transaction wrapper
|
85
115
|
module Transaction
|
86
116
|
is_ole_snippet
|
87
117
|
|
118
|
+
def self.depricate
|
119
|
+
Kernel.warn '[DEPRICATION]'\
|
120
|
+
" '#{self.name}` is deprecated and will be"\
|
121
|
+
" removed soon. Please use "\
|
122
|
+
'\'AssOle::Snipptes::Shared::InTransactionDo` instead.'\
|
123
|
+
end
|
124
|
+
|
125
|
+
[method(:included), method(:extended)].each do |old_method|
|
126
|
+
name = old_method.name
|
127
|
+
old = "_depricate_#{name}"
|
128
|
+
singleton_class.class_eval {
|
129
|
+
alias_method old, name
|
130
|
+
define_method name do |*args, &block|
|
131
|
+
AssOle::Snippets::Shared::Transaction.depricate
|
132
|
+
send old, *args, &block
|
133
|
+
end
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
88
137
|
# rubocop:disable Metrics/MethodLength
|
89
138
|
|
139
|
+
# @deprecated Use {InTransactionDo#in_transaction} instead
|
90
140
|
# @raise [RuntimeError] if nested transaction
|
91
141
|
def do_in_transaction(&block)
|
142
|
+
AssOle::Snippets::Shared::Transaction.depricate
|
92
143
|
fail ArgumentError, 'Block require' unless block_given?
|
93
144
|
fail 'Nested transaction is mindless in 1C runtime' if\
|
94
145
|
transactionActive
|
@@ -110,6 +161,7 @@ module AssOle
|
|
110
161
|
require 'ass_ole/snippets/shared/array'
|
111
162
|
require 'ass_ole/snippets/shared/binary_data'
|
112
163
|
require 'ass_ole/snippets/shared/value_table'
|
164
|
+
require 'ass_ole/snippets/shared/in_transaction_do'
|
113
165
|
end
|
114
166
|
end
|
115
167
|
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module AssOle
|
2
|
+
module Snippets
|
3
|
+
module Shared
|
4
|
+
# Mixin for wrapping execution into 1C transaction.
|
5
|
+
# @example
|
6
|
+
# #!/sbin/env ruby
|
7
|
+
#
|
8
|
+
# require 'ass_ole'
|
9
|
+
# require 'ass_ole/snippets/shred/in_transaction_do'
|
10
|
+
#
|
11
|
+
# PLATFORM_REQUIRE = '~> 8.3.10.0'
|
12
|
+
#
|
13
|
+
# # External connection runtime for accounting infobase
|
14
|
+
# module AccountingRuntime
|
15
|
+
# is_ole_runtime :external
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# # External connection runtime for HRM infobase
|
19
|
+
# module HrmRuntime
|
20
|
+
# is_ole_runtime :external
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# # Worker do anything in accounting infobase
|
24
|
+
# class AcctWorker
|
25
|
+
# like_ole_runtime AccountingRuntime
|
26
|
+
# include AssOle::Snipptes::Shared::InTransactionDo
|
27
|
+
#
|
28
|
+
# attr_reader :ib
|
29
|
+
# def initialize(connection_string)
|
30
|
+
# @ib = AssMaintainer::InfoBase
|
31
|
+
# .new('accounting', connection_string, PLATFORM_REQUIRE)
|
32
|
+
# ole_runtime_get.run ib #connect to infobase
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# def action_one
|
36
|
+
# #NOP
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# def action_two(action_one_result)
|
40
|
+
# #NOP
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# def make_job_in_transaction
|
44
|
+
# in_transaction do
|
45
|
+
# make_job
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# def make_job
|
50
|
+
# action_two(action_one)
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# # Worker do anything in HRM infobase
|
55
|
+
# class HrmWorker
|
56
|
+
# like_ole_runtime HrmRuntime
|
57
|
+
# include AssOle::Snipptes::Shared::InTransactionDo
|
58
|
+
#
|
59
|
+
# attr_reader :ib
|
60
|
+
# def initialize(connection_string)
|
61
|
+
# @ib = AssMaintainer::InfoBase
|
62
|
+
# .new('accounting', connection_string, PLATFORM_REQUIRE)
|
63
|
+
# ole_runtime_get.run ib #connect to infobase
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# def action_one(acct_result)
|
67
|
+
# #NOP
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# def action_two(acct_result)
|
71
|
+
# #NOP
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# def make_job(acct_result)
|
75
|
+
# action_one(acct_result)
|
76
|
+
# action_two(acct_reult)
|
77
|
+
# true
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# module Programm
|
82
|
+
# # It working like distributed transaction
|
83
|
+
# def self.execute_in_nested_transaction(acct_cs, hrm_cs)
|
84
|
+
# # Trasaction in HrmWorker committed automatically
|
85
|
+
# HrmWorker.new(hrm_cs).in_transaction do |hrm_worker|
|
86
|
+
# # Trasaction in AcctWorker keep alive
|
87
|
+
# acct_result = AcctWorker.new(acct_cs).in_transaction(false) do |acct_worker|
|
88
|
+
# acct_worker.make_job
|
89
|
+
# end
|
90
|
+
# result = hrm_worker.make_job(acct_result)
|
91
|
+
# #Commit AcctWorker transaction
|
92
|
+
# acct_worker._commit_transaction_
|
93
|
+
# result
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# #Do in accounting infobase only
|
99
|
+
# puts AcctWorker.new(ARGV[0]).make_job_in_transaction
|
100
|
+
#
|
101
|
+
# #Do in accounting and hrm infobases
|
102
|
+
# puts Programm.execute_in_nested_transaction(ARGV[0], ARGV[1])
|
103
|
+
module InTransactionDo
|
104
|
+
is_ole_snippet
|
105
|
+
|
106
|
+
# Wrap execution in 1C transaction. If execution failure
|
107
|
+
# transaction always rolledback!
|
108
|
+
# @param auto_commit [true false] if +true+ transaction will be committed
|
109
|
+
# automatically
|
110
|
+
# @param managed_lock (see #_begin_transaction_)
|
111
|
+
# @yield self
|
112
|
+
# @return execution result
|
113
|
+
def in_transaction(auto_commit = true, managed_lock = false, &block)
|
114
|
+
fail 'Block require' unless block_given?
|
115
|
+
_begin_transaction_ managed_lock
|
116
|
+
begin
|
117
|
+
result = yield self
|
118
|
+
_commit_transaction_ if auto_commit
|
119
|
+
rescue Exception => e
|
120
|
+
_rollback_transaction_
|
121
|
+
fail e
|
122
|
+
end
|
123
|
+
result
|
124
|
+
end
|
125
|
+
|
126
|
+
# @param managed_lock [false true] if true 1C +BeginTransaction+ call with
|
127
|
+
# +DataLockControlMode.Managed+
|
128
|
+
def _begin_transaction_(managed_lock = false)
|
129
|
+
ole_connector.beginTransaction unless managed_lock
|
130
|
+
ole_connector.beginTransaction ole_connector
|
131
|
+
.dataLockControlMode.Managed if managed_lock
|
132
|
+
end
|
133
|
+
|
134
|
+
def _rollback_transaction_
|
135
|
+
ole_connector.rollBackTransaction
|
136
|
+
end
|
137
|
+
|
138
|
+
def _commit_transaction_
|
139
|
+
ole_connector.commitTransaction
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -95,8 +95,8 @@ module AssOle
|
|
95
95
|
|
96
96
|
# @param columns [Array] +ValueTable+ columns
|
97
97
|
# @param columns_with_types [Hash] +ValueTable+ columns with column
|
98
|
-
# type names
|
99
|
-
# or
|
98
|
+
# type names +Array+ like +%w{TypeName OtheTypeName}+
|
99
|
+
# or +String+ like +'TypeName, OtheTypeName'+
|
100
100
|
# @yield [Wrapper]
|
101
101
|
# @return [WIN32OLE] 1C +ValueTable+ object
|
102
102
|
def value_table(*columns, **columns_with_types, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ass_ole-snippets-shared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonid Vlasov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ass_ole
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/ass_ole/snippets/shared.rb
|
142
142
|
- lib/ass_ole/snippets/shared/array.rb
|
143
143
|
- lib/ass_ole/snippets/shared/binary_data.rb
|
144
|
+
- lib/ass_ole/snippets/shared/in_transaction_do.rb
|
144
145
|
- lib/ass_ole/snippets/shared/mapped.rb
|
145
146
|
- lib/ass_ole/snippets/shared/value_table.rb
|
146
147
|
- lib/ass_ole/snippets/shared/version.rb
|
@@ -163,9 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.6.13
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: Shared snippets for ass_ole gem
|
170
171
|
test_files: []
|
171
|
-
has_rdoc:
|