deep_clone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
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
19
+ bin
20
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deep_clone.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rspec", "~> 2.11"
8
+ end
9
+
10
+ gem "rake"
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013 Sergey Gaychuk
2
+ Copyright (c) 2011-2013 Durran Jordan
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # DeepClone
2
+
3
+ ![alt tag](http://i.qkme.me/356wcq.jpg)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'deep_clone'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install deep_clone
18
+
19
+ ## Usage
20
+
21
+ require 'deep_clone'
22
+
23
+ {a: 1, b: 2, c: {d: 3}, e: [100, 101, 102]}.__deep_clone__
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1,32 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ require "rake"
5
+ require "rspec"
6
+ require "rspec/core/rake_task"
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
9
+ require "deep_clone/version"
10
+
11
+ task :gem => :build
12
+ task :build do
13
+ system "gem build deep_clone.gemspec"
14
+ end
15
+
16
+ task :install => :build do
17
+ system "gem install deep_clone-#{DeepClone::VERSION}.gem"
18
+ end
19
+
20
+ task :release => :build do
21
+ system "git tag -a v#{DeepClone::VERSION} -m 'Tagging #{DeepClone::VERSION}'"
22
+ system "git push --tags"
23
+ system "gem push deep_clone-#{DeepClone::VERSION}.gem"
24
+ system "rm deep_clone-#{DeepClone::VERSION}.gem"
25
+ end
26
+
27
+ RSpec::Core::RakeTask.new("spec") do |spec|
28
+ spec.pattern = "spec/**/*_spec.rb"
29
+ spec.rspec_opts = %w(--format documentation --colour)
30
+ end
31
+
32
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deep_clone/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "deep_clone"
8
+ gem.version = DeepClone::VERSION
9
+ gem.authors = ["Sergey Gaychuk"]
10
+ gem.email = ["sergey.gaychuk@gmail.com"]
11
+ gem.description = %q{Extends base classes for deep copy}
12
+ gem.summary = %q{Extends base classes for deep copy}
13
+ gem.homepage = "https://github.com/sergeygaychuk/deep_clone"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,4 @@
1
+
2
+ require "deep_clone/version"
3
+ require 'deep_clone/extensions'
4
+
@@ -0,0 +1,4 @@
1
+
2
+ require 'deep_clone/extensions/object'
3
+ require 'deep_clone/extensions/hash'
4
+ require 'deep_clone/extensions/array'
@@ -0,0 +1,20 @@
1
+
2
+ module DeepClone
3
+ module Extensions
4
+ module Array
5
+
6
+ # Makes a deep copy of the array, deep copying every element inside the
7
+ # array.
8
+ #
9
+ # @example Get a deep copy of the array.
10
+ # [ 1, 2, 3 ].__deep_clone__
11
+ #
12
+ # @return [ Array ] The deep copy of the array.
13
+ def __deep_clone__
14
+ map { |value| value.__deep_clone__ }
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ ::Array.__send__(:include, DeepClone::Extensions::Array)
@@ -0,0 +1,23 @@
1
+
2
+ module DeepClone
3
+ module Extensions
4
+ module Hash
5
+
6
+ # Make a deep copy of this hash.
7
+ #
8
+ # @example Make a deep copy of the hash.
9
+ # { field: value }.__deep_clone__
10
+ #
11
+ # @return [ Hash ] The copied hash.
12
+ def __deep_clone__
13
+ {}.tap do |copy|
14
+ each_pair do |key, value|
15
+ copy.store(key, value.__deep_clone__)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ::Hash.__send__(:include, DeepClone::Extensions::Hash)
@@ -0,0 +1,18 @@
1
+
2
+ module DeepClone
3
+ module Extensions
4
+ module Object
5
+
6
+ # Deep copy the object. This is for API compatibility, but needs to be
7
+ # overridden.
8
+ #
9
+ # @example Deep copy the object.
10
+ # 1.__deep_clone__
11
+ #
12
+ # @return [ Object ] self.
13
+ def __deep_clone__; self; end
14
+ end
15
+ end
16
+ end
17
+
18
+ ::Object.__send__(:include, DeepClone::Extensions::Object)
@@ -0,0 +1,3 @@
1
+ module DeepClone
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe DeepClone do
4
+ it 'should have a version number' do
5
+ DeepClone::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Hash do
5
+ let(:inner) { [3, 4] }
6
+ let(:data) { [ 1, 2, inner ] }
7
+ let(:copy) { data.__deep_clone__ }
8
+
9
+ it "should return an equal hash" do
10
+ data.should eq(copy)
11
+ end
12
+
13
+ it "should return a copy" do
14
+ data.should_not equal(copy)
15
+ end
16
+
17
+ it "should return an equal hash" do
18
+ copy[2].should eq(inner)
19
+ copy[2].should_not equal(inner)
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Hash do
5
+ let(:inner) { { a: 3, b: 4 } }
6
+ let(:data) { { a: 1, b: 2, c: inner } }
7
+ let(:copy) { data.__deep_clone__ }
8
+
9
+ it "should return an equal hash" do
10
+ data.should eq(copy)
11
+ end
12
+
13
+ it "should return a copy" do
14
+ data.should_not equal(copy)
15
+ end
16
+
17
+ it "should return an equal hash" do
18
+ copy[:c].should eq(inner)
19
+ copy[:c].should_not equal(inner)
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe Object do
5
+ it "should respond to deep copy" do
6
+ Object.new.should be_respond_to(:__deep_clone__)
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rspec'
3
+ require 'deep_clone'
4
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deep_clone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergey Gaychuk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Extends base classes for deep copy
15
+ email:
16
+ - sergey.gaychuk@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - deep_clone.gemspec
28
+ - lib/deep_clone.rb
29
+ - lib/deep_clone/extensions.rb
30
+ - lib/deep_clone/extensions/array.rb
31
+ - lib/deep_clone/extensions/hash.rb
32
+ - lib/deep_clone/extensions/object.rb
33
+ - lib/deep_clone/version.rb
34
+ - spec/deep_clone_spec.rb
35
+ - spec/extensions/array_spec.rb
36
+ - spec/extensions/hash_spec.rb
37
+ - spec/extensions/object_spec.rb
38
+ - spec/spec_helper.rb
39
+ homepage: https://github.com/sergeygaychuk/deep_clone
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ segments:
52
+ - 0
53
+ hash: -3049193081357269342
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ segments:
61
+ - 0
62
+ hash: -3049193081357269342
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Extends base classes for deep copy
69
+ test_files:
70
+ - spec/deep_clone_spec.rb
71
+ - spec/extensions/array_spec.rb
72
+ - spec/extensions/hash_spec.rb
73
+ - spec/extensions/object_spec.rb
74
+ - spec/spec_helper.rb