simple-identity 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/.simplecov ADDED
@@ -0,0 +1,8 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.command_name 'bacon'
8
+ SimpleCov.start {add_filter 'test'}
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-19mode
8
+ script: rake test
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in forwardablex.gemspec
4
+ gemspec
5
+
6
+ gem 'simplecov', :require => false, :group => :test
7
+ gem 'coveralls', :require => false, :group => :test
8
+ gem 'json', '~> 1.7.7'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keita Yamaguchi
2
+
3
+ MIT License
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # simple-identity
2
+
3
+ simple-identity is a Ruby library for providing simple identity methods of #eql?, #==, and #hash.
4
+
5
+ ## Installation
6
+
7
+ $ gem install simple-identity
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ class A
13
+ include SimpleIdentity
14
+ attr_accessor :a, :b, :c
15
+ def initialize(a, b, c)
16
+ @a = a
17
+ @b = b
18
+ @c = c
19
+ end
20
+ end
21
+
22
+ A.new(1,2,3) == A.new(1,2,3) # true
23
+ A.new(1,2,3) != A.new(3,2,1) # true
24
+ ````
25
+
26
+ ## License
27
+
28
+ simple-identity is free software distributed under MIT license.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Test specs'
4
+ task 'test' do
5
+ sh "bundle exec bacon -a"
6
+ end
7
+
8
+ desc 'Generate API document'
9
+ task 'html' do
10
+ sh "bundle exec yard doc -o html --hide-void-return --no-api"
11
+ end
12
+
13
+ desc 'Show undocumented function list'
14
+ task 'html:undoc' do
15
+ sh "bundle exec yard stats --list-undoc --no-api --compact"
16
+ end
17
+
18
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module SimpleIdentity
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,15 @@
1
+ require "simple-identity/version"
2
+
3
+ module SimpleIdentity
4
+ def eql?(other)
5
+ return false unless other.kind_of?(self.class)
6
+ instance_variables.all? do |symbol|
7
+ instance_variable_get(symbol) == other.__send__(symbol.to_s[1..-1])
8
+ end
9
+ end
10
+ alias :"==" :eql?
11
+
12
+ def hash
13
+ instance_variables.map{|symbol| instance_variable_get(symbol)}.hash
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # -*- ruby -*-
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'simple-identity/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "simple-identity"
9
+ spec.version = SimpleIdentity::VERSION
10
+ spec.authors = ["Keita Yamaguchi"]
11
+ spec.email = ["keita.yamaguchi@gmail.com"]
12
+ spec.description = "simple-identity provides simple identity methods of #eql?, #==, and #hash"
13
+ spec.summary = spec.description
14
+ spec.homepage = "https://github.com/keita/simple-identity"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "bacon"
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'simplecov'
2
+ require 'simple-identity'
3
+
4
+ class A
5
+ include SimpleIdentity
6
+ attr_accessor :a, :b, :c
7
+ def initialize(a, b, c)
8
+ @a = a
9
+ @b = b
10
+ @c = c
11
+ end
12
+ end
13
+
14
+ describe "SimpleIdentity" do
15
+ it 'should equal' do
16
+ A.new(1,2,3).should == A.new(1,2,3)
17
+ end
18
+
19
+ it 'should not equal' do
20
+ A.new(1,2,3).should != A.new(3,2,1)
21
+ A.new(1,2,3).should != 1
22
+ end
23
+
24
+ it 'should have same hash values' do
25
+ A.new(1,2,3).hash.should == A.new(1,2,3).hash
26
+ end
27
+
28
+ it 'should have different hash values' do
29
+ A.new(1,2,3).hash.should != A.new(3,2,1).hash
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple-identity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Keita Yamaguchi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bacon
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'simple-identity provides simple identity methods of #eql?, #==, and
63
+ #hash'
64
+ email:
65
+ - keita.yamaguchi@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .simplecov
72
+ - .travis.yml
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - lib/simple-identity.rb
78
+ - lib/simple-identity/version.rb
79
+ - simple-identity.gemspec
80
+ - test/spec_simple-identity.rb
81
+ homepage: https://github.com/keita/simple-identity
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 923825047101298620
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 923825047101298620
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: ! 'simple-identity provides simple identity methods of #eql?, #==, and #hash'
112
+ test_files:
113
+ - test/spec_simple-identity.rb