anima 0.3.0 → 0.3.1

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: 4d3d1052ef69a252eba9f680d8918977ebe21957
4
- data.tar.gz: 95726462b39f8b85f7706c5415369eb0e141e48d
2
+ SHA256:
3
+ metadata.gz: e28b3bf5fb2361a433db0d65938c2a5880921fcffd122e56da5e2a81d4c3bcbd
4
+ data.tar.gz: 4966ec506c17918b5c2d05ca6c4f41cf02b8227bb18c50dc41edbbce0b098bb4
5
5
  SHA512:
6
- metadata.gz: 320e39521765b3c969063d635b90c3fc51927b2ac9f1fb46e4c13b02f56a539fb3bf1d57fd8f05742a7fe2b83143c0b3d91c3b3e037a4b142cb3341c7907f9cb
7
- data.tar.gz: 73e0f2c5c9dc9901dc0c0ce04b899a3c23c5587ff144794b303e53eff9da2bc13d09ca99ea43ff9600805cc8f3ff58c991ebfe66b1eeb9cf8e9c9a796630e29f
6
+ metadata.gz: afcb05d47ba54ade5f45f889221fba44c64864d60021e74471a5b4f13c760d379295487a3f7165bfcf08272424be9f7daac49773908657823fe4fd427c5f0e29
7
+ data.tar.gz: b884903b68754c6f1afbc64ab2df7baab2c74db82462ed46ed54fd2c4b00db11b6ef418617691a78c490ce00642d58f7ed806b8750ceb495c547f08d4a03cc58
@@ -0,0 +1,32 @@
1
+ defaults: &defaults
2
+ working_directory: ~/anima
3
+ docker:
4
+ - image: circleci/ruby:2.6.0
5
+ version: 2
6
+ jobs:
7
+ unit_specs:
8
+ <<: *defaults
9
+ steps:
10
+ - checkout
11
+ - run: bundle install
12
+ - run: bundle exec rspec spec/unit
13
+ metrics:
14
+ <<: *defaults
15
+ steps:
16
+ - checkout
17
+ - run: bundle install
18
+ - run: bundle exec rake metrics:rubocop
19
+ - run: bundle exec rake metrics:reek
20
+ mutant:
21
+ <<: *defaults
22
+ steps:
23
+ - checkout
24
+ - run: bundle install
25
+ - run: bundle exec rake metrics:mutant
26
+ workflows:
27
+ version: 2
28
+ test:
29
+ jobs:
30
+ - unit_specs
31
+ - metrics
32
+ - mutant
@@ -1,4 +1,8 @@
1
- # v0.3.0 2015-xx-xx
1
+ # v0.3.1 2018-02-15
2
+
3
+ * Fix falsy key match detection
4
+
5
+ # v0.3.0 2015-09-04
2
6
 
3
7
  Changes:
4
8
 
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem 'devtools', git: 'https://github.com/rom-rb/devtools.git'
6
- gem 'mutant', git: 'https://github.com/mbj/mutant.git',
7
- branch: 'fix/anima-update'
8
- gem 'morpher', git: 'https://github.com/mbj/morpher.git',
9
- branch: 'fix/upgrade-anima'
@@ -1,8 +1,6 @@
1
- # encoding: utf-8
2
-
3
1
  Gem::Specification.new do |s|
4
2
  s.name = 'anima'
5
- s.version = '0.3.0'
3
+ s.version = '0.3.1'
6
4
 
7
5
  s.authors = ['Markus Schirp']
8
6
  s.email = 'mbj@schirp-dso.com'
@@ -20,4 +18,6 @@ Gem::Specification.new do |s|
20
18
  s.add_dependency('adamantium', '~> 0.2')
21
19
  s.add_dependency('equalizer', '~> 0.0.11')
22
20
  s.add_dependency('abstract_type', '~> 0.0.7')
21
+
22
+ s.add_development_dependency('devtools', '~> 0.1.23')
23
23
  end
@@ -1,100 +1,98 @@
1
1
  ---
2
- UncommunicativeParameterName:
3
- accept: []
4
- exclude: []
5
- enabled: true
6
- reject:
7
- - !ruby/regexp /^.$/
8
- - !ruby/regexp /[0-9]$/
9
- - !ruby/regexp /[A-Z]/
10
- TooManyMethods:
11
- max_methods: 9
12
- exclude: []
13
- enabled: true
14
- max_instance_variables: 2
15
- UncommunicativeMethodName:
16
- accept: []
17
- exclude: []
18
- enabled: true
19
- reject:
20
- - !ruby/regexp /^[a-z]$/
21
- - !ruby/regexp /[0-9]$/
22
- - !ruby/regexp /[A-Z]/
23
- LongParameterList:
24
- max_params: 2 # TODO: decrease max_params to 2
25
- exclude:
26
- - Anima::Error#initialize # 3 params
27
- enabled: true
28
- overrides: {}
29
- FeatureEnvy:
30
- exclude:
31
- - Anima#attributes_hash
32
- enabled: true
33
- ClassVariable:
34
- exclude: []
35
- enabled: true
36
- BooleanParameter:
37
- exclude: []
38
- enabled: true
39
- # Buggy like hell
40
- IrresponsibleModule:
41
- exclude: []
42
- enabled: false
43
- UncommunicativeModuleName:
44
- accept: []
45
- exclude: []
46
- enabled: true
47
- reject:
48
- - !ruby/regexp /^.$/
49
- - !ruby/regexp /[0-9]$/
50
- NestedIterators:
51
- ignore_iterators: []
52
- exclude:
53
- - Anima::Attribute#define_reader # 2 levels
54
- - Anima#included # 2 levels
55
- enabled: true
56
- max_allowed_nesting: 1
57
- TooManyStatements:
58
- max_statements: 7 # TODO: decrease max_statements to 5 or less
59
- exclude: []
60
- enabled: true
61
- DuplicateMethodCall:
62
- allow_calls: []
63
- exclude: []
64
- enabled: true
65
- max_calls: 1
66
- UtilityFunction:
67
- max_helper_calls: 1
68
- exclude:
69
- - Anima::Error#initialize # false positive, calls super
70
- enabled: true
71
- Attribute:
72
- exclude: []
73
- enabled: false
74
- UncommunicativeVariableName:
75
- accept: []
76
- exclude: []
77
- enabled: true
78
- reject:
79
- - !ruby/regexp /^.$/
80
- - !ruby/regexp /[0-9]$/
81
- - !ruby/regexp /[A-Z]/
82
- RepeatedConditional:
83
- exclude: []
84
- enabled: true
85
- max_ifs: 1
86
- DataClump:
87
- exclude: []
88
- enabled: true
89
- max_copies: 1
90
- min_clump_size: 3
91
- ControlParameter:
92
- exclude: []
93
- enabled: true
94
- LongYieldList:
95
- max_params: 1
96
- exclude: []
97
- enabled: true
98
- # Thats the whole point of this lib, oOo.
99
- ModuleInitialize:
100
- enabled: false
2
+ detectors:
3
+ UncommunicativeParameterName:
4
+ accept: []
5
+ exclude: []
6
+ enabled: true
7
+ reject:
8
+ - '/^.$/'
9
+ - '/[0-9]$/'
10
+ - '/[A-Z]/'
11
+ TooManyMethods:
12
+ max_methods: 9
13
+ exclude: []
14
+ enabled: true
15
+ UncommunicativeMethodName:
16
+ accept: []
17
+ exclude: []
18
+ enabled: true
19
+ reject:
20
+ - '/^[a-z]$/'
21
+ - '/[0-9]$/'
22
+ - '/[A-Z]/'
23
+ LongParameterList:
24
+ max_params: 2 # TODO: decrease max_params to 2
25
+ exclude:
26
+ - Anima::Error#initialize # 3 params
27
+ enabled: true
28
+ overrides: {}
29
+ FeatureEnvy:
30
+ exclude:
31
+ - Anima#attributes_hash
32
+ enabled: true
33
+ ClassVariable:
34
+ exclude: []
35
+ enabled: true
36
+ BooleanParameter:
37
+ exclude: []
38
+ enabled: true
39
+ # Buggy like hell
40
+ IrresponsibleModule:
41
+ exclude: []
42
+ enabled: false
43
+ UncommunicativeModuleName:
44
+ accept: []
45
+ exclude: []
46
+ enabled: true
47
+ reject:
48
+ - '/^.$/'
49
+ - '/[0-9]$/'
50
+ NestedIterators:
51
+ ignore_iterators: []
52
+ exclude:
53
+ - Anima::Attribute#define_reader # 2 levels
54
+ - Anima#included # 2 levels
55
+ enabled: true
56
+ max_allowed_nesting: 1
57
+ TooManyStatements:
58
+ max_statements: 7 # TODO: decrease max_statements to 5 or less
59
+ exclude: []
60
+ enabled: true
61
+ DuplicateMethodCall:
62
+ allow_calls: []
63
+ exclude: []
64
+ enabled: true
65
+ max_calls: 1
66
+ UtilityFunction:
67
+ exclude: []
68
+ enabled: true
69
+ Attribute:
70
+ exclude: []
71
+ enabled: false
72
+ UncommunicativeVariableName:
73
+ accept: []
74
+ exclude: []
75
+ enabled: true
76
+ reject:
77
+ - '/^.$/'
78
+ - '/[0-9]$/'
79
+ - '/[A-Z]/'
80
+ RepeatedConditional:
81
+ exclude: []
82
+ enabled: true
83
+ max_ifs: 1
84
+ DataClump:
85
+ exclude: []
86
+ enabled: true
87
+ max_copies: 1
88
+ min_clump_size: 3
89
+ ControlParameter:
90
+ exclude: []
91
+ enabled: true
92
+ LongYieldList:
93
+ max_params: 1
94
+ exclude: []
95
+ enabled: true
96
+ # Thats the whole point of this lib, oOo.
97
+ ModuleInitialize:
98
+ enabled: false
@@ -96,7 +96,7 @@ SymbolArray:
96
96
 
97
97
  # Align if/else blocks with the variable assignment
98
98
  EndAlignment:
99
- AlignWith: variable
99
+ EnforcedStyleAlignWith: variable
100
100
 
101
101
  # Do not always align parameters when it is easier to read
102
102
  AlignParameters:
@@ -1,27 +1,20 @@
1
- # encoding: utf-8
2
-
3
1
  require 'adamantium'
4
2
  require 'equalizer'
5
3
  require 'abstract_type'
6
4
 
7
5
  # Main library namespace and mixin
6
+ # @api private
8
7
  class Anima < Module
9
8
  include Adamantium::Flat, Equalizer.new(:attributes)
10
9
 
11
10
  # Return names
12
11
  #
13
12
  # @return [AttributeSet]
14
- #
15
- # @api private
16
- #
17
13
  attr_reader :attributes
18
14
 
19
15
  # Initialize object
20
16
  #
21
17
  # @return [undefined]
22
- #
23
- # @api private
24
- #
25
18
  def initialize(*names)
26
19
  @attributes = names.uniq.map(&Attribute.method(:new)).freeze
27
20
  end
@@ -34,8 +27,6 @@ class Anima < Module
34
27
  # anima = Anima.new(:foo)
35
28
  # anima.add(:bar) # equals Anima.new(:foo, :bar)
36
29
  #
37
- # @api private
38
- #
39
30
  def add(*names)
40
31
  new(attribute_names + names)
41
32
  end
@@ -48,8 +39,6 @@ class Anima < Module
48
39
  # anima = Anima.new(:foo, :bar)
49
40
  # anima.remove(:bar) # equals Anima.new(:foo)
50
41
  #
51
- # @api public
52
- #
53
42
  def remove(*names)
54
43
  new(attribute_names - names)
55
44
  end
@@ -59,9 +48,6 @@ class Anima < Module
59
48
  # @param [Object] object
60
49
  #
61
50
  # @return [Hash]
62
- #
63
- # @api private
64
- #
65
51
  def attributes_hash(object)
66
52
  attributes.each_with_object({}) do |attribute, attributes_hash|
67
53
  attributes_hash[attribute.name] = attribute.get(object)
@@ -71,9 +57,6 @@ class Anima < Module
71
57
  # Return attribute names
72
58
  #
73
59
  # @return [Enumerable<Symbol>]
74
- #
75
- # @api private
76
- #
77
60
  def attribute_names
78
61
  attributes.map(&:name)
79
62
  end
@@ -86,9 +69,6 @@ class Anima < Module
86
69
  # @param [Hash] attribute_hash
87
70
  #
88
71
  # @return [self]
89
- #
90
- # @api private
91
- #
92
72
  def initialize_instance(object, attribute_hash)
93
73
  assert_known_attributes(object.class, attribute_hash)
94
74
  attributes.each do |attribute|
@@ -105,14 +85,15 @@ class Anima < Module
105
85
  # a hash that matches anima defined attributes
106
86
  #
107
87
  # @return [undefined]
108
- #
109
- # @api public
110
88
  def initialize(attributes)
111
89
  self.class.anima.initialize_instance(self, attributes)
112
90
  end
113
91
 
114
92
  # Return a hash representation of an anima infected object
115
93
  #
94
+ # @example
95
+ # anima.to_h # => { :foo => : bar }
96
+ #
116
97
  # @return [Hash]
117
98
  #
118
99
  # @api public
@@ -136,8 +117,7 @@ class Anima < Module
136
117
  #
137
118
  # @return [Anima]
138
119
  #
139
- # @api private
140
- #
120
+ # @api public
141
121
  def with(attributes)
142
122
  self.class.new(to_h.update(attributes))
143
123
  end
@@ -150,9 +130,6 @@ class Anima < Module
150
130
  # @param [Class, Module] scope
151
131
  #
152
132
  # @return [undefined]
153
- #
154
- # @api private
155
- #
156
133
  def included(descendant)
157
134
  descendant.instance_exec(self, attribute_names) do |anima, names|
158
135
  # Define anima method
@@ -180,15 +157,15 @@ class Anima < Module
180
157
  # @return [undefined]
181
158
  #
182
159
  # @raise [Error]
183
- #
184
- # @api private
185
160
  def assert_known_attributes(klass, attribute_hash)
186
161
  keys = attribute_hash.keys
187
162
 
188
163
  unknown = keys - attribute_names
189
164
  missing = attribute_names - keys
190
165
 
191
- fail Error.new(klass, missing, unknown) if unknown.any? || missing.any?
166
+ unless unknown.empty? && missing.empty?
167
+ fail Error.new(klass, missing, unknown)
168
+ end
192
169
  end
193
170
 
194
171
  # Return new instance
@@ -196,9 +173,6 @@ class Anima < Module
196
173
  # @param [Enumerable<Symbol>] attributes
197
174
  #
198
175
  # @return [Anima]
199
- #
200
- # @api private
201
- #
202
176
  def new(attributes)
203
177
  self.class.new(*attributes)
204
178
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  class Anima
4
2
  # An attribute
5
3
  class Attribute
@@ -8,9 +6,6 @@ class Anima
8
6
  # Initialize attribute
9
7
  #
10
8
  # @param [Symbol] name
11
- #
12
- # @api private
13
- #
14
9
  def initialize(name)
15
10
  @name, @instance_variable_name = name, :"@#{name}"
16
11
  end
@@ -18,17 +13,11 @@ class Anima
18
13
  # Return attribute name
19
14
  #
20
15
  # @return [Symbol]
21
- #
22
- # @api private
23
- #
24
16
  attr_reader :name
25
17
 
26
18
  # Return instance variable name
27
19
  #
28
20
  # @return [Symbol]
29
- #
30
- # @api private
31
- #
32
21
  attr_reader :instance_variable_name
33
22
 
34
23
  # Load attribute
@@ -37,9 +26,6 @@ class Anima
37
26
  # @param [Hash] attributes
38
27
  #
39
28
  # @return [self]
40
- #
41
- # @api private
42
- #
43
29
  def load(object, attributes)
44
30
  set(object, attributes.fetch(name))
45
31
  end
@@ -49,9 +35,6 @@ class Anima
49
35
  # @param [Object] object
50
36
  #
51
37
  # @return [Object]
52
- #
53
- # @api private
54
- #
55
38
  def get(object)
56
39
  object.public_send(name)
57
40
  end
@@ -62,9 +45,6 @@ class Anima
62
45
  # @param [Object] value
63
46
  #
64
47
  # @return [self]
65
- #
66
- # @api private
67
- #
68
48
  def set(object, value)
69
49
  object.instance_variable_set(instance_variable_name, value)
70
50
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  class Anima
4
2
  # Abstract base class for anima errors
5
3
  class Error < RuntimeError
@@ -14,9 +12,6 @@ class Anima
14
12
  # @param [Enumerable<Symbol>] unknown
15
13
  #
16
14
  # @return [undefined]
17
- #
18
- # @api private
19
- #
20
15
  def initialize(klass, missing, unknown)
21
16
  super(FORMAT % [klass, missing, unknown])
22
17
  end
@@ -1,7 +1,3 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
1
  class TestClass
6
2
  include Anima.new(:firstname, :lastname)
7
3
  end
@@ -1,5 +1,2 @@
1
- # encoding: utf-8
2
-
3
1
  require 'anima'
4
- require 'devtools'
5
- Devtools.init_spec_helper
2
+ require 'devtools/spec_helper'
@@ -1,7 +1,3 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe Anima::Attribute do
6
2
  let(:object) { described_class.new(:foo) }
