ass_maintainer-info_base 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 662be0fd5b4c3cdcb6a262d14467d36a5edbd8f4
4
+ data.tar.gz: bcfed5068d14bab47917ebd22ca351d586de79b1
5
+ SHA512:
6
+ metadata.gz: b6527c21fd7322dd9613b65145f62304b7b6bfcad13d38a4bc5e0758fda6da0cc6e54bcd1c87595fb3a3b522449fff3e211602afc58d008386ca777dcf904e5b
7
+ data.tar.gz: 5e55ee0aa79f601fc393a9e9440645671af14f9fd1f1a7ac55661f9a003ae79b35a1d92c5ee3e548938ec4042420fcf29b1007afdd231d6e2c6c677fa961abeb
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.simplecov ADDED
@@ -0,0 +1 @@
1
+ SimpleCov.start if ENV['SIMPLECOV']
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ass_maintainer-info_base.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Leonid Vlasov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # AssMaintainer::InfoBase
2
+
3
+
4
+ Gem provides features for manipulate with 1C:Enterprise applications as easy
5
+ as possible.
6
+
7
+ Main thing of this gem `class AssMaintainer::InfoBase` provides
8
+ some methods for manipulate with information base;
9
+
10
+ ## Realase note
11
+
12
+ ### v.0.1.0
13
+
14
+ - Not support infobases deployed on 1C:Enterprise server
15
+ - Not support configuration extensions
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'ass_maintainer-info_base'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install ass_maintainer-info_base
32
+
33
+ ## Usage
34
+
35
+ Small example:
36
+
37
+ ```ruby
38
+ reqiure 'ass_maintainer/info_base'
39
+
40
+ # As infobase admin you should make backups of infobase
41
+
42
+ # Describe connection string
43
+ connection_string = 'File="infobase_path";'
44
+
45
+ # Get InfoBase instance
46
+ ib = AssMaintainer::InfoBase.new('infobase_name', connection_string, read_only)
47
+
48
+ # Dump data
49
+ ib.dump(dump_path)
50
+
51
+
52
+ # As 1C application developer you should make dump of infobase configuration
53
+
54
+ # Dump configuration
55
+ ib.cfg.dump(cf_dump_path)
56
+
57
+ # ... etc
58
+
59
+ ```
60
+
61
+ For more examples see [examples](./test/ass_maintainer/examples_test.rb)
62
+
63
+ ## Test
64
+
65
+ For running tests require installs 1C:Enterprise platform version defined in constant
66
+ `PLATFORM_REQUIRE` from
67
+ [test_helper.rb](./test/test_helper.rb)
68
+
69
+ $export SIMPLECOV=YES && rake test
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec ass_maintainer-info_base` to use the gem in this directory, ignoring other installed copies of this gem.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/leoniv/ass_maintainer-info_base.
80
+
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
85
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ass_maintainer/info_base/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ass_maintainer-info_base"
8
+ spec.version = AssMaintainer::InfoBase::VERSION
9
+ spec.authors = ["Leonid Vlasov"]
10
+ spec.email = ["leoniv.vlasov@gmail.com"]
11
+
12
+ spec.summary = %q{Manipulate with 1C:Enterprise application instances}
13
+ spec.description = %q{Classes and utils for manipulate with 1C:Enterprise application instances also known as "InfoBase" or "Information Base"}
14
+ spec.homepage = "https://github.com/leoniv/ass_maintainer-info_base"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "ass_launcher", "~> 0.2.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "mocha"
30
+
31
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ass_maintainer/info_base"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ # require "irb"
14
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,52 @@
1
+ require 'ass_tests/info_bases'
2
+
3
+ AssTests::InfoBases.describe do
4
+ file :empty_ib do
5
+ # DescribeOptions
6
+ template nil # Путь к шаблону ИБ
7
+ fixtures nil # Объект реализующий интрфейс AssTests::FixturesInterface для
8
+ # заполнения ИБ
9
+ maker nil # Объект реализующий интерфейс AssTests::IbMakerInterface создающий
10
+ # ИБ
11
+ destroyer nil # Объект реализующий интерфейс AssTests::IbDistroyerInterface
12
+ # уничтожающий ИБ
13
+ platform_require ENV['ASS_PLATFORM']
14
+ before_make ->(ib) { puts "Before make #{ib.name}"}
15
+ after_make ->(ib) { puts "After make #{ib.name}"}
16
+ before_rm ->(ib) { puts "Before rm #{ib.name}"}
17
+ after_rm ->(ib) { puts "After rm #{ib.name}"}
18
+ # CommonDescriber
19
+ locale nil
20
+ user 'name'
21
+ password 'password'
22
+ # FileIb
23
+ directory File.expand_path('../../tmp', __FILE__)
24
+ end
25
+
26
+ server :empty_server_ib do
27
+ # DescribeOptions
28
+ template nil
29
+ fixtures nil
30
+ maker nil
31
+ destroyer nil
32
+ platform_require '~> 8.3.8'
33
+ before_make nil
34
+ after_make nil
35
+ before_rm nil
36
+ after_rm nil
37
+ # CommonDescriber
38
+ locale nil
39
+ user 'name'
40
+ password 'password'
41
+ # ServerIb
42
+ agent ENV['ASS_SERVER_AGENT'] # --host 'host:port' --user 'admin' --password 'password'
43
+ claster ENV['ASS_CLASTER'] # --host 'host:port' --user 'admin' --password 'password'
44
+ # db ['EMPTY_DATA_BASE'] # --host 'host:port' --dbms 'MSSQLServer' --db-name 'db_name' --user 'admin' --password 'password' --create-db
45
+ db "--host 'host:port' --dbms 'MSSQLServer' --db-name 'db_name' --user 'admin' --password 'password' --create-db"
46
+ schjobdn # Запрет заданий см строка соединения
47
+ end
48
+
49
+ external :acc30, ENV['ACC30_IB_CONNECTION_STRING'] do
50
+ platform_require '>= 8.3'
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ass_maintainer/info_base"
@@ -0,0 +1,339 @@
1
+ require 'ass_maintainer/info_base/version'
2
+ require 'ass_launcher'
3
+
4
+ module AssMaintainer
5
+ # rubocop:disable Metrics/ClassLength
6
+
7
+ # Class for manipulate with 1C:Enterprise application instance aka
8
+ # +information base+ or +infobase+
9
+ #
10
+ # Instances of this class have dinamicly generated interfaece
11
+ #
12
+ # 1C:Enterprise application may be deployed as file (aka file infobase) or
13
+ # on a 1C:Enterprise server (aka server infobase). In the {#initialize}
14
+ # instance of this class will be extended suitable module:
15
+ # - server infobase instance will be extend module {ServerIb}
16
+ # - file infobase instance will be exten module {FileIb}
17
+ #
18
+ # Both instance type inherits methods from {Interfaces::InfoBaseWrapper}
19
+ #
20
+ # All instances get methods wrappers for access to {#options} see
21
+ # {.build_options_wrapper}
22
+ class InfoBase
23
+ extend AssLauncher::Api
24
+ require 'ass_maintainer/info_base/config'
25
+ require 'ass_maintainer/info_base/interfaces'
26
+ require 'ass_maintainer/info_base/file_ib'
27
+ require 'ass_maintainer/info_base/server_ib'
28
+ require 'ass_maintainer/info_base/cfg'
29
+ require 'ass_maintainer/info_base/default_maker'
30
+
31
+ # :nodoc:
32
+ class MethodDenied < StandardError
33
+ def initialize(m)
34
+ super "Infobase is read only. Method #{m} denied!"
35
+ end
36
+ end
37
+
38
+ # Deafult port for connect to 1C:Enterprise serever agent
39
+ DEFAULT_SAGENT_PORT = '1540'
40
+
41
+ # Hooks before and after make and remove infobase. Hooks may be passed as
42
+ # options or seted later see {#add_hook}
43
+ HOOKS = {
44
+ before_make: ->(ib) {},
45
+ after_make: ->(ib) {},
46
+ before_rm: ->(ib) {},
47
+ after_rm: ->(ib) {}
48
+ }
49
+
50
+ # On default for make and remove infobase uses {DefaultMaker} and
51
+ # {FileIb::FileBaseDestroyer} or {ServerIb::ServerBaseDestroyer}
52
+ # but we can pass custom maker and destroyer as {#options}.
53
+ # Maker and destroyer must implements {Interfaces::IbMaker} and
54
+ # {Interfaces::IbDestroyer}
55
+ WORKERS = {
56
+ maker: nil,
57
+ destroyer: nil
58
+ }
59
+
60
+ # - +:latform_require+ Required 1C:Enterprise version
61
+ # - +:agent_host+ Host name of 1C:Enterprise server agent
62
+ # - +:agent_port+ TCP port of 1C:Enterprise server agent on
63
+ # default {DEFAULT_SAGENT_PORT}
64
+ # - +:agent_usr+ Admin for 1C:Enterprise server agent
65
+ # - +:agent_pwd+ Admin password for 1C:Enterprise server agent
66
+ # - +:laster_usr+ Admin for 1C:Enterprise claster.
67
+ # See {ServerIb#claster_usr}
68
+ # - +:laster_pwd+ Pasword Admin for 1C:Enterprise claster.
69
+ # See {ServerIb#claster_pwd}
70
+ # - +:nlock_code+ Code for connect to locked infobase aka "/UC" parameter
71
+ ARGUMENTS = {
72
+ platform_require: nil,
73
+ sagent_host: nil,
74
+ sagent_port: nil,
75
+ sagent_usr: nil,
76
+ sagent_pwd: nil,
77
+ claster_usr: nil,
78
+ claster_pwd: nil,
79
+ unlock_code: nil
80
+ }
81
+
82
+ OPTIONS = (ARGUMENTS.merge HOOKS).merge WORKERS
83
+
84
+ # Dinamicaly builds of options wrappers
85
+ def self.build_options_wrapper
86
+ OPTIONS.each_key do |key|
87
+ next if WORKERS.keys.include? key
88
+ define_method key do
89
+ options[key]
90
+ end
91
+
92
+ next if HOOKS.keys.include? key
93
+ define_method "#{key}=".to_sym do |arg|
94
+ options[key] = arg
95
+ end
96
+ end
97
+ end
98
+
99
+ build_options_wrapper
100
+
101
+ # see {#initialize} +name+
102
+ attr_reader :name
103
+ # see {#initialize} +connection_string+
104
+ attr_reader :connection_string
105
+ # see {#initialize} +options+
106
+ attr_reader :options
107
+ # InfoBase is read only
108
+ # destructive methods will be fail with {MethodDenied} error
109
+ attr_reader :read_only
110
+ alias_method :read_only?, :read_only
111
+
112
+ # @param name [String] name of infobase
113
+ # @param connection_string [String AssLauncher::Support::ConnectionString]
114
+ # @param read_only [true false] infobse is read only or not
115
+ # @param options [Hash] see {OPTIONS}
116
+ def initialize(name, connection_string, read_only = true, **options)
117
+ @name = name
118
+ @connection_string = self.class.cs(connection_string.to_s)
119
+ @read_only = read_only
120
+ @options = OPTIONS.merge(options)
121
+ case self.connection_string.is
122
+ when :file then extend FileIb
123
+ when :server then extend ServerIb
124
+ else fail ArgumentError
125
+ end
126
+ yield self if block_given?
127
+ end
128
+
129
+ # Add hook. In all hook whill be passed +self+
130
+ # @raise [ArgumentError] if invalid hook name or not block given
131
+ # @param hook [Symbol] hook name
132
+ def add_hook(hook, &block)
133
+ fail ArgumentError, "Invalid hook `#{hook}'" unless\
134
+ HOOKS.keys.include? hook
135
+ fail ArgumentError, 'Block require' unless block_given?
136
+ options[hook] = block
137
+ end
138
+
139
+ # Requrement 1C version
140
+ # @return [String]
141
+ def platform_require
142
+ options[:platform_require] || self.class.config.platform_require
143
+ end
144
+
145
+ # Rebuild infobse first call {#rm!} second call {#make}
146
+ # @raise (see #rm!)
147
+ def rebuild!(sure = :no)
148
+ rm! sure
149
+ make
150
+ end
151
+
152
+ # (see #make_infobase!)
153
+ def make
154
+ make_infobase! unless exists?
155
+ self
156
+ end
157
+
158
+ # Make new empty infobase
159
+ # wrpped in +before_make+ and +after_make+ hooks
160
+ # @raise [MethodDenied] if infobase {#read_only?}
161
+ def make_infobase!
162
+ fail MethodDenied, :make_infobase! if read_only?
163
+ before_make.call(self)
164
+ maker.execute(self)
165
+ after_make.call(self)
166
+ self
167
+ end
168
+ private :make_infobase!
169
+
170
+ # (see #rm_infobase!)
171
+ def rm!(sure = :no)
172
+ fail 'If you are sure pass :yes value' unless sure == :yes
173
+ return unless exists?
174
+ rm_infobase!
175
+ nil
176
+ end
177
+
178
+ # Remove infobase
179
+ # wrpped in +before_rm+ and +after_rm+ hooks
180
+ # @raise [MethodDenied] if infobase {#read_only?}
181
+ def rm_infobase!
182
+ fail MethodDenied, :rm_infobase! if read_only?
183
+ before_rm.call(self)
184
+ destroyer.execute(self)
185
+ after_rm.call(self)
186
+ end
187
+ private :rm_infobase!
188
+
189
+ # Returns type of infobase
190
+ # @return [Symbol] +:file+ or +:server+
191
+ def is
192
+ connection_string.is
193
+ end
194
+
195
+ # Check type of infobase
196
+ # @param type [Symbol] +:file+ or +:server+
197
+ def is?(type)
198
+ connection_string.is?(type)
199
+ end
200
+
201
+ # Set user name
202
+ def usr=(user_name)
203
+ connection_string.usr = user_name
204
+ end
205
+
206
+ # User name
207
+ # @return [String]
208
+ def usr
209
+ connection_string.usr
210
+ end
211
+
212
+ # Set locale
213
+ # @param l [String] locale code +en+, +ru+ etc
214
+ def locale=(l)
215
+ connection_string.locale = l
216
+ end
217
+
218
+ # Get locale
219
+ # @return [String]
220
+ def locale
221
+ connection_string.locale
222
+ end
223
+
224
+ # Set user password
225
+ def pwd=(password)
226
+ connection_string.pwd = password
227
+ end
228
+
229
+ # User password
230
+ # @return [String]
231
+ def pwd
232
+ connection_string.pwd
233
+ end
234
+
235
+ # @return [AssLauncher::Enterprise::BinaryWrapper::ThickClient]
236
+ def thick
237
+ self.class.thicks(platform_require).last ||
238
+ fail("Platform 1C #{platform_require} not found")
239
+ end
240
+
241
+ # @return [AssLauncher::Enterprise::BinaryWrapper::ThinClient]
242
+ def thin
243
+ self.class.thins(platform_require).last ||
244
+ fail("Platform 1C #{platform_require} not found")
245
+ end
246
+
247
+ # Get ole connector specified in +type+ parameter
248
+ # @param type [Symbol] see +AssLauncher::Api#ole+
249
+ def ole(type)
250
+ self.class.ole(type, ole_requirement)
251
+ end
252
+
253
+ def ole_requirement
254
+ "= #{thick.version}"
255
+ end
256
+ private :ole_requirement
257
+
258
+ def fail_if_not_exists
259
+ fail 'Infobase not exists' unless exists?
260
+ end
261
+ private :fail_if_not_exists
262
+
263
+ # Build command for run designer
264
+ # block will be passed to arguments builder
265
+ # @return [AssLauncher::Support::Shell::Command]
266
+ def designer(&block)
267
+ command(:thick, :designer, &block)
268
+ end
269
+
270
+ # Build command for run enterprise
271
+ # block will be passed to arguments builder
272
+ # @param client [Symbol] +:thin+ or +thick+ client
273
+ # @return [AssLauncher::Support::Shell::Command]
274
+ def enterprise(client, &block)
275
+ command(client, :enterprise, &block)
276
+ end
277
+
278
+ def command(client, mode, &block)
279
+ fail_if_not_exists
280
+ case client
281
+ when :thin then
282
+ thin.command(connection_string.to_args + common_args, &block)
283
+ when :thick then
284
+ thick.command(mode, connection_string.to_args + common_args,
285
+ &block)
286
+ else
287
+ fail ArgumentError, "Invalid client #{client}"
288
+ end
289
+ end
290
+ private :command
291
+
292
+ # Common arguments for all commands
293
+ def common_args
294
+ r = []
295
+ r += ['/L', locale] if locale
296
+ r += ['/UC', unlock_code] if unlock_code
297
+ r
298
+ end
299
+
300
+ # Dump infobase to +.dt+ file
301
+ def dump(path)
302
+ designer do
303
+ dumpIB path
304
+ end.run.wait.result.verify!
305
+ path
306
+ end
307
+
308
+ # Restore infobase from +.dt+ file
309
+ # @raise [MethodDenied] if {#read_only?}
310
+ def restore!(path)
311
+ fail MethodDenied, :restore! if read_only?
312
+ designer do
313
+ restoreIB path
314
+ end.run.wait.result.verify!
315
+ path
316
+ end
317
+
318
+ # Returns instance for manipuate with
319
+ # InfoBase database. If infobase not
320
+ # exists returns nil
321
+ # @return [Dbase nil]
322
+ def db_cfg
323
+ @db_cfg ||= DbCfg.new(self) if exists?
324
+ end
325
+
326
+ # Returns instance for manipuate with
327
+ # databse configuration. If infobase not
328
+ # exists returns nil
329
+ # @return [Cfg nil]
330
+ def cfg
331
+ @cfg ||= Cfg.new(self) if exists?
332
+ end
333
+
334
+ extend Forwardable
335
+ def_delegators :infobase_wrapper,
336
+ *Interfaces::InfoBaseWrapper.instance_methods
337
+ end
338
+ # rubocop:enable Metrics/ClassLength
339
+ end
@@ -0,0 +1,81 @@
1
+ module AssMaintainer
2
+ class InfoBase
3
+ # @abstract
4
+ class AbstractCfg
5
+ attr_reader :infobase
6
+ # @param infobase [InfoBase]
7
+ def initialize(infobase)
8
+ @infobase = infobase
9
+ end
10
+ end
11
+
12
+ # Object for manipuate whith infobase configuration
13
+ class Cfg < AbstractCfg
14
+ # Dump configuration to +XML+ files
15
+ # @param path [String]
16
+ # @return [String] path
17
+ def dump_xml(path)
18
+ infobase.designer do
19
+ dumpConfigToFiles path
20
+ end.run.wait.result.verify!
21
+ path
22
+ end
23
+
24
+ # Dump configuration to +.cf+ file
25
+ # @param path [String]
26
+ # @return [String] path
27
+ def dump(path)
28
+ infobase.designer do
29
+ dumpCfg path
30
+ end.run.wait.result.verify!
31
+ path
32
+ end
33
+
34
+ # Load configuration from +XML+ files
35
+ # @param path [String]
36
+ # @return [String] path
37
+ def load_xml(path)
38
+ fail MethodDenied, :load_xml if infobase.read_only?
39
+ infobase.designer do
40
+ loadConfigFromFiles path
41
+ end.run.wait.result.verify!
42
+ path
43
+ end
44
+
45
+ # Load configuration from +.cf+ file
46
+ # @param path [String]
47
+ # @return [String] path
48
+ def load(path)
49
+ fail MethodDenied, :load_cf if infobase.read_only?
50
+ infobase.designer do
51
+ loadCfg path
52
+ end.run.wait.result.verify!
53
+ path
54
+ end
55
+ end
56
+
57
+ # Object for manipuate whith database configuration
58
+ class DbCfg < AbstractCfg
59
+ # Update database configuration from infobase
60
+ # configuration
61
+ def update
62
+ fail MethodDenied, :update if infobase.read_only?
63
+ infobase.designer do
64
+ updateDBCfg do
65
+ warningsAsErrors
66
+ end
67
+ end.run.wait.result.verify!
68
+ end
69
+
70
+ # Dump configuration to +.cf+ file
71
+ # @param path [String]
72
+ # @return [String] path
73
+ def dump(path)
74
+ infobase.designer do
75
+ dumpDBCfg path
76
+ end.run.wait.result.verify!
77
+ path
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,28 @@
1
+ module AssMaintainer
2
+ #
3
+ class InfoBase
4
+ ASS_PLATFORM_REQUIRE = ENV['ASS_PLATFORM_REQUIRE'] || '> 0'
5
+
6
+ # Settings for {InfoBase}
7
+ class Config
8
+ # Set reqirement for version of 1C:Enterprise
9
+ attr_writer :platform_require
10
+ # Reqirement for version of 1C:Enterprise
11
+ # @return [String]
12
+ def platform_require
13
+ @platform_require ||= ASS_PLATFORM_REQUIRE
14
+ end
15
+ end
16
+
17
+ # Make settings
18
+ def self.configure
19
+ yield config
20
+ end
21
+
22
+ # Get settings
23
+ # @return [Config]
24
+ def self.config
25
+ @config ||= Config.new
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module AssMaintainer
2
+ class InfoBase
3
+ # Default infobase maker
4
+ class DefaultMaker
5
+ include Interfaces::IbMaker
6
+ # :hodoc:
7
+ def entry_point
8
+ infobase.thick
9
+ .command(:createinfobase,
10
+ infobase.connection_string.createinfobase_args +
11
+ infobase.common_args)
12
+ .run.wait.result.verify!
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,76 @@
1
+ module AssMaintainer
2
+ class InfoBase
3
+ # Mixins for file deployed infobase
4
+ module FileIb
5
+ # Default destroyer for file infobase
6
+ class FileBaseDestroyer
7
+ include Interfaces::IbDestroyer
8
+ def entry_point
9
+ FileUtils.rm_r infobase.connection_string.path.to_s
10
+ end
11
+ end
12
+
13
+ # True if infobase exists
14
+ def exists?
15
+ File.file?("#{connection_string.path}/1Cv8.1CD")
16
+ end
17
+
18
+ def maker
19
+ options[:maker] || InfoBase::DefaultMaker.new
20
+ end
21
+ private :maker
22
+
23
+ def destroyer
24
+ options[:destroyer] || FileBaseDestroyer.new
25
+ end
26
+ private :destroyer
27
+
28
+ # Connection string fore createinfobase
29
+ def make_connection_string
30
+ connection_string
31
+ end
32
+
33
+ # Dummy infobase wrupper
34
+ # @return [InfoBaseWrapper]
35
+ def infobase_wrapper
36
+ @infobase_wrapper = InfoBaseWrapper.new(self)
37
+ end
38
+
39
+ # (see Interfaces::InfoBaseWrapper)
40
+ class InfoBaseWrapper
41
+ include Interfaces::InfoBaseWrapper
42
+ attr_accessor :infobase
43
+ def initialize(infobase)
44
+ self.infobase = infobase
45
+ end
46
+
47
+ # (see Interfaces::InfoBaseWrapper#sessions)
48
+ def sessions
49
+ []
50
+ end
51
+
52
+ # (see Interfaces::InfoBaseWrapper#lock)
53
+ def lock
54
+ end
55
+
56
+ # (see Interfaces::InfoBaseWrapper#unlock)
57
+ def unlock
58
+ end
59
+
60
+ # (see Interfaces::InfoBaseWrapper#unlock!)
61
+ def unlock!
62
+ end
63
+
64
+ # (see Interfaces::InfoBaseWrapper#locked?)
65
+ def locked?
66
+ false
67
+ end
68
+
69
+ # (see Interfaces::InfoBaseWrapper#locked_we?)
70
+ def locked_we?
71
+ false
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,78 @@
1
+ module AssMaintainer
2
+ class InfoBase
3
+ # Define absract Interfaces
4
+ # for worker classes
5
+ module Interfaces
6
+ # Interface for class which make new InfoBase
7
+ # Class must implement +#entry_point+ methodmodule Fixtures
8
+ module IbMaker
9
+ attr_reader :infobase
10
+ def execute(infobase)
11
+ @infobase = infobase
12
+ entry_point
13
+ end
14
+
15
+ def entry_point
16
+ fail NotImplementedError
17
+ end
18
+ end
19
+
20
+ # Interface for class which destroy InfoBase
21
+ # Class must implement +#entry_point+ methodmodule Fixtures
22
+ module IbDestroyer
23
+ attr_reader :infobase
24
+ def execute(infobase)
25
+ @infobase = infobase
26
+ entry_point
27
+ end
28
+
29
+ def entry_point
30
+ fail NotImplementedError
31
+ end
32
+ end
33
+
34
+ # Interface for {FileIb::InfoBaseWrapper} and
35
+ # {ServerIb::InfoBaseWrapper} classes
36
+ module InfoBaseWrapper
37
+ # Returns array of infobase sessions
38
+ # For file infobase returns empty array
39
+ # @return [Array <Session>]
40
+ def sessions
41
+ fail NotImplementedError
42
+ end
43
+
44
+ # Lock infobase. It work for server infobase only.
45
+ # For file infobase it do nothing
46
+ def lock
47
+ fail NotImplementedError
48
+ end
49
+
50
+ # Unlock infobase which {#locked_we?}.
51
+ # It work for server infobase only.
52
+ # For file infobase it do nothing
53
+ def unlock
54
+ fail NotImplementedError
55
+ end
56
+
57
+ # Unlock infobase.
58
+ # It work for server infobase only.
59
+ # For file infobase it do nothing
60
+ def unlock!
61
+ fail NotImplementedError
62
+ end
63
+
64
+ # Lock infobase. It work for server infobase only.
65
+ # For file infobase it return +false+
66
+ def locked?
67
+ fail NotImplementedError
68
+ end
69
+
70
+ # True if infobase locked this
71
+ # For file infobase it return +false+
72
+ def locked_we?
73
+ fail NotImplementedError
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,98 @@
1
+ module AssMaintainer
2
+ class InfoBase
3
+ # Mixins for infobase deployed on 1C:Eneterprise server
4
+ module ServerIb
5
+ require 'ass_maintainer/info_base/server_ib/helpers'
6
+ # Defauld destroyer for serever infobase
7
+ class ServerBaseDestroyer
8
+ include Interfaces::IbDestroyer
9
+ def entry_point
10
+ fail NotImplementedError
11
+ end
12
+ end
13
+
14
+ def maker
15
+ options[:maker] || InfoBase::DefaultMaker.new
16
+ end
17
+ private :maker
18
+
19
+ # True if infobase exists
20
+ def exists?
21
+ infobase_wrapper.exists?
22
+ end
23
+
24
+ def destroyer
25
+ options[:destroyer] || ServerBaseDestroyer.new
26
+ end
27
+ private :destroyer
28
+
29
+ # @return (see #def_server_agent)
30
+ def server_agent
31
+ @server_agent ||= def_server_agent
32
+ end
33
+
34
+ # @return [EnterpriseServers::ServerAgent]
35
+ def def_server_agent
36
+ host = sagent_host || connection_string.servers[0].host
37
+ port = sagent_port || InfoBase::DEFAULT_SAGENT_PORT
38
+ EnterpriseServers::ServerAgent.new("#{host}:#{port}",
39
+ sagent_usr,
40
+ sagent_pwd)
41
+ end
42
+ private :def_server_agent
43
+
44
+ # @param a [EnterpriseServers::ServerAgent]
45
+ def server_agent=(a)
46
+ fail ArgumentError unless a.instance_of? ServerAgent
47
+ @server_agent = a
48
+ end
49
+
50
+ # Set claster user name
51
+ # @param user_name [String]
52
+ def cluster_usr=(user_name)
53
+ connection_string.susr = user_name
54
+ end
55
+
56
+ # Claster user name
57
+ def claster_usr
58
+ connection_string.susr || (self.claster_usr = options[:claster_usr])
59
+ end
60
+
61
+ # Set claster user password
62
+ # @param password [String]
63
+ def cluster_pwd=(password)
64
+ connection_string.spwd = password
65
+ end
66
+
67
+ # Claster user password
68
+ def claster_pwd
69
+ connection_string.spwd || (self.claster_pwd = options[:claster_pwd])
70
+ end
71
+
72
+ # @return [EnrepriseServers::Claster]
73
+ def claster
74
+ EnterpriseServers::Claster.from_cs(connection_string)
75
+ end
76
+
77
+ def filled?(fields)
78
+ fields.each do |f|
79
+ return false if connection_string[f].nil?
80
+ end
81
+ true
82
+ end
83
+ private :filled?
84
+
85
+ # Connection string fore createinfobase
86
+ def make_connection_string
87
+ fields = [:dbsrvr, :db, :dbms]
88
+ fail "Required fields #{fields} must be filled" unless filled?(fields)
89
+ AssLauncher::Support::ConnectionString.new(connection_string.to_s)
90
+ end
91
+
92
+ # @return {InfoBaseWrapper}
93
+ def infobase_wrapper
94
+ @infobase_wrapper = InfoBaseWrapper.new(self, server_agent, claster)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,50 @@
1
+ module AssMaintainer
2
+ class InfoBase
3
+ module ServerIb
4
+ module EnterpriseServers
5
+ # Mixins for serever connection describers {Claster} {ServerAgent}
6
+ module ServerConnection
7
+ attr_reader :host_port, :user, :password
8
+ def initialize(host_port, user, password)
9
+ fail ArgumentError, 'Host name require' if host_port.to_s.empty?
10
+ @host_port = host_port.to_s
11
+ @user = user
12
+ @password = password
13
+ end
14
+ end
15
+
16
+ # Object descrbed 1C server agent connection
17
+ class ServerAgent
18
+ include ServerConnection
19
+ end
20
+
21
+ # Object descrbed 1C claster connection
22
+ class Claster
23
+ include ServerConnection
24
+ def self.from_cs(cs)
25
+ new cs.srvr, cs.susr, cs.spwd
26
+ end
27
+ end
28
+ end
29
+
30
+ # Wrapper for manipulate
31
+ # with real information base deployed in 1C:Enterprise server
32
+ # ower the 1C Ole classes
33
+ class InfoBaseWrapper
34
+ include Interfaces::InfoBaseWrapper
35
+ attr_accessor :infobase, :server_agent, :claster
36
+ # @api private
37
+ def initialize(infobase, server_agent, claster)
38
+ self.infobase = infobase
39
+ self.server_agent = server_agent
40
+ self.claster = claster
41
+ end
42
+
43
+ # True if infobase exists
44
+ def exists?
45
+ fail NotImplementedError
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,6 @@
1
+ module AssMaintainer
2
+ #
3
+ class InfoBase
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ass_maintainer-info_base
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Leonid Vlasov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ass_launcher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Classes and utils for manipulate with 1C:Enterprise application instances
112
+ also known as "InfoBase" or "Information Base"
113
+ email:
114
+ - leoniv.vlasov@gmail.com
115
+ executables:
116
+ - ass_maintainer-info_base
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - .simplecov
122
+ - .travis.yml
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - ass_maintainer-info_base.gemspec
128
+ - bin/console
129
+ - bin/setup
130
+ - examples/describe_infobase.rb
131
+ - exe/ass_maintainer-info_base
132
+ - lib/ass_maintainer/info_base.rb
133
+ - lib/ass_maintainer/info_base/cfg.rb
134
+ - lib/ass_maintainer/info_base/config.rb
135
+ - lib/ass_maintainer/info_base/default_maker.rb
136
+ - lib/ass_maintainer/info_base/file_ib.rb
137
+ - lib/ass_maintainer/info_base/interfaces.rb
138
+ - lib/ass_maintainer/info_base/server_ib.rb
139
+ - lib/ass_maintainer/info_base/server_ib/helpers.rb
140
+ - lib/ass_maintainer/info_base/version.rb
141
+ homepage: https://github.com/leoniv/ass_maintainer-info_base
142
+ licenses:
143
+ - MIT
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.0.14
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Manipulate with 1C:Enterprise application instances
165
+ test_files: []
166
+ has_rdoc: