concord 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f74165f31b905e23604129b63bee915d27163b01
4
- data.tar.gz: a0c18289f47110909de05e3a0af56b10a282101a
2
+ SHA256:
3
+ metadata.gz: 00e1baf3ada59ca39db75ee30475ab7f0cee4de044b7e3656f9de5265e7468a9
4
+ data.tar.gz: 709c2cce624598048899d5335dc45d1922caccb4aa9347bbf010477de9145496
5
5
  SHA512:
6
- metadata.gz: 4efa105dc76a5bdff0b93d2fb91897a56f16ae1115314472bc25b913d7eb2f153ef0c0514d123b1d257856a2524008c7463d61a2e97ea447bfb30a8b878b9229
7
- data.tar.gz: 1c13e549d343a704e9df9d336e7f6d9430280c8a24a069a90c2c81e20ec9a1256792aa294e90ae54a1df10392d028b703b8faf22eb97979173f32a9302cbc780
6
+ metadata.gz: 6e79d310bb26e6291a5935d1dbe5a91dce9cac422cd9922971b14dc5429e6c284aaa4f5777fc42a506599b79a0034275377d514f15c42b152282dc0651ffb551
7
+ data.tar.gz: 9211e15e7bf7ccfa4dd7c20f1768cf72c6362a82e0066a308c0342cae2eabd5ea29efed345c27ab0c0d5250b208a7c7f27e3d2e38b03fc1e8577778d6054f476
@@ -26,11 +26,10 @@ class Concord < Module
26
26
  #
27
27
  def initialize(*names)
28
28
  if names.length > MAX_NR_OF_OBJECTS
29
- raise "Composition of more than #{MAX_NR_OF_OBJECTS} objects is not allowed"
29
+ fail "Composition of more than #{MAX_NR_OF_OBJECTS} objects is not allowed"
30
30
  end
31
31
 
32
- @names = names
33
- @module = Module.new
32
+ @names, @module = names, Module.new
34
33
  define_initialize
35
34
  define_readers
36
35
  define_equalizer
@@ -38,8 +37,6 @@ class Concord < Module
38
37
 
39
38
  # Hook run when module is included
40
39
  #
41
- # @param [Class|Module] descendant
42
- #
43
40
  # @return [undefined]
44
41
  #
45
42
  # @api private
@@ -50,8 +47,6 @@ class Concord < Module
50
47
 
51
48
  # Define equalizer
52
49
  #
53
- # @param [Class|Module] descendant
54
- #
55
50
  # @return [undefined]
56
51
  #
57
52
  # @api private
@@ -62,8 +57,6 @@ class Concord < Module
62
57
 
63
58
  # Define readers
64
59
  #
65
- # @param [Class|Module] descendant
66
- #
67
60
  # @return [undefined]
68
61
  #
69
62
  # @api private
@@ -78,19 +71,19 @@ class Concord < Module
78
71
 
79
72
  # Define initialize method
80
73
  #
81
- # @param [Class|Module] descendant
82
- #
83
74
  # @return [undefined]
84
75
  #
85
76
  # @api private
86
77
  #
78
+ # rubocop:disable MethodLength
79
+ #
87
80
  def define_initialize
88
81
  ivars, size = instance_variable_names, names.size
89
82
  @module.class_eval do
90
83
  define_method :initialize do |*args|
91
84
  args_size = args.size
92
85
  if args_size != size
93
- raise ArgumentError, "wrong number of arguments (#{args_size} for #{size})"
86
+ fail ArgumentError, "wrong number of arguments (#{args_size} for #{size})"
94
87
  end
95
88
  ivars.zip(args) { |ivar, arg| instance_variable_set(ivar, arg) }
96
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-20 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adamantium
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: devtools
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.26
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.26
41
55
  description: Helper for object composition
42
56
  email:
43
57
  - mbj@schirp-dso.com
@@ -45,35 +59,12 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - ".circle.yml"
49
- - ".gitignore"
50
- - ".rspec"
51
- - ".rubocop.yml"
52
- - ".travis.yml"
53
- - Changelog.md
54
- - Gemfile
55
- - Gemfile.devtools
56
- - Guardfile
57
- - LICENSE
58
- - README.md
59
- - Rakefile
60
- - circle.yml
61
- - concord.gemspec
62
- - config/flay.yml
63
- - config/flog.yml
64
- - config/mutant.yml
65
- - config/reek.yml
66
- - config/roodi.yml
67
- - config/rubocop.yml
68
- - config/yardstick.yml
69
62
  - lib/concord.rb
70
- - spec/spec_helper.rb
71
- - spec/unit/concord/universal_spec.rb
72
63
  homepage: https://github.com/mbj/concord
73
64
  licenses:
74
65
  - MIT
75
66
  metadata: {}
76
- post_install_message:
67
+ post_install_message:
77
68
  rdoc_options: []
78
69
  require_paths:
79
70
  - lib
@@ -88,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
79
  - !ruby/object:Gem::Version
89
80
  version: '0'
90
81
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.2.2
93
- signing_key:
82
+ rubygems_version: 3.0.3
83
+ signing_key:
94
84
  specification_version: 4
95
85
  summary: Helper for object composition
96
86
  test_files: []
@@ -1,4 +0,0 @@
1
- ---
2
- test:
3
- override:
4
- - bundle exec rake ci
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- /tmp
2
- /Gemfile.lock
3
- /.bundle
4
- /vendor
data/.rspec DELETED
@@ -1,6 +0,0 @@
1
- --color
2
- --format progress
3
- --profile
4
- --order random
5
- --fail-fast
6
- --warnings
@@ -1,7 +0,0 @@
1
- AllCops:
2
- Includes:
3
- - 'Gemfile'
4
- Excludes:
5
- - 'Gemfile.devtools'
6
- - 'vendor/**'
7
- - 'benchmarks/**'
@@ -1,17 +0,0 @@
1
- language: ruby
2
- script: 'bundle exec rake ci'
3
- rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - jruby-19mode
7
- - jruby-head
8
- - rbx
9
- matrix:
10
- allow_failures:
11
- - rvm: ruby-head
12
- notifications:
13
- irc:
14
- channels:
15
- - irc.freenode.org#rom-rb
16
- on_success: never
17
- on_failure: change
@@ -1,37 +0,0 @@
1
- # v0.1.5 2014-04-10
2
-
3
- * Dependency bumps
4
- * Support calling (z)super from custom initialize
5
-
6
- # v0.1.4 2013-09-22
7
-
8
- * Dependency bumps
9
-
10
- # v0.1.3 2013-08-31
11
-
12
- * Dependency bumps
13
-
14
- # v0.1.2 2013-08-07
15
-
16
- * Dependency bumps
17
- * Internal refactorings
18
-
19
- # v0.1.1 2013-05-15
20
-
21
- + Add Concord::Public mixin defaulting to public attr_readers
22
-
23
- # v0.1.0 2013-05-15
24
-
25
- * [change] Set default attribute visibility to protected
26
-
27
- # v0.0.3 2013-03-08
28
-
29
- * [fix] 1.9.2 visibility problem
30
-
31
- # v0.0.2 2013-03-07
32
-
33
- * [change] remove unneded backports dependency
34
-
35
- # v0.0.1 2013-03-06
36
-
37
- * First public release!
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'devtools', git: 'https://github.com/rom-rb/devtools.git', branch: 'master'
6
- eval_gemfile 'Gemfile.devtools'
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
-
3
- group :development do
4
- gem 'rake', '~> 10.2.1'
5
- gem 'rspec', '~> 2.14.1'
6
- gem 'rspec-core', '~> 2.14.8'
7
- gem 'yard', '~> 0.8.7.4'
8
-
9
- platform :rbx do
10
- gem 'rubysl-singleton', '~> 2.0.0'
11
- end
12
- end
13
-
14
- group :yard do
15
- gem 'kramdown', '~> 1.3.3'
16
- end
17
-
18
- group :guard do
19
- gem 'guard', '~> 2.6.0'
20
- gem 'guard-bundler', '~> 2.0.0'
21
- gem 'guard-rspec', '~> 4.2.8'
22
- gem 'guard-rubocop', '~> 1.0.2'
23
-
24
- # file system change event handling
25
- gem 'listen', '~> 2.7.1'
26
- gem 'rb-fchange', '~> 0.0.6', require: false
27
- gem 'rb-fsevent', '~> 0.9.4', require: false
28
- gem 'rb-inotify', '~> 0.9.3', require: false
29
-
30
- # notification handling
31
- gem 'libnotify', '~> 0.8.2', require: false
32
- gem 'rb-notifu', '~> 0.0.4', require: false
33
- gem 'terminal-notifier-guard', '~> 1.5.3', require: false
34
- end
35
-
36
- group :metrics do
37
- gem 'coveralls', '~> 0.7.0'
38
- gem 'flay', '~> 2.4.0'
39
- gem 'flog', '~> 4.2.0'
40
- gem 'reek', '~> 1.3.7'
41
- gem 'rubocop', '~> 0.19.1'
42
- gem 'simplecov', '~> 0.8.2'
43
- gem 'yardstick', '~> 0.9.9'
44
-
45
- platforms :mri do
46
- gem 'mutant', '~> 0.5.10'
47
- gem 'mutant-rspec', '~> 0.5.10'
48
- end
49
-
50
- platforms :ruby_19, :ruby_20 do
51
- gem 'yard-spellcheck', '~> 0.1.5'
52
- end
53
-
54
- platform :rbx do
55
- gem 'json', '~> 1.8.1'
56
- gem 'racc', '~> 1.4.11'
57
- gem 'rubysl-logger', '~> 2.0.0'
58
- gem 'rubysl-open-uri', '~> 2.0.0'
59
- gem 'rubysl-prettyprint', '~> 2.0.3'
60
- end
61
- end
62
-
63
- group :benchmarks do
64
- gem 'rbench', '~> 0.2.3'
65
- end
66
-
67
- platform :jruby do
68
- group :jruby do
69
- gem 'jruby-openssl', '~> 0.8.5'
70
- end
71
- end
data/Guardfile DELETED
@@ -1,8 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec' do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
- end
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2012 Markus Schirp
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 DELETED
@@ -1,86 +0,0 @@
1
- concord
2
- =======
3
-
4
- [![Build Status](https://secure.travis-ci.org/mbj/concord.png?branch=master)](http://travis-ci.org/mbj/concord)
5
- [![Dependency Status](https://gemnasium.com/mbj/concord.png)](https://gemnasium.com/mbj/concord)
6
- [![Code Climate](https://codeclimate.com/github/mbj/concord.png)](https://codeclimate.com/github/mbj/concord)
7
-
8
- Library to transform this:
9
-
10
- ```ruby
11
- class ComposedObject
12
- include Equalizer.new(:foo, :bar)
13
-
14
- # Return foo
15
- #
16
- # @return [Foo]
17
- #
18
- # @api private
19
- #
20
- attr_reader :foo
21
- protected :foo
22
-
23
- # Return bar
24
- #
25
- # @return [Bar]
26
- #
27
- # @api private
28
- #
29
- attr_reader :bar
30
- protected :bar
31
-
32
- # Initialize object
33
- #
34
- # @param [Foo] foo
35
- # @param [Bar] bar
36
- #
37
- # @return [undefined]
38
- #
39
- # @api private
40
- #
41
- def initialize(foo, bar)
42
- @foo, @bar = foo, bar
43
- end
44
- end
45
- ```
46
-
47
- Into shorter and easier to parse by eyes:
48
-
49
- ```ruby
50
- class ComposedObject
51
- include Concord.new(:foo, :bar)
52
- end
53
- ```
54
-
55
- Sure the replacement is missing YARD docs, but IMHO it is better.
56
-
57
- Rubies
58
- ------
59
-
60
- Tested under all >= 1.9 rubies.
61
-
62
- Installation
63
- ------------
64
-
65
- Install the gem `concord` via your prefered method.
66
-
67
- Credits
68
- -------
69
-
70
- * [mbj](https://github.com/mbj)
71
-
72
- Contributing
73
- -------------
74
-
75
- * Fork the project.
76
- * Make your feature addition or bug fix.
77
- * Add tests for it. This is important so I don't break it in a
78
- future version unintentionally.
79
- * Commit, do not mess with Rakefile or version
80
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
81
- * Send me a pull request. Bonus points for topic branches.
82
-
83
- License
84
- -------
85
-
86
- See LICENSE
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'devtools'
2
- Devtools.init_rake_tasks
3
-
4
- Rake.application.load_imports
5
- task('metrics:mutant').clear
6
-
7
- namespace :metrics do
8
- task :mutant => :coverage do
9
- $stderr.puts 'Concord is a dependency of mutant and zombification is currently defunkt :('
10
- end
11
- end
data/circle.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- test:
3
- override:
4
- - bundle exec rake ci
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'concord'
5
- s.version = '0.1.5'
6
- s.authors = ['Markus Schirp']
7
- s.email = ['mbj@schirp-dso.com']
8
- s.homepage = 'https://github.com/mbj/concord'
9
- s.summary = %q{Helper for object composition}
10
- s.license = 'MIT'
11
- s.description = s.summary
12
-
13
- s.files = `git ls-files`.split("\n")
14
- s.test_files = `git ls-files -- {spec}/*`.split("\n")
15
- s.executables = []
16
- s.require_paths = ['lib']
17
-
18
- s.required_ruby_version = '>= 1.9.3'
19
-
20
- s.add_dependency('adamantium', '~> 0.2.0')
21
- s.add_dependency('equalizer', '~> 0.0.9')
22
- end
@@ -1,3 +0,0 @@
1
- ---
2
- threshold: 3
3
- total_score: 18.0
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 25.5
@@ -1,3 +0,0 @@
1
- name: concord
2
- namespace: Concord
3
- strategy: --rspec-unit
@@ -1,92 +0,0 @@
1
- UncommunicativeParameterName:
2
- accept: []
3
- exclude: []
4
- enabled: true
5
- reject:
6
- - !ruby/regexp /^.$/
7
- - !ruby/regexp /[0-9]$/
8
- - !ruby/regexp /[A-Z]/
9
- TooManyMethods:
10
- max_methods: 14
11
- enabled: true
12
- exclude: []
13
- max_instance_variables: 4
14
- UncommunicativeMethodName:
15
- accept: []
16
- exclude: []
17
- enabled: true
18
- reject:
19
- - !ruby/regexp /^[a-z]$/
20
- - !ruby/regexp /[0-9]$/
21
- - !ruby/regexp /[A-Z]/
22
- LongParameterList:
23
- max_params: 2
24
- exclude: []
25
- enabled: true
26
- overrides: {}
27
- FeatureEnvy:
28
- exclude:
29
- - Concord#define_readers
30
- enabled: true
31
- ClassVariable:
32
- exclude: []
33
- enabled: true
34
- BooleanParameter:
35
- exclude: []
36
- enabled: true
37
- IrresponsibleModule:
38
- exclude: []
39
- enabled: true
40
- UncommunicativeModuleName:
41
- accept: []
42
- exclude: []
43
- enabled: true
44
- reject:
45
- - !ruby/regexp /^.$/
46
- - !ruby/regexp /[0-9]$/
47
- NestedIterators:
48
- ignore_iterators: []
49
- exclude:
50
- - Concord#define_initialize
51
- enabled: true
52
- max_allowed_nesting: 1
53
- TooManyStatements:
54
- max_statements: 7
55
- exclude:
56
- - Concord#define_initialize
57
- enabled: true
58
- DuplicateMethodCall:
59
- allow_calls: []
60
- exclude: []
61
- enabled: true
62
- max_calls: 1
63
- UtilityFunction:
64
- max_helper_calls: 0
65
- exclude: []
66
- enabled: true
67
- Attribute:
68
- exclude: []
69
- enabled: false
70
- UncommunicativeVariableName:
71
- accept: []
72
- exclude: []
73
- enabled: true
74
- reject:
75
- - !ruby/regexp /^.$/
76
- - !ruby/regexp /[0-9]$/
77
- - !ruby/regexp /[A-Z]/
78
- RepeatedConditional:
79
- enabled: true
80
- max_ifs: 1
81
- DataClump:
82
- exclude: []
83
- enabled: true
84
- max_copies: 0
85
- min_clump_size: 2
86
- ControlParameter:
87
- exclude: []
88
- enabled: true
89
- LongYieldList:
90
- max_params: 0
91
- exclude: []
92
- enabled: true
@@ -1,20 +0,0 @@
1
- ---
2
- AbcMetricMethodCheck:
3
- score: 25.1
4
- AssignmentInConditionalCheck: { }
5
- CaseMissingElseCheck: { }
6
- ClassLineCountCheck: { line_count: 317 }
7
- ClassNameCheck:
8
- pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
9
- ClassVariableCheck: { }
10
- CyclomaticComplexityBlockCheck: { complexity: 3 }
11
- CyclomaticComplexityMethodCheck: { complexity: 4 }
12
- EmptyRescueBodyCheck: { }
13
- ForLoopCheck: { }
14
- MethodLineCountCheck: { line_count: 14 }
15
- MethodNameCheck:
16
- pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/
17
- ModuleLineCountCheck: { line_count: 320 }
18
- ModuleNameCheck:
19
- pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/
20
- ParameterNumberCheck: { parameter_count: 3 }
@@ -1,82 +0,0 @@
1
- inherit_from: ../.rubocop.yml
2
-
3
- AllCops:
4
- Includes:
5
- - '**/*.rake'
6
- - 'Gemfile'
7
- - 'Gemfile.triage'
8
-
9
- # Avoid parameter lists longer than five parameters.
10
- ParameterLists:
11
- Max: 3
12
- CountKeywordArgs: true
13
-
14
- MethodLength:
15
- CountComments: false
16
- Max: 15
17
-
18
- # Avoid more than `Max` levels of nesting.
19
- BlockNesting:
20
- Max: 3
21
-
22
- # Align with the style guide.
23
- CollectionMethods:
24
- PreferredMethods:
25
- collect: 'map'
26
- inject: 'reduce'
27
- find: 'detect'
28
- find_all: 'select'
29
-
30
- # Limit line length
31
- LineLength:
32
- Max: 113 # TODO: lower to 79 once the rubocop branch in shared/Gemfile is removed
33
-
34
- ClassLength:
35
- Max: 204
36
-
37
- # Disabled because of indenting with private keyword in class bodies.
38
- IndentationWidth:
39
- Enabled: false
40
-
41
- # I like raise more
42
- SignalException:
43
- Enabled: false
44
-
45
- # False positive in unparser source
46
- OneLineConditional:
47
- Enabled: false
48
-
49
- Documentation:
50
- Enabled: false
51
-
52
- # Disable documentation checking until a class needs to be documented once
53
- Documentation:
54
- Enabled: false
55
-
56
- # Do not favor modifier if/unless usage when you have a single-line body
57
- IfUnlessModifier:
58
- Enabled: false
59
-
60
- # Allow case equality operator (in limited use within the specs)
61
- CaseEquality:
62
- Enabled: false
63
-
64
- # Constants do not always have to use SCREAMING_SNAKE_CASE
65
- ConstantName:
66
- Enabled: false
67
-
68
- # Not all trivial readers/writers can be defined with attr_* methods
69
- TrivialAccessors:
70
- Enabled: false
71
-
72
- # Do not prefer do/end over {} for multiline blocks
73
- Blocks:
74
- Enabled: false
75
-
76
- # I like to have an empty line before closing the currently opened body
77
- EmptyLinesAroundBody:
78
- Enabled: false
79
-
80
- # I like my style more
81
- AccessModifierIndentation:
82
- Enabled: false
@@ -1,2 +0,0 @@
1
- ---
2
- threshold: 100
@@ -1,3 +0,0 @@
1
- require 'devtools'
2
- require 'concord'
3
- Devtools.init_spec_helper
@@ -1,133 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Concord do
4
-
5
- let(:class_under_test) do
6
- Class.new do
7
- include Concord.new(:foo, :bar)
8
- end
9
- end
10
-
11
- let(:instance_a) { class_under_test.new(foo, bar) }
12
- let(:instance_b) { class_under_test.new(foo, bar) }
13
- let(:instance_c) { class_under_test.new(foo, double('Baz')) }
14
-
15
- let(:foo) { double('Foo') }
16
- let(:bar) { double('Bar') }
17
-
18
- context 'initializer lines' do
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 is callable via super' do
36
- class_under_test.class_eval do
37
- attr_reader :baz
38
- public :foo
39
- public :bar
40
-
41
- def initialize(foo, bar)
42
- @baz = foo + bar
43
- super(foo, bar)
44
- end
45
- end
46
-
47
- instance = class_under_test.new(1, 2)
48
- expect(instance.foo).to eql(1)
49
- expect(instance.bar).to eql(2)
50
- expect(instance.baz).to eql(3)
51
- end
52
-
53
- it 'creates an initializer that is callable via zsuper' do
54
- class_under_test.class_eval do
55
- attr_reader :baz
56
- public :foo
57
- public :bar
58
-
59
- def initialize(foo, bar)
60
- @baz = foo + bar
61
- super
62
- end
63
- end
64
-
65
- instance = class_under_test.new(1, 2)
66
- expect(instance.foo).to eql(1)
67
- expect(instance.bar).to eql(2)
68
- expect(instance.baz).to eql(3)
69
- end
70
-
71
- it 'creates an initializer that sets the instance variables' do
72
- instance = class_under_test.new(1, 2)
73
- expect(instance.instance_variable_get(:@foo)).to be(1)
74
- expect(instance.instance_variable_get(:@bar)).to be(2)
75
- end
76
- end
77
-
78
- context 'with no objects to compose' do
79
- it 'assigns no ivars' do
80
- instance = Class.new { include Concord.new }.new
81
- expect(instance.instance_variables).to be_empty
82
- end
83
- end
84
-
85
- context 'visibility' do
86
- it 'should set attribute readers to protected' do
87
- protected_methods = class_under_test.protected_instance_methods
88
- expect(protected_methods).to match_array([:foo, :bar])
89
- end
90
- end
91
-
92
- context 'attribute behavior' do
93
- subject { instance_a }
94
-
95
- specify { expect(subject.send(:foo)).to be(foo) }
96
- specify { expect(subject.send(:bar)).to be(bar) }
97
- end
98
-
99
- context 'equalization behavior' do
100
- specify 'composed objects are equalized on attributes' do
101
- expect(instance_a).to eql(instance_b)
102
- expect(instance_a.hash).to eql(instance_b.hash)
103
- expect(instance_a).to eql(instance_b)
104
- expect(instance_a).to_not be(instance_c)
105
- expect(instance_a).to_not eql(instance_c)
106
- end
107
- end
108
-
109
- context 'when composing too many objects' do
110
- specify 'it raises an error' do
111
- expect {
112
- Concord.new(:a, :b, :c, :d)
113
- }.to raise_error(RuntimeError, 'Composition of more than 3 objects is not allowed')
114
- expect {
115
- Concord.new(:a, :b, :c)
116
- }.to_not raise_error
117
- end
118
- end
119
-
120
- context Concord::Public do
121
- let(:class_under_test) do
122
- Class.new do
123
- include Concord::Public.new(:foo, :bar)
124
- end
125
- end
126
-
127
- it 'should create public attr readers' do
128
- object = class_under_test.new(:foo, :bar)
129
- expect(object.foo).to eql(:foo)
130
- expect(object.bar).to eql(:bar)
131
- end
132
- end
133
- end