7
3
 
@@ -1,7 +1,3 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe Anima::Error do
6
2
  describe '#message' do
7
3
  let(:object) { described_class.new(Anima, missing, unknown) }
@@ -1,7 +1,3 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe Anima do
6
2
  let(:object) { described_class.new(:foo) }
7
3
 
@@ -132,6 +128,17 @@ describe Anima do
132
128
  Anima::Error.new(target.class, [], [:baz]).message
133
129
  )
134
130
  end
131
+
132
+ context 'and the extra key is falsy' do
133
+ let(:attribute_hash) { { foo: foo, bar: bar, nil => double('Baz') } }
134
+
135
+ it 'should raise error' do
136
+ expect { subject }.to raise_error(
137
+ Anima::Error,
138
+ Anima::Error.new(target.class, [], [nil]).message
139
+ )
140
+ end
141
+ end
135
142
  end
136
143
 
137
144
  context 'when a key is missing in attribute hash' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anima
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-04 00:00:00.000000000 Z
11
+ date: 2019-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adamantium
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.0.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: devtools
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.23
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.23
55
69
  description:
56
70
  email: mbj@schirp-dso.com
57
71
  executables: []
@@ -59,23 +73,20 @@ extensions: []
59
73
  extra_rdoc_files:
60
74
  - README.md
61
75
  files:
76
+ - ".circleci/config.yml"
62
77
  - ".gitignore"
63
78
  - ".rspec"
64
79
  - ".rubocop.yml"
65
80
  - ".travis.yml"
66
81
  - Changelog.md
67
82
  - Gemfile
68
- - Guardfile
69
83
  - README.md
70
84
  - Rakefile
71
- - TODO
72
85
  - anima.gemspec
73
- - circle.yml
74
86
  - config/flay.yml
75
87
  - config/flog.yml
76
88
  - config/mutant.yml
77
89
  - config/reek.yml
78
- - config/roodi.yml
79
90
  - config/rubocop.yml
80
91
  - config/yardstick.yml
81
92
  - lib/anima.rb
@@ -105,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
116
  - !ruby/object:Gem::Version
106
117
  version: '0'
107
118
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.4.5.1
119
+ rubygems_version: 3.0.1
110
120
  signing_key:
111
121
  specification_version: 4
112
122
  summary: Initialize object attributes via attributes hash
@@ -116,4 +126,3 @@ test_files:
116
126
  - spec/unit/anima/attribute_spec.rb
117
127
  - spec/unit/anima/error_spec.rb
118
128
  - spec/unit/anima_spec.rb
119
- has_rdoc:
data/Guardfile DELETED
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
-
3
- guard :bundler do
4
- watch('Gemfile')
5
- end
6
-
7
- guard :rspec, :version => 2 do
8
- # run all specs if the spec_helper or supporting files files are modified
9
- watch('spec/spec_helper.rb') { 'spec' }
10
- watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
11
-
12
- # run unit specs if associated lib code is modified
13
- watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
14
- watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
15
-
16
- # run a spec if it is modified
17
- watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
18
- end
data/TODO DELETED
@@ -1,3 +0,0 @@
1
- * Use module subclass trick to improve expressiveness of Attribute / AttributeSet / ClassMethod
2
- * Add ability to freeze attribute_set via dsl
3
- * Add full unit spec coverage
data/circle.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- machine:
3
- ruby:
4
- version: '2.2'
5
- test:
6
- override:
7
- - bundle exec rake ci
@@ -1,18 +0,0 @@
1
- ---
2
- AbcMetricMethodCheck: { score: 11.0 }
3
- AssignmentInConditionalCheck: { }
4
- CaseMissingElseCheck: { }
5
- ClassLineCountCheck: { line_count: 293 }
6
- ClassNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
7
- ClassVariableCheck: { }
8
- CyclomaticComplexityBlockCheck: { complexity: 2 }
9
- CyclomaticComplexityMethodCheck: { complexity: 4 }
10
- EmptyRescueBodyCheck: { }
11
- ForLoopCheck: { }
12
- # TODO: decrease line_count to 5 to 10
13
- MethodLineCountCheck: { line_count: 14 }
14
- MethodNameCheck: { pattern: !ruby/regexp '/\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/' }
15
- ModuleLineCountCheck: { line_count: 295 }
16
- ModuleNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
17
- # TODO: decrease parameter_count to 2 or less
18
- ParameterNumberCheck: { parameter_count: 3 }