adamantium 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +4 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +86 -0
  4. data/Gemfile +54 -0
  5. data/Guardfile +18 -0
  6. data/LICENSE +21 -0
  7. data/README.md +90 -0
  8. data/Rakefile +9 -0
  9. data/TODO +1 -0
  10. data/adamantium.gemspec +25 -0
  11. data/config/flay.yml +3 -0
  12. data/config/flog.yml +2 -0
  13. data/config/roodi.yml +18 -0
  14. data/config/site.reek +91 -0
  15. data/config/yardstick.yml +2 -0
  16. data/lib/adamantium.rb +249 -0
  17. data/lib/adamantium/version.rb +3 -0
  18. data/spec/rcov.opts +7 -0
  19. data/spec/shared/command_method_behavior.rb +7 -0
  20. data/spec/shared/each_method_behaviour.rb +15 -0
  21. data/spec/shared/hash_method_behavior.rb +17 -0
  22. data/spec/shared/idempotent_method_behavior.rb +7 -0
  23. data/spec/shared/invertible_method_behaviour.rb +9 -0
  24. data/spec/spec_helper.rb +11 -0
  25. data/spec/unit/adamantium/class_methods/freeze_object_spec.rb +57 -0
  26. data/spec/unit/adamantium/class_methods/new_spec.rb +14 -0
  27. data/spec/unit/adamantium/dup_spec.rb +13 -0
  28. data/spec/unit/adamantium/fixtures/classes.rb +28 -0
  29. data/spec/unit/adamantium/freeze_spec.rb +51 -0
  30. data/spec/unit/adamantium/memoize_spec.rb +57 -0
  31. data/spec/unit/adamantium/memoized_spec.rb +29 -0
  32. data/spec/unit/adamantium/module_methods/included_spec.rb +16 -0
  33. data/spec/unit/adamantium/module_methods/memoize_spec.rb +88 -0
  34. data/tasks/metrics/ci.rake +7 -0
  35. data/tasks/metrics/flay.rake +47 -0
  36. data/tasks/metrics/flog.rake +43 -0
  37. data/tasks/metrics/heckle.rake +208 -0
  38. data/tasks/metrics/metric_fu.rake +29 -0
  39. data/tasks/metrics/reek.rake +15 -0
  40. data/tasks/metrics/roodi.rake +15 -0
  41. data/tasks/metrics/yardstick.rake +23 -0
  42. data/tasks/spec.rake +45 -0
  43. data/tasks/yard.rake +9 -0
  44. metadata +174 -0
