hash-keyable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hash-keyable might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4fded2e1b3d3ddfa2405d398d7ebd4e03bbf57f15b681728c330117a192548aa
4
+ data.tar.gz: 41dd31099788a2ef45a2c6266ccb766084868ec827609fb384df7b47f0b4c53c
5
+ SHA512:
6
+ metadata.gz: 7d4df04a1f46430f558c1498f47479eb119205898e31b18ffcae7de8ba76a5c5858524ae26eeb87597ce823c1dae06830f468e2614f3ce1210b5dbac93802709
7
+ data.tar.gz: 94eb6d6a014efd60dbfc3ca2284b53cc66b5c6ca38a9c2d055395062d3fdd0c43eeaad3376f9bdf597e95dc2a3ab7430bbab5406d2d617e58cf2f0bb84e2e6f7
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ .redcar
30
+
31
+ # other
32
+ *.lock
33
+ *.bak
34
+ tool/
35
+ *\#*
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.6
6
+ - 2.5
7
+ - rbx-3
8
+ - jruby-head
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: rbx-3
14
+ - rvm: jruby-head
15
+
16
+ before_install:
17
+ - gem install bundler
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --readme README.md --protected --private lib/**/*.rb - MIT-LICENSE
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # coding: us-ascii
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rake'
13
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X11 License)
2
+
3
+ Copyright (c) 2012 Kenichi Kamiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ hash-keyable
2
+ =============
3
+
4
+ [![Build Status](https://secure.travis-ci.org/kachick/hash-keyable.png)](http://travis-ci.org/kachick/hash-keyable)
5
+ [![Gem Version](https://badge.fury.io/rb/hash-keyable.png)](http://badge.fury.io/rb/hash-keyable)
6
+
7
+ Description
8
+ ------------
9
+
10
+ Tiny template for Hash keys.
11
+
12
+ Features
13
+ --------
14
+
15
+ * Pure Ruby :)
16
+
17
+ Usage
18
+ -----
19
+
20
+ ### Overview
21
+
22
+ ```ruby
23
+ require 'hash/keyable'
24
+
25
+ class FooBar
26
+ include Hash::Keyable
27
+
28
+ attr_accessor :var
29
+ end
30
+
31
+ foo = FooBar.new
32
+ bar = FooBar.new
33
+
34
+ HASH = {foo => :value}
35
+
36
+ p HASH.key? bar #=> true
37
+
38
+ foo.var = 'foo'
39
+ bar.var = 'bar'
40
+
41
+ p HASH.key? bar #=> false
42
+
43
+ bar.var = 'foo'
44
+
45
+ p HASH.key? bar #=> false
46
+
47
+ HASH.rehash
48
+
49
+ p HASH.key? bar #=> true
50
+ ```
51
+
52
+ Requirements
53
+ -------------
54
+
55
+ * [Ruby - 2.5 or later](http://travis-ci.org/#!/kachick/hash-keyable)
56
+
57
+ Install
58
+ -------
59
+
60
+ ```bash
61
+ gem install hash-keyable
62
+ ```
63
+
64
+ Link
65
+ ----
66
+
67
+ * [code](https://github.com/kachick/hash-keyable)
68
+ * [API](http://kachick.github.com/hash-keyable/yard/frames.html)
69
+ * [issues](https://github.com/kachick/hash-keyable/issues)
70
+ * [CI](http://travis-ci.org/#!/kachick/hash-keyable)
71
+ * [gem](https://rubygems.org/gems/hash-keyable)
72
+
73
+ License
74
+ --------
75
+
76
+ The MIT X11 License
77
+ Copyright (c) 2012 Kenichi Kamiya
78
+ See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ # coding: us-ascii
3
+
4
+ require 'bundler/gem_tasks'
5
+
6
+ require 'rake/testtask'
7
+
8
+ task default: [:test]
9
+
10
+ Rake::TestTask.new do |tt|
11
+ tt.verbose = true
12
+ end
@@ -0,0 +1,31 @@
1
+ # coding: us-ascii
2
+
3
+ $VERBOSE = true
4
+
5
+ require_relative '../lib/hash/keyable'
6
+
7
+ class FooBar
8
+ include Hash::Keyable
9
+
10
+ attr_accessor :var
11
+ end
12
+
13
+ foo = FooBar.new
14
+ bar = FooBar.new
15
+
16
+ HASH = {foo => :value}
17
+
18
+ p HASH.key? bar #=> true
19
+
20
+ foo.var = 'foo'
21
+ bar.var = 'bar'
22
+
23
+ p HASH.key? bar #=> false
24
+
25
+ bar.var = 'foo'
26
+
27
+ p HASH.key? bar #=> false
28
+
29
+ HASH.rehash
30
+
31
+ p HASH.key? bar #=> true
@@ -0,0 +1,30 @@
1
+ # coding: us-ascii
2
+
3
+ Gem::Specification.new do |gem|
4
+ # specific
5
+
6
+ gem.name = 'hash-keyable'
7
+ gem.description = %q{Tiny template for Hash keys.}
8
+ gem.summary = gem.description.dup
9
+ gem.license = 'MIT'
10
+ gem.version = '0.1.0'
11
+
12
+ gem.add_development_dependency 'declare', '~> 0.0.6'
13
+ gem.add_development_dependency 'yard', '>= 0.9.20', '< 2'
14
+ gem.add_development_dependency 'rake', '>= 10', '< 20'
15
+ gem.add_development_dependency 'bundler', '>= 2', '< 3'
16
+
17
+ if RUBY_ENGINE == 'rbx'
18
+ gem.add_dependency 'rubysl', '~> 2.0'
19
+ end
20
+
21
+ # common
22
+
23
+ gem.homepage = "http://kachick.github.com/#{gem.name}"
24
+ gem.authors = ['Kenichi Kamiya']
25
+ gem.email = ['kachick1+ruby@gmail.com']
26
+ gem.files = `git ls-files`.split($\)
27
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
28
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
+ gem.require_paths = ['lib']
30
+ end
@@ -0,0 +1,39 @@
1
+ # coding: us-ascii
2
+ # Copyright (c) 2012 Kenichi Kamiya
3
+
4
+ class Hash
5
+
6
+ # default behavior is depending just only instance variables
7
+ # you can change the behavior, when override the #_hash_key_comparisons
8
+ module Keyable
9
+
10
+ # @return [Integer]
11
+ def hash
12
+ _hash_key_comparisons.hash
13
+ end
14
+
15
+ def eql?(other)
16
+ other.instance_of?(self.class) && \
17
+ other._hash_key_comparisons.eql?(_hash_key_comparisons)
18
+ end
19
+
20
+ protected
21
+
22
+ # @return [Array]
23
+ # @example
24
+ # class Foo
25
+ # include Hash::Keyable
26
+ #
27
+ # protected
28
+ #
29
+ # def _hash_key_comparisons(*specifics)
30
+ # super my_specific1, my_specific2, *specifics
31
+ # end
32
+ # end
33
+ def _hash_key_comparisons(*specifics)
34
+ instance_variables.map{|var|instance_variable_get var} + specifics
35
+ end
36
+
37
+ end
38
+
39
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ # coding: us-ascii
2
+
3
+ require 'declare/autorun'
4
+
5
+ $VERBOSE = true
6
+
7
+ require_relative '../lib/hash/keyable'
@@ -0,0 +1,60 @@
1
+ # coding: us-ascii
2
+
3
+ require_relative 'helper'
4
+
5
+ class FooBar
6
+ include Hash::Keyable
7
+
8
+ attr_accessor :var
9
+ end
10
+
11
+ foo = FooBar.new
12
+ bar = FooBar.new
13
+
14
+ The foo do
15
+ EQL bar
16
+
17
+ foo.var = 'foo'
18
+ bar.var = 'bar'
19
+
20
+ NG EQL?(bar)
21
+
22
+ bar.var = 'foo'
23
+
24
+ EQL bar
25
+ end
26
+
27
+ class FooBar
28
+ def my_specific1
29
+ :specific1
30
+ end
31
+
32
+ protected
33
+
34
+ def _hash_key_comparisons(*specifics)
35
+ super my_specific1, my_specific2, *specifics
36
+ end
37
+
38
+ private
39
+
40
+ def my_specific2
41
+ :specific2
42
+ end
43
+ end
44
+
45
+ foo = FooBar.new
46
+ bar = FooBar.new
47
+
48
+ The foo do
49
+ EQL bar
50
+
51
+ foo.var = 'foo'
52
+ bar.var = 'bar'
53
+
54
+ NG EQL?(bar)
55
+
56
+ bar.var = 'foo'
57
+
58
+ EQL bar
59
+ end
60
+
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash-keyable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenichi Kamiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: declare
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.6
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.20
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.20
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '10'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '20'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '10'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '20'
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '2'
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '3'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '2'
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: '3'
87
+ description: Tiny template for Hash keys.
88
+ email:
89
+ - kachick1+ruby@gmail.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - ".travis.yml"
96
+ - ".yardopts"
97
+ - Gemfile
98
+ - MIT-LICENSE
99
+ - README.md
100
+ - Rakefile
101
+ - example/overview.rb
102
+ - hash-keyable.gemspec
103
+ - lib/hash/keyable.rb
104
+ - test/helper.rb
105
+ - test/test_basic.rb
106
+ homepage: http://kachick.github.com/hash-keyable
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Tiny template for Hash keys.
130
+ test_files:
131
+ - test/helper.rb
132
+ - test/test_basic.rb