crimp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d887596d2b57389ff5f4542a66b6feb0675597c9
4
+ data.tar.gz: fbc0a8b3882d8100ca3e75f9a2fff070480df6e5
5
+ SHA512:
6
+ metadata.gz: 9e9990c056596d3c3b559690bd931db0dd9207bdece77a2f7dd0c65b1b0c30decb8709f896fac86413f582ec2b712dc5569716c937feaf807d1bf6b4becefced
7
+ data.tar.gz: cd88bcba3e77022a349f27d780025b4feb5f6ad77b6fbdd16b2b8dc4e71152f367404737064bd632f3e74c9dea854a3fe8a8dabbb4ed9099ac5e2ff76225918e
@@ -0,0 +1,10 @@
1
+ /config/*.yaml
2
+ /config/*.yml
3
+ Gemfile.lock
4
+ .rspec
5
+ *.gem
6
+
7
+ /pkg
8
+ /tmp
9
+ /components
10
+
@@ -0,0 +1 @@
1
+ jruby-1.7.9
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in crimp.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/.+\.rb$})
4
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robert Kenny
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.
@@ -0,0 +1,46 @@
1
+ # Crimp
2
+
3
+ Creating an md5 hash of a number, string, array, or hash in Ruby
4
+
5
+ ![mighty-boosh-four-way-crimp-o](https://f.cloud.github.com/assets/180050/2148112/b44fd6fa-93de-11e3-9f9a-ad941f069b5c.gif)
6
+
7
+ Shamelessly copied from [this Stack Overflow
8
+ answer](http://stackoverflow.com/a/6462589/3243663).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'crimp'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install crimp
23
+
24
+ ## Usage
25
+
26
+ ```rb
27
+ require 'crimp'
28
+
29
+ Crimp.stringify({:a => {:b => 'b', :c => 'c'}, :d => 'd'})
30
+
31
+ # => [\"aSymbol=>[\\\"bSymbol=>b\\\", \\\"cSymbol=>c\\\"]Array\",
32
+ \"dSymbol=>d\"]Array"
33
+
34
+ Crimp.signature({:a => {:b => 'b', :c => 'c'}, :d => 'd'})
35
+
36
+ # => "68d07febc4f47f56fa6ef5de063a77b1"
37
+
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( http://github.com/<my-github-username>/crimp/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'crimp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "crimp"
8
+ spec.version = Crimp::VERSION
9
+ spec.authors = ["Robert Kenny", "Mark McDonnell"]
10
+ spec.email = ["kenoir@gmail.com","mark.mcdx@gmail.com"]
11
+ spec.summary = %q{Creating an md5 hash of a number, string, array, or hash in Ruby}
12
+ spec.description = <<-EOS.gsub /^\s+/, ""
13
+ Shamelessly lifted from http://stackoverflow.com/questions/6461812/creating-an-md5-hash-of-a-number-string-array-or-hash-in-ruby
14
+
15
+ All credit should go to http://stackoverflow.com/users/394282/luke
16
+ EOS
17
+ spec.homepage = ""
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec-nc"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-rspec"
31
+ spec.add_development_dependency "pry"
32
+ spec.add_development_dependency "pry-remote"
33
+ spec.add_development_dependency "pry-nav"
34
+
35
+ end
@@ -0,0 +1,30 @@
1
+ require "crimp/version"
2
+ require "digest"
3
+
4
+ module Crimp
5
+ def self.stringify(obj)
6
+ if obj.class == Hash
7
+ arr = []
8
+ obj.each do |key, value|
9
+ arr << "#{self.stringify key}=>#{self.stringify value}"
10
+ end
11
+ obj = arr
12
+ end
13
+ if obj.class == Array
14
+ str = ''
15
+ obj.map! do |value|
16
+ self.stringify value
17
+ end.sort!.each do |value|
18
+ str << value
19
+ end
20
+ end
21
+ if obj.class != String
22
+ obj = obj.to_s << obj.class.to_s
23
+ end
24
+ obj
25
+ end
26
+
27
+ def self.signature(obj)
28
+ Digest::MD5.hexdigest( self.stringify obj )
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Crimp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Crimp do
4
+ let (:example_hash) { {:a => {:b => 'b', :c => 'c'}, :d => 'd'} }
5
+ let (:example_hash_unordered) { {:d => 'd', :a => {:c => 'c', :b => 'b'}} }
6
+ let (:example_array) { [1,2,3,[4,[5,6]]] }
7
+ let (:example_array_unordered) { [3,2,1,[[5,6],4]] }
8
+
9
+ describe ".signature(obj)" do
10
+ context "obj.class == Hash" do
11
+ it "returns a string" do
12
+ expect(subject.signature(example_hash)).to be_a String
13
+ end
14
+
15
+ it "returns Digest::MD5.hexdigest of self.stringify(obj)" do
16
+ expect(
17
+ subject.signature(example_hash)
18
+ ).to eq(
19
+ Digest::MD5.hexdigest(subject.stringify(example_hash))
20
+ )
21
+ end
22
+ end
23
+
24
+ context "obj.class == Array" do
25
+ it "returns a string" do
26
+ expect(subject.signature(example_array)).to be_a String
27
+ end
28
+
29
+ it "returns Digest::MD5.hexdigest of self.stringify(obj)" do
30
+ expect(
31
+ subject.signature(example_array)
32
+ ).to eq(
33
+ Digest::MD5.hexdigest(subject.stringify(example_array))
34
+ )
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ describe ".stringify(obj)" do
41
+ context "obj.class == Hash" do
42
+ it "returns a string" do
43
+ expect(subject.stringify(example_hash)).to be_a String
44
+ end
45
+
46
+ it "will return equal strings for differently ordered hashes" do
47
+ expect(
48
+ subject.stringify(example_hash)
49
+ ).to eq(
50
+ subject.stringify(example_hash_unordered)
51
+ )
52
+ end
53
+ end
54
+
55
+ context "obj.class == Array" do
56
+ it "returns a string" do
57
+ expect(subject.stringify(example_array)).to be_a String
58
+ end
59
+
60
+ it "will return equal strings for differently ordered arrays" do
61
+ expect(
62
+ subject.stringify(example_array)
63
+ ).to eq(
64
+ subject.stringify(example_array_unordered)
65
+ )
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ $: << File.join(File.dirname(__FILE__),"..", "lib")
2
+
3
+ require 'pry'
4
+ require 'crimp'
5
+
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crimp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Kenny
8
+ - Mark McDonnell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: '1.5'
26
+ prerelease: false
27
+ type: :development
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ prerelease: false
41
+ type: :development
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ prerelease: false
55
+ type: :development
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-nc
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ prerelease: false
69
+ type: :development
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ prerelease: false
83
+ type: :development
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rspec
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ prerelease: false
97
+ type: :development
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ prerelease: false
111
+ type: :development
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry-remote
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ prerelease: false
125
+ type: :development
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry-nav
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ prerelease: false
139
+ type: :development
140
+ description: |
141
+ Shamelessly lifted from http://stackoverflow.com/questions/6461812/creating-an-md5-hash-of-a-number-string-array-or-hash-in-ruby
142
+ All credit should go to http://stackoverflow.com/users/394282/luke
143
+ email:
144
+ - kenoir@gmail.com
145
+ - mark.mcdx@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .ruby-version
152
+ - Gemfile
153
+ - Guardfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - crimp.gemspec
158
+ - lib/crimp.rb
159
+ - lib/crimp/version.rb
160
+ - spec/crimp_spec.rb
161
+ - spec/spec_helper.rb
162
+ homepage: ''
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.1.9
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Creating an md5 hash of a number, string, array, or hash in Ruby
186
+ test_files:
187
+ - spec/crimp_spec.rb
188
+ - spec/spec_helper.rb