lb-operation 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/.rspec +6 -0
- data/.rubocop.yml +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/Guardfile +43 -0
- data/LICENSE +20 -0
- data/README.md +17 -0
- data/Rakefile +6 -0
- data/config/devtools.yml +2 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/reek.yml +103 -0
- data/config/rubocop.yml +5 -0
- data/config/yardstick.yml +2 -0
- data/lb-operation.gemspec +35 -0
- data/lib/lb/operation/log.rb +56 -0
- data/lib/lb/operation/version.rb +7 -0
- data/lib/lb/operation.rb +58 -0
- data/lib/lb-operation.rb +4 -0
- data/rakelib/ci.rake +23 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/helper.rb +6 -0
- data/spec/unit/lb/operation/call_spec.rb +66 -0
- data/spec/unit/lb/operation/class_methods/new_spec.rb +12 -0
- data/spec/unit/lb/operation/class_methods/operation_name_spec.rb +16 -0
- data/spec/unit/lb/operation/handle_exception_spec.rb +50 -0
- data/spec/unit/lb/operation/value_spec.rb +54 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4225735f37ebf353bf32c324f99952f1521b1552
|
4
|
+
data.tar.gz: 14df6143ac392c1fba5d2193891a20b20cd2c8a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58ca87cbc70da28659bb8f4c7361d6d54d24fe2906ede95a883eb478b588a3cdc62321e8f6c40b5e068eaea7ef8a7d8309ca04461124bff57f79763fb22c56f9
|
7
|
+
data.tar.gz: 71ee2283f511a42590d14baa089b836a648649deb81f96c418c64eee9074c33ea56bf6c327bfd75f082ce6b2b1d31676a10e1df824cb6cb18a985561ec4054b1
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.sw[op]
|
15
|
+
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
.rbx
|
19
|
+
|
20
|
+
## PROJECT::GENERAL
|
21
|
+
*.gem
|
22
|
+
coverage
|
23
|
+
profiling
|
24
|
+
turbulence
|
25
|
+
rdoc
|
26
|
+
pkg
|
27
|
+
tmp
|
28
|
+
doc
|
29
|
+
log
|
30
|
+
.yardoc
|
31
|
+
measurements
|
32
|
+
|
33
|
+
## BUNDLER
|
34
|
+
.bundle
|
35
|
+
Gemfile.lock
|
36
|
+
|
37
|
+
## ctags
|
38
|
+
tags
|
39
|
+
gems.tags
|
40
|
+
|
41
|
+
## PROJECT::SPECIFIC
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
./config/rubocop.yml
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.2
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
guard :bundler do
|
5
|
+
watch('Gemfile')
|
6
|
+
watch('Gemfile.lock')
|
7
|
+
watch(/\A(.+)\.gemspec\z/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard :rspec, cmd: 'bundle exec rspec ' +
|
11
|
+
File.read('.rspec').split.join(' '),
|
12
|
+
failed_mode: :keep do
|
13
|
+
# Run all specs if configuration is modified
|
14
|
+
watch('.rspec') { 'spec' }
|
15
|
+
watch('Guardfile') { 'spec' }
|
16
|
+
watch('Gemfile.lock') { 'spec' }
|
17
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
18
|
+
|
19
|
+
# Run all specs if supporting files files are modified
|
20
|
+
watch(%r{\Aspec/(?:fixtures|lib|support|shared)/.+\.rb\z}) { 'spec' }
|
21
|
+
|
22
|
+
# Run unit specs if associated lib code is modified
|
23
|
+
watch(%r{\Alib/(.+)\.rb\z}) do |m|
|
24
|
+
Dir["spec/unit/#{m[1]}*"]
|
25
|
+
end
|
26
|
+
|
27
|
+
watch(%r{\Alib/(.+)/support/(.+)\.rb\z}) do |m|
|
28
|
+
Dir["spec/unit/#{m[1]}/#{m[2]}*"]
|
29
|
+
end
|
30
|
+
|
31
|
+
watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") do
|
32
|
+
'spec'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Run a spec if it is modified
|
36
|
+
watch(%r{\Aspec/(?:unit|integration|features)/.+_spec\.rb\z})
|
37
|
+
end
|
38
|
+
|
39
|
+
guard :rubocop, cli: %w(--config config/rubocop.yml) do
|
40
|
+
watch(/.+\.(?:rb|rake|gemspec)\z/)
|
41
|
+
watch(%r{\Aconfig/rubocop\.yml\z}) { |m| File.dirname(m[0]) }
|
42
|
+
watch(%r{(?:.+/)?\.rubocop\.yml\z}) { |m| File.dirname(m[0]) }
|
43
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2017 Firas Zaidan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
[gem]: https://rubygems.org/gems/lb-operation
|
2
|
+
[gemnasium]: https://gemnasium.com/lb-rb/lb-operation
|
3
|
+
|
4
|
+
# lb-operation
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/lb-operation.svg)][gem]
|
7
|
+
[![Dependency Status](https://gemnasium.com/lb-rb/lb-operation.svg)][gemnasium]
|
8
|
+
|
9
|
+
Operations for transactions
|
10
|
+
|
11
|
+
## Credits
|
12
|
+
|
13
|
+
* [Firas Zaidan](https://github.com/zaidan)
|
14
|
+
|
15
|
+
## License
|
16
|
+
|
17
|
+
See `LICENSE` file.
|
data/Rakefile
ADDED
data/config/devtools.yml
ADDED
data/config/flay.yml
ADDED
data/config/flog.yml
ADDED
data/config/mutant.yml
ADDED
data/config/reek.yml
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
---
|
2
|
+
Attribute:
|
3
|
+
enabled: false
|
4
|
+
exclude: []
|
5
|
+
BooleanParameter:
|
6
|
+
enabled: true
|
7
|
+
exclude: []
|
8
|
+
ClassVariable:
|
9
|
+
enabled: true
|
10
|
+
exclude: []
|
11
|
+
ControlParameter:
|
12
|
+
enabled: true
|
13
|
+
exclude: []
|
14
|
+
DataClump:
|
15
|
+
enabled: true
|
16
|
+
exclude: []
|
17
|
+
max_copies: 0
|
18
|
+
min_clump_size: 2
|
19
|
+
DuplicateMethodCall:
|
20
|
+
enabled: true
|
21
|
+
exclude: []
|
22
|
+
max_calls: 1
|
23
|
+
allow_calls: []
|
24
|
+
FeatureEnvy:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
IrresponsibleModule:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
LongParameterList:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
max_params: 2
|
34
|
+
overrides: {}
|
35
|
+
LongYieldList:
|
36
|
+
enabled: true
|
37
|
+
exclude: []
|
38
|
+
max_params: 0
|
39
|
+
NestedIterators:
|
40
|
+
enabled: true
|
41
|
+
exclude: []
|
42
|
+
max_allowed_nesting: 1
|
43
|
+
ignore_iterators: []
|
44
|
+
NilCheck:
|
45
|
+
enabled: true
|
46
|
+
exclude: []
|
47
|
+
RepeatedConditional:
|
48
|
+
enabled: true
|
49
|
+
exclude: []
|
50
|
+
max_ifs: 1
|
51
|
+
TooManyConstants:
|
52
|
+
enabled: true
|
53
|
+
exclude: []
|
54
|
+
TooManyInstanceVariables:
|
55
|
+
enabled: true
|
56
|
+
exclude: []
|
57
|
+
max_instance_variables: 2
|
58
|
+
TooManyMethods:
|
59
|
+
enabled: true
|
60
|
+
exclude: []
|
61
|
+
max_methods: 15
|
62
|
+
TooManyStatements:
|
63
|
+
enabled: true
|
64
|
+
exclude: []
|
65
|
+
max_statements: 5
|
66
|
+
UncommunicativeMethodName:
|
67
|
+
enabled: true
|
68
|
+
exclude: []
|
69
|
+
reject:
|
70
|
+
- !ruby/regexp /^[a-z]$/
|
71
|
+
- !ruby/regexp /[0-9]$/
|
72
|
+
- !ruby/regexp /[A-Z]/
|
73
|
+
accept: []
|
74
|
+
UncommunicativeModuleName:
|
75
|
+
enabled: true
|
76
|
+
exclude: []
|
77
|
+
reject:
|
78
|
+
- !ruby/regexp /^.$/
|
79
|
+
- !ruby/regexp /[0-9]$/
|
80
|
+
accept: []
|
81
|
+
UncommunicativeParameterName:
|
82
|
+
enabled: true
|
83
|
+
exclude: []
|
84
|
+
reject:
|
85
|
+
- !ruby/regexp /^.$/
|
86
|
+
- !ruby/regexp /[0-9]$/
|
87
|
+
- !ruby/regexp /[A-Z]/
|
88
|
+
accept: []
|
89
|
+
UncommunicativeVariableName:
|
90
|
+
enabled: true
|
91
|
+
exclude: []
|
92
|
+
reject:
|
93
|
+
- !ruby/regexp /^.$/
|
94
|
+
- !ruby/regexp /[0-9]$/
|
95
|
+
- !ruby/regexp /[A-Z]/
|
96
|
+
accept: []
|
97
|
+
UnusedParameters:
|
98
|
+
enabled: true
|
99
|
+
exclude: []
|
100
|
+
UtilityFunction:
|
101
|
+
enabled: true
|
102
|
+
exclude: []
|
103
|
+
max_helper_calls: 0
|
data/config/rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.expand_path('../lib/lb/operation/version', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'lb-operation'
|
8
|
+
gem.version = LB::Operation::VERSION.dup
|
9
|
+
gem.authors = ['Firas Zaidan']
|
10
|
+
gem.email = ['firas@zaidan.de']
|
11
|
+
gem.description = 'Operations for transactions'
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = 'https://github.com/lb-rb/lb'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.bindir = 'bin'
|
17
|
+
gem.require_paths = %w(lib bin)
|
18
|
+
gem.files = `git ls-files`
|
19
|
+
.split($INPUT_RECORD_SEPARATOR)
|
20
|
+
gem.executables = `git ls-files -- bin/*`
|
21
|
+
.split("\n").map { |f| File.basename(f) }
|
22
|
+
gem.test_files = `git ls-files -- spec`
|
23
|
+
.split($INPUT_RECORD_SEPARATOR)
|
24
|
+
gem.extra_rdoc_files = %w(README.md)
|
25
|
+
gem.required_ruby_version = '>= 2.4'
|
26
|
+
|
27
|
+
gem.add_dependency 'dry-configurable', '~> 0.7.0', '< 0.7.1'
|
28
|
+
gem.add_dependency 'dry-equalizer', '~> 0.2.0'
|
29
|
+
|
30
|
+
gem.add_development_dependency 'devtools', '~> 0.1.18'
|
31
|
+
gem.add_development_dependency 'guard', '~> 2.14'
|
32
|
+
gem.add_development_dependency 'guard-bundler', '~> 2.1'
|
33
|
+
gem.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3'
|
34
|
+
gem.add_development_dependency 'guard-rubocop', '~> 1.3'
|
35
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LB
|
4
|
+
class Operation
|
5
|
+
# Helper for logging
|
6
|
+
module Log
|
7
|
+
# Logger class interface
|
8
|
+
module ClassInterface
|
9
|
+
attr_reader :logger
|
10
|
+
|
11
|
+
# Sets the logger.
|
12
|
+
#
|
13
|
+
# @param [Object] logger
|
14
|
+
# @return [self]
|
15
|
+
def with_logger(logger)
|
16
|
+
@logger = logger
|
17
|
+
self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Extends base class with class interface.
|
22
|
+
#
|
23
|
+
# @param [Class] base
|
24
|
+
# @return [Object]
|
25
|
+
def self.included(base)
|
26
|
+
base.extend ClassInterface
|
27
|
+
end
|
28
|
+
|
29
|
+
# Retrieves the logger.
|
30
|
+
#
|
31
|
+
# @return [Object]
|
32
|
+
def logger
|
33
|
+
result = self.class.logger
|
34
|
+
if result.nil?
|
35
|
+
raise ArgumentError,
|
36
|
+
'No logger availible: Please set logger via '\
|
37
|
+
'LB::Operation::Log[logger] or '\
|
38
|
+
'LB::Operation::Log.with_logger(logger)'
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
# Calls given logger method with given arguments.
|
44
|
+
#
|
45
|
+
# @param [Symbol] method
|
46
|
+
# @param [Array] args
|
47
|
+
# @return [Object]
|
48
|
+
def log(method, *args)
|
49
|
+
unless logger.respond_to?(method)
|
50
|
+
raise ArgumentError, "Logger does not respond to :#{method}."
|
51
|
+
end
|
52
|
+
logger.public_send(method, *args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/lb/operation.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-configurable'
|
4
|
+
require 'dry-equalizer'
|
5
|
+
|
6
|
+
require 'lb/operation/version'
|
7
|
+
require 'lb/operation/log'
|
8
|
+
|
9
|
+
# LB namespace
|
10
|
+
module LB
|
11
|
+
# Base class for operations
|
12
|
+
class Operation
|
13
|
+
include Dry::Equalizer(:config)
|
14
|
+
extend Dry::Configurable
|
15
|
+
include LB::Operation::Log
|
16
|
+
|
17
|
+
setting :name
|
18
|
+
|
19
|
+
attr_reader :config
|
20
|
+
|
21
|
+
# Retrieves the operation name.
|
22
|
+
#
|
23
|
+
# @return [Symbol]
|
24
|
+
def self.operation_name
|
25
|
+
config.name
|
26
|
+
end
|
27
|
+
|
28
|
+
# Executes the operation.
|
29
|
+
#
|
30
|
+
# @return [self]
|
31
|
+
def call
|
32
|
+
raise NotImplementedError, 'Override Operation#call(*args)!'
|
33
|
+
end
|
34
|
+
|
35
|
+
# Executes the operation with given arguments. Returns result or value of
|
36
|
+
# result if result responds to :value.
|
37
|
+
#
|
38
|
+
# @param [Array] args
|
39
|
+
# @return [Object]
|
40
|
+
def value(*args)
|
41
|
+
result = call(*args)
|
42
|
+
result.respond_to?(:value) ? result.value : result
|
43
|
+
end
|
44
|
+
|
45
|
+
# Handles exception if given: Logs message and backtrace as :error.
|
46
|
+
#
|
47
|
+
# @param [Hash] error
|
48
|
+
# @return [self]
|
49
|
+
def handle_exception(error)
|
50
|
+
return self unless error.key?(:exception)
|
51
|
+
exception = error.fetch(:exception)
|
52
|
+
log :error, exception.message
|
53
|
+
log :error, exception.backtrace.inspect
|
54
|
+
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/lb-operation.rb
ADDED
data/rakelib/ci.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Remove existing same-named tasks
|
3
|
+
%w(ci ci:metrics).each do |task|
|
4
|
+
klass = Rake::Task
|
5
|
+
klass[task].clear if klass.task_defined?(task)
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Run all specs, metrics and mutant'
|
9
|
+
task ci: %w(ci:metrics metrics:mutant)
|
10
|
+
|
11
|
+
namespace :ci do
|
12
|
+
tasks = %w(
|
13
|
+
metrics:coverage
|
14
|
+
metrics:yardstick:verify
|
15
|
+
metrics:rubocop
|
16
|
+
metrics:flog
|
17
|
+
metrics:flay
|
18
|
+
spec:integration
|
19
|
+
)
|
20
|
+
|
21
|
+
desc 'Run metrics (except mutant)'
|
22
|
+
task metrics: tasks
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
if ENV['COVERAGE'] == 'true'
|
5
|
+
require 'simplecov'
|
6
|
+
|
7
|
+
SimpleCov.start do
|
8
|
+
command_name 'spec:unit'
|
9
|
+
|
10
|
+
add_filter 'config'
|
11
|
+
add_filter 'spec'
|
12
|
+
|
13
|
+
minimum_coverage 100
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
$LOAD_PATH << 'lib'
|
18
|
+
|
19
|
+
require 'lb-operation'
|
20
|
+
|
21
|
+
require 'devtools/spec_helper'
|
22
|
+
|
23
|
+
# require spec support files and shared behavior
|
24
|
+
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
|
25
|
+
require file
|
26
|
+
end
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
config.include(SpecHelper)
|
30
|
+
config.mock_framework = :rspec
|
31
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LB::Operation, '#call' do
|
5
|
+
subject { object.call(*args) }
|
6
|
+
|
7
|
+
let(:args) { [] }
|
8
|
+
let(:object) { described_class.new }
|
9
|
+
|
10
|
+
let(:expected_result) { 'called' }
|
11
|
+
|
12
|
+
let(:error) { 'Override Operation#call(*args)!' }
|
13
|
+
|
14
|
+
let(:child_class) do
|
15
|
+
Class.new(described_class) do
|
16
|
+
setting :foo, :bar
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:child_class_with_call) do
|
21
|
+
klass = child_class.dup
|
22
|
+
klass.class_eval do
|
23
|
+
def call
|
24
|
+
'called'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
klass
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should raise NotImplementedError when called without extending' do
|
31
|
+
expect { subject }.to raise_error(NotImplementedError, error)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with child class' do
|
35
|
+
let(:object) { child_class.new }
|
36
|
+
|
37
|
+
it 'should raise NotImplementedError when called without '\
|
38
|
+
'overwriting call' do
|
39
|
+
expect { subject }.to raise_error(NotImplementedError, error)
|
40
|
+
end
|
41
|
+
context 'and overwritten call method' do
|
42
|
+
let(:object) { child_class_with_call.new }
|
43
|
+
|
44
|
+
it 'should return "called"' do
|
45
|
+
expect(subject).to eq(expected_result)
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'and multiple arguments' do
|
49
|
+
let(:child_class_with_call) do
|
50
|
+
klass = child_class.dup
|
51
|
+
klass.class_eval do
|
52
|
+
def call(a, b, c)
|
53
|
+
a + b + c
|
54
|
+
end
|
55
|
+
end
|
56
|
+
klass
|
57
|
+
end
|
58
|
+
let(:args) { %w(ca ll ed) }
|
59
|
+
|
60
|
+
it 'should return "called"' do
|
61
|
+
expect(subject).to eq(expected_result)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LB::Operation, '.new' do
|
5
|
+
subject { object.new }
|
6
|
+
|
7
|
+
let(:object) { described_class }
|
8
|
+
|
9
|
+
it 'should be instance of LB::Operation' do
|
10
|
+
expect(subject).to be_instance_of(object)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LB::Operation, '.operation_name' do
|
5
|
+
subject { object.operation_name }
|
6
|
+
|
7
|
+
let(:object) do
|
8
|
+
Class.new(described_class) do
|
9
|
+
setting :name, :foo
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return :foo' do
|
14
|
+
expect(subject).to eq(:foo)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LB::Operation, '#handle_exception' do
|
5
|
+
subject { object.handle_exception(error) }
|
6
|
+
|
7
|
+
let(:object) { described_class.with_logger(logger).new }
|
8
|
+
|
9
|
+
let(:error) { {} }
|
10
|
+
|
11
|
+
let(:logger) do
|
12
|
+
Class.new do
|
13
|
+
def error(message)
|
14
|
+
message
|
15
|
+
end
|
16
|
+
end.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return self' do
|
20
|
+
expect(subject).to be(object)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with value' do
|
24
|
+
let(:inspect_value) { double(:inspect) }
|
25
|
+
let(:backtrace) { Struct.new(:inspect).new(inspect_value) }
|
26
|
+
let(:message) { double(:message) }
|
27
|
+
|
28
|
+
let(:exception) { Struct.new(:message, :backtrace).new(message, backtrace) }
|
29
|
+
let(:error) { { exception: exception } }
|
30
|
+
|
31
|
+
it 'should log' do
|
32
|
+
LB::Operation.with_logger(logger)
|
33
|
+
|
34
|
+
expect(object).to receive(:log)
|
35
|
+
.at_least(:once)
|
36
|
+
.with(:error, message)
|
37
|
+
.ordered
|
38
|
+
expect(object).to receive(:log)
|
39
|
+
.at_least(:once)
|
40
|
+
.with(:error, inspect_value)
|
41
|
+
.ordered
|
42
|
+
|
43
|
+
subject
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return self' do
|
47
|
+
expect(subject).to be(object)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LB::Operation, '#value' do
|
5
|
+
subject { object.value(*args) }
|
6
|
+
|
7
|
+
let(:object) { object_class.new }
|
8
|
+
|
9
|
+
let(:args) { [] }
|
10
|
+
|
11
|
+
let(:expected_result) { 'called' }
|
12
|
+
|
13
|
+
let(:object_class) do
|
14
|
+
Class.new(described_class) do
|
15
|
+
def call
|
16
|
+
'called'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should return "called"' do
|
22
|
+
expect(subject).to eq(expected_result)
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with value' do
|
26
|
+
let(:object_class) do
|
27
|
+
Class.new(described_class) do
|
28
|
+
def call
|
29
|
+
Struct.new(:value).new('called')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return "called"' do
|
35
|
+
expect(subject).to eq(expected_result)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with arguments' do
|
39
|
+
let(:args) { %w(ca ll ed) }
|
40
|
+
|
41
|
+
let(:object_class) do
|
42
|
+
Class.new(described_class) do
|
43
|
+
def call(a, b, c)
|
44
|
+
Struct.new(:value).new(a + b + c)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return "called"' do
|
50
|
+
expect(subject).to eq(expected_result)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lb-operation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Firas Zaidan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-configurable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.7.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.7.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.7.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dry-equalizer
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.2.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: devtools
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.18
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.18
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: guard
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.14'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2.14'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: guard-bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.1'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: guard-rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '4.7'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 4.7.3
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '4.7'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 4.7.3
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: guard-rubocop
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '1.3'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '1.3'
|
123
|
+
description: Operations for transactions
|
124
|
+
email:
|
125
|
+
- firas@zaidan.de
|
126
|
+
executables: []
|
127
|
+
extensions: []
|
128
|
+
extra_rdoc_files:
|
129
|
+
- README.md
|
130
|
+
files:
|
131
|
+
- ".gitignore"
|
132
|
+
- ".rspec"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- ".ruby-version"
|
135
|
+
- Gemfile
|
136
|
+
- Guardfile
|
137
|
+
- LICENSE
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- config/devtools.yml
|
141
|
+
- config/flay.yml
|
142
|
+
- config/flog.yml
|
143
|
+
- config/mutant.yml
|
144
|
+
- config/reek.yml
|
145
|
+
- config/rubocop.yml
|
146
|
+
- config/yardstick.yml
|
147
|
+
- lb-operation.gemspec
|
148
|
+
- lib/lb-operation.rb
|
149
|
+
- lib/lb/operation.rb
|
150
|
+
- lib/lb/operation/log.rb
|
151
|
+
- lib/lb/operation/version.rb
|
152
|
+
- rakelib/ci.rake
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/support/helper.rb
|
155
|
+
- spec/unit/lb/operation/call_spec.rb
|
156
|
+
- spec/unit/lb/operation/class_methods/new_spec.rb
|
157
|
+
- spec/unit/lb/operation/class_methods/operation_name_spec.rb
|
158
|
+
- spec/unit/lb/operation/handle_exception_spec.rb
|
159
|
+
- spec/unit/lb/operation/value_spec.rb
|
160
|
+
homepage: https://github.com/lb-rb/lb
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
- bin
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2.4'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.6.14
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Operations for transactions
|
185
|
+
test_files:
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/support/helper.rb
|
188
|
+
- spec/unit/lb/operation/call_spec.rb
|
189
|
+
- spec/unit/lb/operation/class_methods/new_spec.rb
|
190
|
+
- spec/unit/lb/operation/class_methods/operation_name_spec.rb
|
191
|
+
- spec/unit/lb/operation/handle_exception_spec.rb
|
192
|
+
- spec/unit/lb/operation/value_spec.rb
|