concord 0.1.1 → 0.1.2
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 +7 -0
- data/.travis.yml +8 -7
- data/Gemfile +1 -1
- data/Gemfile.devtools +13 -13
- data/README.md +6 -1
- data/Rakefile +0 -27
- data/concord.gemspec +5 -5
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/mutant.yml +1 -0
- data/config/reek.yml +2 -1
- data/config/roodi.yml +4 -4
- data/lib/concord.rb +26 -26
- data/spec/unit/concord/universal_spec.rb +47 -27
- metadata +11 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2bdb5ade2038b5884813deb9d527d44ddeed1322
|
4
|
+
data.tar.gz: 3f7a3684bd50c715622730568f9e99eb510273da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef6645627811abf8ea289ede8ed2ef4ed6af2b04c5b8548cef13a3697dafa2a13cffdc439b8cfc962c263d1cf24b1af3de71736608d066870001065af31b9316
|
7
|
+
data.tar.gz: 798fe84211b8dca1afec360dc8b86b1d2519f605df699d21dd56314f1a54bc6f36d629a8afb257111b78d6cc2af311f174def3f38b239a0eb241b5146549e28c
|
data/.travis.yml
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
language: ruby
|
2
2
|
script: 'bundle exec rake ci'
|
3
3
|
rvm:
|
4
|
-
- ree
|
5
|
-
- 1.8.7
|
6
4
|
- 1.9.2
|
7
5
|
- 1.9.3
|
8
6
|
- 2.0.0
|
9
7
|
- ruby-head
|
10
|
-
- jruby-18mode
|
11
8
|
- jruby-19mode
|
12
9
|
- jruby-head
|
13
|
-
- rbx-18mode
|
14
10
|
- rbx-19mode
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: ruby-head
|
15
14
|
notifications:
|
16
|
-
irc:
|
17
|
-
|
18
|
-
|
15
|
+
irc:
|
16
|
+
channels:
|
17
|
+
- irc.freenode.org#rom-rb
|
18
|
+
on_success: never
|
19
|
+
on_failure: change
|
data/Gemfile
CHANGED
data/Gemfile.devtools
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem 'rake', '~> 10.0
|
4
|
+
gem 'rake', '~> 10.1.0'
|
5
5
|
gem 'rspec', '~> 2.13.0'
|
6
6
|
gem 'yard', '~> 0.8.6.1'
|
7
7
|
end
|
@@ -11,12 +11,12 @@ group :yard do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
group :guard do
|
14
|
-
gem 'guard', '~> 1.8.
|
14
|
+
gem 'guard', '~> 1.8.1'
|
15
15
|
gem 'guard-bundler', '~> 1.0.0'
|
16
|
-
gem 'guard-rspec', '~>
|
16
|
+
gem 'guard-rspec', '~> 3.0.2'
|
17
17
|
|
18
18
|
# file system change event handling
|
19
|
-
gem 'listen', '~> 1.
|
19
|
+
gem 'listen', '~> 1.2.2'
|
20
20
|
gem 'rb-fchange', '~> 0.0.6', :require => false
|
21
21
|
gem 'rb-fsevent', '~> 0.9.3', :require => false
|
22
22
|
gem 'rb-inotify', '~> 0.9.0', :require => false
|
@@ -28,20 +28,20 @@ group :guard do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
group :metrics do
|
31
|
-
gem 'backports',
|
32
|
-
gem 'coveralls',
|
33
|
-
gem 'flay',
|
34
|
-
gem 'flog',
|
35
|
-
gem 'reek',
|
36
|
-
gem 'simplecov',
|
37
|
-
gem 'yardstick',
|
31
|
+
gem 'backports', '~> 3.3', '>= 3.3.2'
|
32
|
+
gem 'coveralls', '~> 0.6.7'
|
33
|
+
gem 'flay', '~> 2.3.0'
|
34
|
+
gem 'flog', '~> 4.1.0'
|
35
|
+
gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
|
36
|
+
gem 'simplecov', '~> 0.7.1'
|
37
|
+
gem 'yardstick', '~> 0.9.6'
|
38
38
|
|
39
39
|
platforms :ruby_19 do
|
40
40
|
gem 'yard-spellcheck', '~> 0.1.5'
|
41
41
|
end
|
42
42
|
|
43
|
-
platforms :
|
44
|
-
gem 'mutant', '~> 0.
|
43
|
+
platforms :ruby_19, :ruby_20 do
|
44
|
+
gem 'mutant', '~> 0.3.0.beta6'
|
45
45
|
end
|
46
46
|
|
47
47
|
platforms :rbx do
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ class ComposedObject
|
|
12
12
|
include Equalizer.new(:foo, :bar)
|
13
13
|
|
14
14
|
# Return foo
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# @return [Foo]
|
17
17
|
#
|
18
18
|
# @api private
|
@@ -54,6 +54,11 @@ end
|
|
54
54
|
|
55
55
|
Sure the replacement is missing YARD docs, but IMHO it is better.
|
56
56
|
|
57
|
+
Rubies
|
58
|
+
------
|
59
|
+
|
60
|
+
Tested under all >= 1.9 rubies.
|
61
|
+
|
57
62
|
Installation
|
58
63
|
------------
|
59
64
|
|
data/Rakefile
CHANGED
@@ -1,29 +1,2 @@
|
|
1
1
|
require 'devtools'
|
2
2
|
Devtools.init_rake_tasks
|
3
|
-
|
4
|
-
class Rake::Task
|
5
|
-
def overwrite(&block)
|
6
|
-
@actions.clear
|
7
|
-
enhance(&block)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Rake.application.load_imports
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'mutant'
|
15
|
-
rescue LoadError
|
16
|
-
end
|
17
|
-
|
18
|
-
mutant_present = defined?(Mutant)
|
19
|
-
|
20
|
-
allowed_versions = %w(mri-1.9.3 rbx-1.9.3)
|
21
|
-
|
22
|
-
if allowed_versions.include?(Devtools.rvm) and mutant_present and !ENV['DEVTOOLS_SELF']
|
23
|
-
Rake::Task['metrics:mutant'].overwrite do
|
24
|
-
status = Mutant::CLI.run(%W(--rspec-full -r ./spec/spec_helper.rb ::Concord))
|
25
|
-
unless status.zero?
|
26
|
-
fail "Not mutation covered :("
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/concord.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'concord'
|
5
|
-
s.version = '0.1.
|
5
|
+
s.version = '0.1.2'
|
6
6
|
s.authors = ['Markus Schirp']
|
7
|
-
s.email = ['mbj@
|
8
|
-
s.homepage = 'https://github.com/mbj/
|
7
|
+
s.email = ['mbj@schirp-dso.com']
|
8
|
+
s.homepage = 'https://github.com/mbj/concord'
|
9
9
|
s.summary = %q{Helper for object composition}
|
10
10
|
s.description = s.summary
|
11
11
|
|
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.executables = []
|
15
15
|
s.require_paths = ['lib']
|
16
16
|
|
17
|
-
s.add_dependency('adamantium',
|
18
|
-
s.add_dependency('equalizer',
|
17
|
+
s.add_dependency('adamantium', '~> 0.0.10')
|
18
|
+
s.add_dependency('equalizer', '~> 0.0.5')
|
19
19
|
end
|
data/config/flay.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
3
|
-
total_score:
|
2
|
+
threshold: 3
|
3
|
+
total_score: 16.0
|
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
2
|
+
threshold: 23.3
|
data/config/mutant.yml
CHANGED
data/config/reek.yml
CHANGED
data/config/roodi.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
---
|
2
|
-
AbcMetricMethodCheck:
|
2
|
+
AbcMetricMethodCheck:
|
3
3
|
score: 25.1
|
4
4
|
AssignmentInConditionalCheck: { }
|
5
5
|
CaseMissingElseCheck: { }
|
6
6
|
ClassLineCountCheck: { line_count: 317 }
|
7
|
-
ClassNameCheck:
|
7
|
+
ClassNameCheck:
|
8
8
|
pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
|
9
9
|
ClassVariableCheck: { }
|
10
10
|
CyclomaticComplexityBlockCheck: { complexity: 3 }
|
@@ -12,9 +12,9 @@ CyclomaticComplexityMethodCheck: { complexity: 4 }
|
|
12
12
|
EmptyRescueBodyCheck: { }
|
13
13
|
ForLoopCheck: { }
|
14
14
|
MethodLineCountCheck: { line_count: 14 }
|
15
|
-
MethodNameCheck:
|
15
|
+
MethodNameCheck:
|
16
16
|
pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/
|
17
17
|
ModuleLineCountCheck: { line_count: 320 }
|
18
|
-
ModuleNameCheck:
|
18
|
+
ModuleNameCheck:
|
19
19
|
pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
|
20
20
|
ParameterNumberCheck: { parameter_count: 3 }
|
data/lib/concord.rb
CHANGED
@@ -5,6 +5,9 @@ require 'equalizer'
|
|
5
5
|
class Concord < Module
|
6
6
|
include Adamantium::Flat, Equalizer.new(:names)
|
7
7
|
|
8
|
+
# The maximum number of objects the hosting class is composed of
|
9
|
+
MAX_NR_OF_OBJECTS = 3
|
10
|
+
|
8
11
|
# Return names
|
9
12
|
#
|
10
13
|
# @return [Enumerable<Symbol>]
|
@@ -13,7 +16,7 @@ class Concord < Module
|
|
13
16
|
#
|
14
17
|
attr_reader :names
|
15
18
|
|
16
|
-
private
|
19
|
+
private
|
17
20
|
|
18
21
|
# Initialize object
|
19
22
|
#
|
@@ -22,8 +25,8 @@ private
|
|
22
25
|
# @api private
|
23
26
|
#
|
24
27
|
def initialize(*names)
|
25
|
-
if names.length >
|
26
|
-
raise
|
28
|
+
if names.length > MAX_NR_OF_OBJECTS
|
29
|
+
raise "Composition of more than #{MAX_NR_OF_OBJECTS} objects is not allowed"
|
27
30
|
end
|
28
31
|
|
29
32
|
@names = names
|
@@ -38,7 +41,7 @@ private
|
|
38
41
|
# @api private
|
39
42
|
#
|
40
43
|
def included(descendant)
|
41
|
-
|
44
|
+
define_initialize(descendant)
|
42
45
|
define_readers(descendant)
|
43
46
|
define_equalizer(descendant)
|
44
47
|
end
|
@@ -65,11 +68,13 @@ private
|
|
65
68
|
#
|
66
69
|
def define_readers(descendant)
|
67
70
|
attribute_names = names
|
68
|
-
descendant.
|
69
|
-
|
71
|
+
descendant.class_eval do
|
72
|
+
attr_reader *attribute_names
|
73
|
+
protected *attribute_names
|
74
|
+
end
|
70
75
|
end
|
71
76
|
|
72
|
-
# Define
|
77
|
+
# Define initialize method
|
73
78
|
#
|
74
79
|
# @param [Class|Module] descendant
|
75
80
|
#
|
@@ -77,13 +82,18 @@ private
|
|
77
82
|
#
|
78
83
|
# @api private
|
79
84
|
#
|
80
|
-
def
|
81
|
-
|
82
|
-
descendant.class_eval
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def define_initialize(descendant)
|
86
|
+
ivars, size = instance_variable_names, names.size
|
87
|
+
descendant.class_eval do
|
88
|
+
define_method :initialize do |*args|
|
89
|
+
args_size = args.size
|
90
|
+
if args_size != size
|
91
|
+
raise ArgumentError,
|
92
|
+
"wrong number of arguments (#{args_size} for #{size})"
|
93
|
+
end
|
94
|
+
ivars.zip(args) { |ivar, arg| instance_variable_set(ivar, arg) }
|
95
|
+
end
|
96
|
+
end
|
87
97
|
end
|
88
98
|
|
89
99
|
# Return instance variable names
|
@@ -93,23 +103,13 @@ private
|
|
93
103
|
# @api private
|
94
104
|
#
|
95
105
|
def instance_variable_names
|
96
|
-
names.map { |name| "@#{name}" }
|
97
|
-
end
|
98
|
-
|
99
|
-
# Return param names
|
100
|
-
#
|
101
|
-
# @return [String]
|
102
|
-
#
|
103
|
-
# @api private
|
104
|
-
#
|
105
|
-
def argument_names
|
106
|
-
names.join(', ')
|
106
|
+
names.map { |name| "@#{name}" }
|
107
107
|
end
|
108
108
|
|
109
109
|
# Mixin for public attribute readers
|
110
110
|
class Public < self
|
111
111
|
|
112
|
-
# Hook called when module is included
|
112
|
+
# Hook called when module is included
|
113
113
|
#
|
114
114
|
# @param [Class,Module] descendant
|
115
115
|
#
|
@@ -16,48 +16,68 @@ describe Concord do
|
|
16
16
|
let(:bar) { mock('Bar') }
|
17
17
|
|
18
18
|
context 'initializer lines' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
it 'creates a private #initialize method' do
|
20
|
+
mod = Module.new
|
21
|
+
expect { mod.send(:include, Concord.new) }.
|
22
|
+
to change { mod.private_method_defined?(:initialize) }.
|
23
|
+
from(false).to(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates an initializer that asserts the number of arguments' do
|
27
|
+
expect { class_under_test.new(1) }.
|
28
|
+
to raise_error(ArgumentError, 'wrong number of arguments (1 for 2)')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'creates an initializer that allows 2 arguments' do
|
32
|
+
expect { class_under_test.new(1, 2) }.to_not raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'creates an initializer that sets the instance variables' do
|
36
|
+
instance = class_under_test.new(1, 2)
|
37
|
+
expect(instance.instance_variable_get(:@foo)).to be(1)
|
38
|
+
expect(instance.instance_variable_get(:@bar)).to be(2)
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
32
|
-
context '
|
33
|
-
it '
|
34
|
-
|
35
|
-
|
36
|
-
|
42
|
+
context 'with no objects to compose' do
|
43
|
+
it 'assigns no ivars' do
|
44
|
+
instance = Class.new { include Concord.new }.new
|
45
|
+
expect(instance.instance_variables).to be_empty
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'visibility' do
|
50
|
+
it 'should set attribute readers to protected' do
|
51
|
+
protected_methods = class_under_test.protected_instance_methods
|
52
|
+
expect(protected_methods).to match_array([:foo, :bar])
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
40
56
|
context 'attribute behavior' do
|
41
57
|
subject { instance_a }
|
42
58
|
|
43
|
-
specify { subject.send(:foo).
|
44
|
-
specify { subject.send(:bar).
|
59
|
+
specify { expect(subject.send(:foo)).to be(foo) }
|
60
|
+
specify { expect(subject.send(:bar)).to be(bar) }
|
45
61
|
end
|
46
62
|
|
47
63
|
context 'equalization behavior' do
|
48
64
|
specify 'composed objects are equalized on attributes' do
|
49
|
-
instance_a.
|
50
|
-
instance_a.hash.
|
51
|
-
instance_a.
|
52
|
-
|
53
|
-
instance_a.
|
54
|
-
instance_a.should_not eql(instance_c)
|
65
|
+
expect(instance_a).to eql(instance_b)
|
66
|
+
expect(instance_a.hash).to eql(instance_b.hash)
|
67
|
+
expect(instance_a).to eql(instance_b)
|
68
|
+
expect(instance_a).to_not be(instance_c)
|
69
|
+
expect(instance_a).to_not eql(instance_c)
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
58
|
-
context '
|
73
|
+
context 'when composing too many objects' do
|
59
74
|
specify 'it raises an error' do
|
60
|
-
expect {
|
75
|
+
expect {
|
76
|
+
Concord.new(:a, :b, :c, :d)
|
77
|
+
}.to raise_error(RuntimeError, 'Composition of more than 3 objects is not allowed')
|
78
|
+
expect {
|
79
|
+
Concord.new(:a, :b, :c)
|
80
|
+
}.to_not raise_error
|
61
81
|
end
|
62
82
|
end
|
63
83
|
|
@@ -70,8 +90,8 @@ describe Concord do
|
|
70
90
|
|
71
91
|
it 'should create public attr readers' do
|
72
92
|
object = class_under_test.new(:foo, :bar)
|
73
|
-
object.foo.
|
74
|
-
object.bar.
|
93
|
+
expect(object.foo).to eql(:foo)
|
94
|
+
expect(object.bar).to eql(:bar)
|
75
95
|
end
|
76
96
|
end
|
77
97
|
end
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Markus Schirp
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: adamantium
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.
|
19
|
+
version: 0.0.10
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.0.
|
26
|
+
version: 0.0.10
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: equalizer
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,14 +34,13 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.0.5
|
46
41
|
description: Helper for object composition
|
47
42
|
email:
|
48
|
-
- mbj@
|
43
|
+
- mbj@schirp-dso.com
|
49
44
|
executables: []
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
@@ -70,29 +65,28 @@ files:
|
|
70
65
|
- lib/concord.rb
|
71
66
|
- spec/spec_helper.rb
|
72
67
|
- spec/unit/concord/universal_spec.rb
|
73
|
-
homepage: https://github.com/mbj/
|
68
|
+
homepage: https://github.com/mbj/concord
|
74
69
|
licenses: []
|
70
|
+
metadata: {}
|
75
71
|
post_install_message:
|
76
72
|
rdoc_options: []
|
77
73
|
require_paths:
|
78
74
|
- lib
|
79
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
76
|
requirements:
|
82
|
-
- -
|
77
|
+
- - '>='
|
83
78
|
- !ruby/object:Gem::Version
|
84
79
|
version: '0'
|
85
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
81
|
requirements:
|
88
|
-
- -
|
82
|
+
- - '>='
|
89
83
|
- !ruby/object:Gem::Version
|
90
84
|
version: '0'
|
91
85
|
requirements: []
|
92
86
|
rubyforge_project:
|
93
|
-
rubygems_version:
|
87
|
+
rubygems_version: 2.0.2
|
94
88
|
signing_key:
|
95
|
-
specification_version:
|
89
|
+
specification_version: 4
|
96
90
|
summary: Helper for object composition
|
97
91
|
test_files: []
|
98
92
|
has_rdoc:
|