@@ -0,0 +1,4 @@
1
+ /Gemfile.lock
2
+ /coverage
3
+ /tmp
4
+ /.rbx
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use @$(basename `pwd`) --create
@@ -0,0 +1,86 @@
1
+ language: ruby
2
+ script: "bundle exec rake spec"
3
+ rvm:
4
+ - ree
5
+ - 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - ruby-head
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ - jruby-18mode
12
+ - jruby-19mode
13
+ - jruby-head
14
+ jdk:
15
+ - openjdk6
16
+ - openjdk7
17
+ - oraclejdk7
18
+ matrix:
19
+ exclude:
20
+ # remove ree from jdk matrix
21
+ - rvm: ree
22
+ jdk: openjdk6
23
+ - rvm: ree
24
+ jdk: openjdk7
25
+ - rvm: ree
26
+ jdk: oraclejdk7
27
+
28
+ # remove 1.8.7 from jdk matrix
29
+ - rvm: 1.8.7
30
+ jdk: openjdk6
31
+ - rvm: 1.8.7
32
+ jdk: openjdk7
33
+ - rvm: 1.8.7
34
+ jdk: oraclejdk7
35
+
36
+ # remove 1.9.2 from jdk matrix
37
+ - rvm: 1.9.2
38
+ jdk: openjdk6
39
+ - rvm: 1.9.2
40
+ jdk: openjdk7
41
+ - rvm: 1.9.2
42
+ jdk: oraclejdk7
43
+
44
+ # remove 1.9.3 from jdk matrix
45
+ - rvm: 1.9.3
46
+ jdk: openjdk6
47
+ - rvm: 1.9.3
48
+ jdk: openjdk7
49
+ - rvm: 1.9.3
50
+ jdk: oraclejdk7
51
+
52
+ # remove ruby-head from jdk matrix
53
+ - rvm: ruby-head
54
+ jdk: openjdk6
55
+ - rvm: ruby-head
56
+ jdk: openjdk7
57
+ - rvm: ruby-head
58
+ jdk: oraclejdk7
59
+
60
+ # remove rbx-18mode from jdk matrix
61
+ - rvm: rbx-18mode
62
+ jdk: openjdk6
63
+ - rvm: rbx-18mode
64
+ jdk: openjdk7
65
+ - rvm: rbx-18mode
66
+ jdk: oraclejdk7
67
+
68
+ # remove rbx-19mode from jdk matrix
69
+ - rvm: rbx-19mode
70
+ jdk: openjdk6
71
+ - rvm: rbx-19mode
72
+ jdk: openjdk7
73
+ - rvm: rbx-19mode
74
+ jdk: oraclejdk7
75
+
76
+ # remove jruby-18mode, jruby-19mode and jruby-head from non-jdk matrix
77
+ - rvm: jruby-18mode
78
+ jdk:
79
+ - rvm: jruby-19mode
80
+ jdk:
81
+ - rvm: jruby-head
82
+ jdk:
83
+ notifications:
84
+ email:
85
+ - dan.kubb@gmail.com
86
+ - mbj@seonic.net
data/Gemfile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'backports', '~> 2.6.1'
6
+ gem 'ice_nine', '~> 0.4.0'
7
+
8
+ group :development do
9
+ gem 'jeweler', '~> 1.8.3'
10
+ gem 'rake', '~> 0.9.2'
11
+ gem 'rspec', '~> 1.3.2'
12
+ gem 'yard', '~> 0.8.1'
13
+ end
14
+
15
+ group :guard do
16
+ gem 'guard', '~> 1.1.1'
17
+ gem 'guard-bundler', '~> 0.1.3'
18
+ gem 'guard-rspec', '~> 0.7.3'
19
+ end
20
+
21
+ group :benchmarks do
22
+ gem 'rbench', '~> 0.2.3'
23
+ end
24
+
25
+ platform :jruby do
26
+ group :jruby do
27
+ gem 'jruby-openssl', '~> 0.7.4'
28
+ end
29
+ end
30
+
31
+ group :metrics do
32
+ gem 'flay', '~> 1.4.2'
33
+ gem 'flog', '~> 2.5.1'
34
+ gem 'reek', '~> 1.2.8', :github => 'dkubb/reek'
35
+ gem 'roodi', '~> 2.1.0'
36
+ gem 'yardstick', '~> 0.5.0'
37
+ gem 'yard-spellcheck', '~> 0.1.5'
38
+
39
+ platforms :mri_18 do
40
+ gem 'arrayfields', '~> 4.7.4' # for metric_fu
41
+ gem 'fattr', '~> 2.2.0' # for metric_fu
42
+ gem 'heckle', '~> 1.4.3'
43
+ gem 'json', '~> 1.7.3' # for metric_fu rake task
44
+ gem 'map', '~> 6.0.1' # for metric_fu
45
+ gem 'metric_fu', '~> 2.1.1'
46
+ gem 'mspec', '~> 1.5.17'
47
+ gem 'rcov', '~> 1.0.0'
48
+ gem 'ruby2ruby', '= 1.2.2' # for heckle
49
+ end
50
+
51
+ platforms :rbx do
52
+ gem 'pelusa', '~> 0.2.1'
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ guard :bundler do
4
+ watch('Gemfile')
5
+ end
6
+
7
+ guard :rspec 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2009-2012 Dan Kubb
2
+ Copyright (c) 2012 Markus Schirp (packaging)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,90 @@
1
+ adamantium
2
+ ==========
3
+
4
+ [![Build Status](https://secure.travis-ci.org/dkubb/adamantium.png)](http://travis-ci.org/dkubb/adamantium)
5
+ [![Dependency Status](https://gemnasium.com/dkubb/adamantium.png)](https://gemnasium.com/dkubb/adamantium)
6
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/dkubb/adamantium)
7
+
8
+ This is a small standalone gem featuring a module ripped out from [veritas](https://github.com/dkubb/veritas).
9
+ It allows to make objects immutable in an unobtrusive way.
10
+
11
+ Installation
12
+ ------------
13
+
14
+ There is no gem release yet so use git source.
15
+
16
+ In your **Gemfile**:
17
+
18
+ ``` ruby
19
+ gem 'adamantium', :git => 'https://github.com/dkubb/adamantium.git'
20
+ ```
21
+
22
+ Examples
23
+ --------
24
+
25
+ ``` ruby
26
+ require 'adamantium'
27
+ require 'securerandom'
28
+
29
+ class Foo
30
+ include Adamantium
31
+
32
+ def bar
33
+ SecureRandom.hex(6)
34
+ end
35
+
36
+ memoize :bar
37
+ end
38
+
39
+ object = Foo.new
40
+ object.bar # => "abcdef"
41
+ # Value is memoized
42
+ object.bar # => "abcdef"
43
+ # Returns the same object on all calls
44
+ object.bar.equal?(object.bar) # => true
45
+ # Object is frozen
46
+ object.frozen? # => true
47
+ ```
48
+
49
+ Credits
50
+ -------
51
+
52
+ * Dan Kubb ([dkubb](https://github.com/dkubb))
53
+ * Markus Schirp ([mbj](https://github.com/mbj))
54
+
55
+ Contributing
56
+ -------------
57
+
58
+ * If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. This library is still in early development, and the direction it is going may not always be clear. Some features may not be appropriate yet, may need to be deferred until later when the foundation for them is laid, or may be more applicable in a plugin.
59
+ * Fork the project.
60
+ * Make your feature addition or bug fix.
61
+ * Follow this [style guide](https://github.com/dkubb/styleguide).
62
+ * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
63
+ * Commit, do not mess with Rakefile, version, or history. (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)
64
+ * Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged.
65
+ * Send me a pull request. Bonus points for topic branches.
66
+
67
+ License
68
+ -------
69
+
70
+ Copyright (c) 2009-2012 Dan Kubb
71
+ Copyright (c) 2012 Markus Schirp (packaging)
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining
74
+ a copy of this software and associated documentation files (the
75
+ "Software"), to deal in the Software without restriction, including
76
+ without limitation the rights to use, copy, modify, merge, publish,
77
+ distribute, sublicense, and/or sell copies of the Software, and to
78
+ permit persons to whom the Software is furnished to do so, subject to
79
+ the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
83
+
84
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
87
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
88
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
89
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
90
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake'
4
+
5
+ require File.expand_path('../lib/adamantium/version', __FILE__)
6
+
7
+ FileList['tasks/**/*.rake'].each { |task| import task }
8
+
9
+ task :default => :spec
data/TODO ADDED
@@ -0,0 +1 @@
1
+ * Make a gem release after review from original author (dkubb).
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/adamantium/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'adamantium'
7
+ gem.version = Adamantium::VERSION.dup
8
+ gem.authors = [ 'Dan Kubb', 'Markus Schirp' ]
9
+ gem.email = [ 'dan.kubb@gmail.com', 'mbj@seonic.net' ]
10
+ gem.description = 'Immutable extensions to objects'
11
+ gem.summary = gem.description
12
+ gem.homepage = 'https://github.com/dkubb/adamantium'
13
+
14
+ gem.require_paths = [ 'lib' ]
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
17
+ gem.extra_rdoc_files = %w[LICENSE README.md TODO]
18
+
19
+ gem.add_runtime_dependency('backports', '~> 2.6.1')
20
+ gem.add_runtime_dependency('ice_nine', '~> 0.4.0')
21
+
22
+ gem.add_development_dependency('rake', '~> 0.9.2')
23
+ gem.add_development_dependency('rspec', '~> 1.3.2')
24
+ gem.add_development_dependency('yard', '~> 0.8.1')
25
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 9
3
+ total_score: 29
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 21.9
@@ -0,0 +1,18 @@
1
+ ---
2
+ AbcMetricMethodCheck: { score: 10.3 }
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 }
@@ -0,0 +1,91 @@
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
+ LargeClass:
11
+ max_methods: 10
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
+ enabled: true
27
+ overrides: {}
28
+ FeatureEnvy:
29
+ exclude: []
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
+ enabled: true
51
+ max_allowed_nesting: 1
52
+ LongMethod:
53
+ max_statements: 7 # TODO: decrease max_statements to 5 or less
54
+ exclude: []
55
+ enabled: true
56
+ Duplication:
57
+ allow_calls: []
58
+ exclude: []
59
+ enabled: true
60
+ max_calls: 1
61
+ UtilityFunction:
62
+ max_helper_calls: 1
63
+ exclude: []
64
+ enabled: true
65
+ Attribute:
66
+ exclude: []
67
+ enabled: false
68
+ UncommunicativeVariableName:
69
+ accept: []
70
+ exclude: []
71
+ enabled: true
72
+ reject:
73
+ - !ruby/regexp /^.$/
74
+ - !ruby/regexp /[0-9]$/
75
+ - !ruby/regexp /[A-Z]/
76
+ SimulatedPolymorphism:
77
+ exclude: []
78
+ enabled: true
79
+ max_ifs: 1
80
+ DataClump:
81
+ exclude: []
82
+ enabled: true
83
+ max_copies: 1
84
+ min_clump_size: 3
85
+ ControlCouple:
86
+ exclude: []
87
+ enabled: true
88
+ LongYieldList:
89
+ max_params: 1
90
+ exclude: []
91
+ enabled: true
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100