ass_ole 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c521cf1ed642c0bfee22b61d8185f8910c48685
4
+ data.tar.gz: a261e51a1e48eb2cd35a0d3f0f9dc232ec04a75c
5
+ SHA512:
6
+ metadata.gz: 04bd263480e52c373c6c45360bd88313376127a5c0a0e976ef25f6c072af80c664b252b766450c787c3d7378350e04fe081c19a71d14b527db298e8e7df0e615
7
+ data.tar.gz: c9b0cb80d1b55d69aa4f54805a7e85797931e50b5c7a98d40c2791981db19d665cf4bea3025d09fcb6578d6a59a272f0bbc9d8990506d18cc4005211ba0be6a5
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_ole.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # AssOle
2
+
3
+ Provides features for easy access to 1C:Enterprise Ole from Ruby code.
4
+ Main things of this gem is `AssOle::Runtimes` and `AssOle::Snippets`
5
+
6
+ `AssOle::Runtimes` provides features for control, despatch and easy access to
7
+ the 1C:Enterprise Ole connectors. `AssOle::Runtimes` inclides mixins which
8
+ provides `ole_connector` method returned specified Ole connector.
9
+
10
+ `AssOle::Snippets` provides features for transparent access to 1C:Enterprise Ole
11
+ methods and properties from Ruby objects like as they are was own Ruby object
12
+ methods. In other words `AssOle::Snippetes` forvarding call unknown methods
13
+ to the `ole_connector` in the `method_missing` handler.
14
+
15
+ Both this things makes Ruby code shorter and tidier
16
+
17
+ ## Attention
18
+
19
+ `AssOle::Runtimes` closes all ole connections in `at_exit` hook. You should
20
+ checks order of modules loading.
21
+ For example if `ass_ole` uses with `minitest` first load
22
+ `ass_ole` secont load `minitest` otherwise all ole connections will be closed
23
+ before start tests executing:
24
+
25
+ ```ruby
26
+ requre 'ass_ole'
27
+ requre 'minitest/autorun'
28
+ ```
29
+
30
+ ## Examples
31
+
32
+ More about it and how to use see [test/examples_test.rb](test/examples_test.rb)
33
+
34
+ ## Installation
35
+
36
+ Add this line to your application's Gemfile:
37
+
38
+ ```ruby
39
+ gem 'ass_ole'
40
+ ```
41
+
42
+ And then execute:
43
+
44
+ $ bundle
45
+
46
+ Or install it yourself as:
47
+
48
+ $ gem install ass_ole
49
+
50
+ ## Development
51
+
52
+ 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.
53
+
54
+ ## Testing
55
+
56
+ $ export SIMPLECOV=YES && rake test
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at
61
+ https://github.com/leoniv/ass_ole.
62
+
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
data/ass_ole.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ass_ole/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ass_ole"
8
+ spec.version = AssOle::VERSION
9
+ spec.authors = ["Leonid Vlasov"]
10
+ spec.email = ["leoniv.vlasov@gmail.com"]
11
+
12
+ spec.summary = %q{Easy access to 1C:Enterprise apps and servers via Ole}
13
+ spec.description = %q{Provides features for easy access to 1C:Enterprise applications and 1C:Enterprise servers from Ruby code}
14
+ spec.homepage = "https://github.com/leoniv/ass_ole"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ass_launcher", "~> 0.2.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "ass_maintainer-info_base"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ass_ole"
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
data/lib/ass_ole.rb ADDED
@@ -0,0 +1,169 @@
1
+ # encoding: utf-8
2
+
3
+ # AssOle provides helpers for manipulate with
4
+ # 1C:Enterprise Ole serevers and some more
5
+ module AssOle
6
+ require 'ass_launcher'
7
+ require 'ass_ole/version'
8
+ require 'ass_ole/snippets'
9
+ require 'ass_ole/dsl'
10
+
11
+ # @api private
12
+ # Runtimes hold all created Ole runtimes and stopped they in +at_axit+ see
13
+ # {.do_at_exit}
14
+ module Runtimes
15
+ def self.runtimes
16
+ @runtimes ||= []
17
+ end
18
+
19
+ # @api private
20
+ # `at_exit` handler closed all opened connections
21
+ def self.do_at_exit
22
+ runtimes.each(&:stop)
23
+ end
24
+
25
+ at_exit do
26
+ do_at_exit
27
+ end
28
+
29
+ # @api private
30
+ module RuntimeDispatcher
31
+ def ole_connector
32
+ ole_runtime_get.ole_connector
33
+ end
34
+
35
+ def ole_runtime_get
36
+ if self.class == Module
37
+ instance_variable_get(:@ole_runtime)
38
+ elsif self.class == Class
39
+ class_variable_get(:@@ole_runtime)
40
+ else
41
+ self.class
42
+ end
43
+ end
44
+ private :ole_runtime_get
45
+ end
46
+
47
+ # @api private
48
+ module ModuleMethods
49
+ attr_reader :ole_connector
50
+
51
+ def run_(connection_string_or_uri)
52
+ ole_connector.__open__ connection_string_or_uri unless runned?
53
+ end
54
+ private :run_
55
+
56
+ def stop
57
+ ole_connector.__close__ if runned?
58
+ end
59
+
60
+ def runned?
61
+ initialized? && ole_connector.__opened__?
62
+ end
63
+
64
+ def initialized?
65
+ !ole_connector.nil?
66
+ end
67
+
68
+ def included(obj)
69
+ ole_runtime_set obj
70
+ obj.send(:extend, RuntimeDispatcher)
71
+ end
72
+
73
+ def extended(obj)
74
+ ole_runtime_set obj
75
+ end
76
+
77
+ def ole_runtime_set(obj)
78
+ if obj.class == Class
79
+ obj.class_variable_set(:@@ole_runtime, self)
80
+ else
81
+ obj.instance_variable_set(:@ole_runtime, self)
82
+ end
83
+ end
84
+ private :ole_runtime_set
85
+ end
86
+
87
+ # @api private
88
+ module AbstractRuntime
89
+ def extended(obj)
90
+ obj.send(:extend, AssOle::Runtimes::ModuleMethods)
91
+ obj.send(:include, AssOle::Runtimes::RuntimeDispatcher)
92
+ Runtimes.runtimes << obj
93
+ end
94
+ end
95
+
96
+ # 1C:Enterprise application runtime helpers
97
+ # @api private
98
+ module App
99
+ # @api private
100
+ # @abstract
101
+ module Abstract
102
+ def run(info_base)
103
+ return ole_connector if runned?
104
+ instance_variable_set(:@ole_connector, info_base.ole(ole_type))
105
+ run_ info_base.connection_string
106
+ end
107
+ end
108
+ # 1C:Enterprise application external connection runtime helper
109
+ module External
110
+ extend AbstractRuntime
111
+ include Abstract
112
+ def ole_type
113
+ :external
114
+ end
115
+ end
116
+
117
+ # 1C:Enterprise thick application connection runtime helper
118
+ module Thick
119
+ extend AbstractRuntime
120
+ include Abstract
121
+ def ole_type
122
+ :thick
123
+ end
124
+ end
125
+
126
+ # 1C:Enterprise thin application connection runtime helper
127
+ module Thin
128
+ extend AbstractRuntime
129
+ include Abstract
130
+ def ole_type
131
+ :thin
132
+ end
133
+ end
134
+ end
135
+
136
+ # 1C:Enterprise server runtime helpers
137
+ # @api private
138
+ module Claster
139
+ # @abstract
140
+ # @api private
141
+ module Abstract
142
+ def run(uri, platform_require = '> 0')
143
+ return ole_connector if runned?
144
+ instance_variable_set(:@ole_connector,
145
+ ole_class.new(platform_require))
146
+ run_ uri
147
+ end
148
+ end
149
+
150
+ # 1C:Enterprise serever worcking process connection helper
151
+ module Wp
152
+ extend AbstractRuntime
153
+ include Abstract
154
+ def ole_class
155
+ AssLauncher::Enterprise::Ole::WpConnection
156
+ end
157
+ end
158
+
159
+ # 1C:Enterprise serever agent connection helper
160
+ module Agent
161
+ extend AbstractRuntime
162
+ include Abstract
163
+ def ole_class
164
+ AssLauncher::Enterprise::Ole::AgentConnection
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,124 @@
1
+ module AssOle
2
+ # It mixins for {Module}
3
+ module DSL
4
+ # rubocop:disable Style/PredicateName
5
+
6
+ # Define module as Ole snippet
7
+ # @example
8
+ # module Query
9
+ # is_ole_snippet
10
+ #
11
+ # def execute(query)
12
+ # q = newObject 'Query', query
13
+ # q.exequte
14
+ # end
15
+ # end
16
+ #
17
+ # class MyOleAccessor
18
+ # it_has_ole_runtime
19
+ # like_ole_runtime external_connection
20
+ #
21
+ # include Query
22
+ #
23
+ # def get_foo
24
+ # text = 'select * from foo where bar'
25
+ # result = execute text
26
+ # end
27
+ # end
28
+ #
29
+ # MyOleAccessor.new.get_foo
30
+ def is_ole_snippet
31
+ fail 'Ole snippet must be a Module not a Class' if\
32
+ self.class == Class
33
+ extend AssOle::Snippets::IsSnippet
34
+ end
35
+
36
+ # Define class or module which transparent call Ole runtime as self
37
+ # @example
38
+ # info_base = AssMaintainer::InfoBase.new('', 'File="path"')
39
+ # class MyOleAccessor
40
+ # like_ole_runtime thick_app
41
+ #
42
+ # thick_app.run info_base
43
+ #
44
+ # def hello(s)
45
+ # sTring s
46
+ # end
47
+ # end
48
+ #
49
+ # MyOleAccessor.hello('Ass')
50
+ def like_ole_runtime(runtime)
51
+ it_has_ole_runtime runtime
52
+ case self
53
+ when Class then
54
+ include AssOle::Snippets::LikeOleRuntime
55
+ else
56
+ extend AssOle::Snippets::LikeOleRuntime
57
+ end
58
+ end
59
+
60
+ # Define class or module wich include Ole runtime
61
+ # @example
62
+ # info_base = AssMaintainer::InfoBase.new('', 'File="path"')
63
+ # class MyOleAccessor
64
+ # it_has_ole_runtime thick_app
65
+ #
66
+ # thick_app.run info_base
67
+ #
68
+ # def hello(s)
69
+ # ole_connector.sTring s
70
+ # end
71
+ # end
72
+ #
73
+ # MyOleAccessor.hello('Ass')
74
+ def it_has_ole_runtime(runtime)
75
+ case self
76
+ when Class then
77
+ include runtime
78
+ else
79
+ extend runtime
80
+ end
81
+ end
82
+
83
+ # rubocop:disable Metrics/CyclomaticComplexity
84
+
85
+ # Define Ole runtime
86
+ # @example
87
+ # acct_infobase = AssMaintainer::InfoBase.new('name', 'File="path"')
88
+ #
89
+ # module AccountingExternal
90
+ # is_ole_runtime :external
91
+ # end
92
+ #
93
+ # AccountingExternal.run acct_infobase
94
+ #
95
+ # module MyScript
96
+ # like_ole_runtime acct_infobase
97
+ #
98
+ # def self.version
99
+ # Metadata.Version
100
+ # end
101
+ # end
102
+ #
103
+ # puts MyScript.version
104
+ def is_ole_runtime(type)
105
+ fail 'Ole runtime is a Module not a Class' if self.class == Class
106
+ case type
107
+ when :external then extend AssOle::Runtimes::App::External
108
+ when :thick then extend AssOle::Runtimes::App::Thick
109
+ when :thin then extend AssOle::Runtimes::App::Thin
110
+ when :wp then extend AssOle::Runtimes::Claster::Wp
111
+ when :agent then extend AssOle::Runtimes::Claster::Agent
112
+ else fail "Invalid runtime #{type}"
113
+ end
114
+ end
115
+ # rubocop:enable Metrics/CyclomaticComplexity
116
+
117
+ # rubocop:enable Style/PredicateName
118
+ end
119
+ end
120
+
121
+ # Pathch for include DSL
122
+ class Module
123
+ include AssOle::DSL
124
+ end
@@ -0,0 +1,86 @@
1
+ module AssOle
2
+ # Helpers for transparency and friendly
3
+ # execute 1C:Enterprise Ole connectors methods as
4
+ # methods a Ryby objects and makes easy for use ruby wrappers over the
5
+ # long and awkward 1C:Enterprise embedded programming language syntax.
6
+ # @api private
7
+ module Snippets
8
+ GOOD_CONTEXT = AssLauncher::Enterprise::Ole::OLE_CLIENT_TYPES.values
9
+
10
+ # :nodoc:
11
+ class ContextError < StandardError
12
+ def initialize(ole_class)
13
+ super "Invalid `ole_connector': #{ole_class}"
14
+ end
15
+ end
16
+
17
+ def self.fail_if_bad_context(obj)
18
+ fail ContextError, ole_class(obj) unless good_context? obj
19
+ end
20
+
21
+ def self.good_context?(obj)
22
+ GOOD_CONTEXT.include? ole_class(obj)
23
+ end
24
+ private_class_method :good_context?
25
+
26
+ def self.ole_class(obj)
27
+ obj.ole_connector.class if obj.respond_to? :ole_connector
28
+ end
29
+ private_class_method :ole_class
30
+
31
+ # @api private
32
+ module IsSnippet
33
+ # Helper for pass into 1C ole runtime understandable file system pathes.
34
+ # This provides method {#real_win_path}
35
+ # which will be available in snippets
36
+ module WinPath
37
+ def real_win_path(path)
38
+ AssLauncher::Support::Platforms
39
+ .path(path).realdirpath.win_string
40
+ end
41
+ end
42
+
43
+ # It worcking via method_missing handler
44
+ module MethodMissing
45
+ def method_missing(method, *args)
46
+ AssOle::Snippets.fail_if_bad_context(self)
47
+ return ole_connector.send(method, *args) if ole_connector
48
+ end
49
+ end
50
+
51
+ # Ole ARGV helper for get value over parameters
52
+ # This provides method `argv` which will be available in snippets
53
+ module Argv
54
+ def argv(i)
55
+ WIN32OLE::ARGV[i]
56
+ end
57
+ end
58
+
59
+ def included(obj)
60
+ return if helper?(obj)
61
+ obj.send(:include, MethodMissing) unless obj.include? MethodMissing
62
+ obj.send(:include, Argv) unless obj.include? Argv
63
+ obj.send(:include, WinPath) unless obj.include? WinPath
64
+ end
65
+
66
+ def helper?(obj)
67
+ obj.class == Module
68
+ end
69
+
70
+ def extended(obj)
71
+ return if obj == AssOle::Snippets::IsSnippet
72
+ obj.send(:extend, MethodMissing) unless\
73
+ obj.singleton_class.include? MethodMissing
74
+ obj.send(:extend, Argv) unless\
75
+ obj.singleton_class.include? Argv
76
+ obj.send(:extend, WinPath) unless\
77
+ obj.singleton_class.include? WinPath
78
+ end
79
+ end
80
+
81
+ # @api private
82
+ module LikeOleRuntime
83
+ extend IsSnippet
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,4 @@
1
+ #
2
+ module AssOle
3
+ VERSION = '0.1.0'
4
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ass_ole
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-04 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: :runtime
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: ass_maintainer-info_base
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: Provides features for easy access to 1C:Enterprise applications and 1C:Enterprise
112
+ servers from Ruby code
113
+ email:
114
+ - leoniv.vlasov@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .simplecov
121
+ - .travis.yml
122
+ - Gemfile
123
+ - README.md
124
+ - Rakefile
125
+ - ass_ole.gemspec
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/ass_ole.rb
129
+ - lib/ass_ole/dsl.rb
130
+ - lib/ass_ole/snippets.rb
131
+ - lib/ass_ole/version.rb
132
+ homepage: https://github.com/leoniv/ass_ole
133
+ licenses: []
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.0.14
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Easy access to 1C:Enterprise apps and servers via Ole
155
+ test_files: []
156
+ has_rdoc: