deep_dup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d00f8bfe1ee27f10defaf6f00fd1da009bac911
4
+ data.tar.gz: 8f6c8f10cd798bf95e47df1bd5798caaee00d696
5
+ SHA512:
6
+ metadata.gz: 2f090c0109e6ab2fe5b7c2d5570de9aeed3cb0470b72e0584d3e9b000fc23c733a325efe3ce4f14dd82e448869bdbfc518d10db3c7eb9e2c1248a5a13410efc7
7
+ data.tar.gz: 9e73b27787434ee36d1504f0d8f1c49b317f6fd1ff87c8d1d53fce14f38b19f35403e59f90d16aad11a6e25ba8b035db70b2ecb6ed77839118932e7c3aa5408f
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2.2
5
+ - 2.1.6
6
+ - 2.0.0
7
+ - 1.9.3
8
+ - jruby-19mode
9
+
10
+ branches:
11
+ only:
12
+ - master
13
+
14
+ notifications:
15
+ email:
16
+ on_success: change
17
+ on_failure: always
18
+
19
+ before_install: "gem install bundler -v 1.10.5"
20
+ install: "bundle --jobs 4"
21
+ script: "bundle exec rspec"
@@ -0,0 +1,7 @@
1
+ --protected
2
+ --private
3
+ --embed-mixins
4
+ lib/**/*.rb
5
+ -
6
+ README.md
7
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deep_dup.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Oldrich Vetesnik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # DeepDup [![Build Status](https://img.shields.io/travis/ollie/deep_dup/master.svg)](https://travis-ci.org/ollie/deep_dup) [![Code Climate](https://img.shields.io/codeclimate/github/ollie/deep_dup.svg)](https://codeclimate.com/github/ollie/deep_dup) [![Gem Version](https://img.shields.io/gem/v/deep_dup.svg)](https://rubygems.org/gems/deep_dup)
2
+
3
+ Deep duplicate Ruby objects. Some objects cannot be `dup`ped like `nil`,
4
+ `false`, `true`, numbers, symbols and method objects. In those cases
5
+ return themselvese.
6
+
7
+ ## Usage
8
+
9
+ No monkey patching:
10
+
11
+ ```ruby
12
+ dupped = DeepDup.deep_dup('chunky')
13
+ dupped = DeepDup.deep_dup(['chunky', [:bacon, { hi: 5 }]])
14
+ dupped = DeepDup.deep_dup(['a', :a, 1, { bacon: { chunky: 'yeah' } }])
15
+ dupped = DeepDup.deep_dup(SomeClass.new)
16
+ ```
17
+
18
+ With monkey patching
19
+
20
+ ```ruby
21
+ require 'deep_dup/core_ext/object'
22
+
23
+ dupped = 'chunky'.deep_dup
24
+ dupped = ['chunky', [:bacon, { hi: 5 }]].deep_dup
25
+ dupped = ['a', :a, 1, { bacon: { chunky: 'yeah' } }].deep_dup
26
+ dupped = SomeClass.new.deep_dup
27
+ ```
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'deep_dup'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install deep_dup
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ollie/deep_dup.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task default: :combo
4
+
5
+ desc 'Run tests, rubocop and generate documentation'
6
+ task :combo do
7
+ sh 'bundle exec rspec'
8
+ sh('bundle exec rubocop') {} # ignore status > 0
9
+ sh 'bundle exec yardoc'
10
+ end
11
+
12
+ desc 'Same as :combo but build a gem, too'
13
+ task mega_combo: :combo do
14
+ sh 'gem build deep_dup.gemspec'
15
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deep_dup'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deep_dup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deep_dup'
8
+ spec.version = DeepDup::VERSION
9
+ spec.authors = ['Oldrich Vetesnik']
10
+ spec.email = ['oldrich.vetesnik@gmail.com']
11
+
12
+ spec.summary = 'Deep duplicate Ruby objects.'
13
+ spec.homepage = 'https://github.com/ollie/deep_dup'
14
+ spec.license = 'MIT'
15
+
16
+ # rubocop:disable Metrics/LineLength
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ # System
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+
25
+ # Test
26
+ spec.add_development_dependency 'rspec', '~> 3.3'
27
+ spec.add_development_dependency 'simplecov', '~> 0.10'
28
+
29
+ # Code style, debugging, docs
30
+ spec.add_development_dependency 'rubocop', '~> 0.32'
31
+ spec.add_development_dependency 'pry', '~> 0.10'
32
+ spec.add_development_dependency 'yard', '~> 0.8'
33
+ spec.add_development_dependency 'rake', '~> 10.4'
34
+ end
@@ -0,0 +1,48 @@
1
+ require 'deep_dup/version'
2
+
3
+ # Deep duplicate any object. Some objects cannot be +dup+ped like +nil+,
4
+ # +false+, +true+, numbers, symbols and method objects. In those cases
5
+ # return themselvese.
6
+ #
7
+ # @example No monkey patching
8
+ # dupped = DeepDup.deep_dup('chunky')
9
+ # dupped = DeepDup.deep_dup(['chunky', [:bacon, { hi: 5 }]])
10
+ # dupped = DeepDup.deep_dup(['a', :a, 1, { bacon: { chunky: 'yeah' } }])
11
+ # dupped = DeepDup.deep_dup(SomeClass.new)
12
+ #
13
+ # @example With monkey patching
14
+ # require 'deep_dup/core_ext/object'
15
+ #
16
+ # dupped = 'chunky'.deep_dup
17
+ # dupped = ['chunky', [:bacon, { hi: 5 }]].deep_dup
18
+ # dupped = ['a', :a, 1, { bacon: { chunky: 'yeah' } }].deep_dup
19
+ # dupped = SomeClass.new.deep_dup
20
+ module DeepDup
21
+ # Deep duplicate any object.
22
+ #
23
+ # @example
24
+ # dupped = DeepDup.deep_dup('chunky')
25
+ # dupped = DeepDup.deep_dup(['chunky', [:bacon, { hi: 5 }]])
26
+ # dupped = DeepDup.deep_dup(['a', :a, 1, { bacon: { chunky: 'yeah' } }])
27
+ # dupped = DeepDup.deep_dup(SomeClass.new)
28
+ #
29
+ # @param object [Object] Pretty much anything.
30
+ #
31
+ # @return [Object] Dupped object if possible.
32
+ def self.deep_dup(object) # rubocop:disable Metrics/MethodLength
33
+ case object
34
+ when String
35
+ object.dup
36
+ when nil, false, true, Numeric, Symbol, Method
37
+ object
38
+ when Array
39
+ object.map { |item| deep_dup(item) }
40
+ when Hash
41
+ object.each.with_object({}) do |(key, value), hash|
42
+ hash[deep_dup(key)] = deep_dup(value)
43
+ end
44
+ else # Object, Class
45
+ object.dup
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ module DeepDup
2
+ # This module holds extensions for core classes.
3
+ module CoreExt
4
+ # Extension for +Object+ class.
5
+ module Object
6
+ # Deep duplicate any object by delegating to +DeepDup.deep_dup+.
7
+ #
8
+ # @example
9
+ # require 'deep_dup/core_ext/object'
10
+ #
11
+ # dupped = 'chunky'.deep_dup
12
+ # dupped = ['chunky', [:bacon, { hi: 5 }]].deep_dup
13
+ # dupped = ['a', :a, 1, { bacon: { chunky: 'yeah' } }].deep_dup
14
+ # dupped = SomeClass.new.deep_dup
15
+ #
16
+ # @return [Object] Dupped object if possible.
17
+ def deep_dup
18
+ DeepDup.deep_dup(self)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # Add +Object#deep_dup+.
25
+ Object.send(:include, DeepDup::CoreExt::Object)
@@ -0,0 +1,4 @@
1
+ module DeepDup
2
+ # Version number, happy now?
3
+ VERSION = '0.0.1'
4
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deep_dup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Oldrich Vetesnik
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.32'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.32'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.4'
111
+ description:
112
+ email:
113
+ - oldrich.vetesnik@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - ".yardopts"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - deep_dup.gemspec
129
+ - lib/deep_dup.rb
130
+ - lib/deep_dup/core_ext/object.rb
131
+ - lib/deep_dup/version.rb
132
+ homepage: https://github.com/ollie/deep_dup
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.8
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Deep duplicate Ruby objects.
156
+ test_files: []
157
+ has_rdoc: