init_copy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE.txt +21 -0
  4. data/Rakefile +51 -0
  5. data/init_copy.gemspec +53 -0
  6. data/lib/init_copy.rb +121 -0
  7. metadata +108 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a765afbc4cd44bccc9f93569103115fba06e57890edab356f247e9e646060a6f
4
+ data.tar.gz: 66c94d8606358ed4cffb8119406ff7080fc7140f960ef05c7fd8c4bdfd1fa824
5
+ SHA512:
6
+ metadata.gz: a9d5bacac505f8bc4bcdfdf475900ccfc200543c95906639806ef300ac5eac491205a32de535c473401799e9ce2b84004831fc3636c8824eb579551ae43a3bff
7
+ data.tar.gz: b65baed07b2295ef5d3e2216e45e831a2d8baf083c914fa637ed1c46ade609f99c296a49823033bd0cbe350c147437bc49e784ea20454360b1321d625c05e4e3
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+
5
+ source 'https://rubygems.org'
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Jonathan Bradley Whited
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ #--
5
+ # This file is part of InitCopy.
6
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
+ #
8
+ # InitCopy is free software: you can redistribute it and/or modify it under
9
+ # the terms of the MIT License.
10
+ #
11
+ # You should have received a copy of the MIT License along with InitCopy.
12
+ # If not, see <https://choosealicense.com/licenses/mit/>.
13
+ #++
14
+
15
+
16
+ require 'bundler/gem_tasks'
17
+
18
+ require 'init_copy'
19
+ require 'rake/clean'
20
+ require 'rake/testtask'
21
+ require 'yard'
22
+
23
+
24
+ CLEAN.exclude('.git/','stock/')
25
+ CLOBBER.include('doc/')
26
+
27
+
28
+ task default: [:test]
29
+
30
+ desc 'Generate doc (YARDoc)'
31
+ task :doc => [:yard] do |task|
32
+ end
33
+
34
+ Rake::TestTask.new() do |task|
35
+ task.libs = ['lib','test']
36
+ task.pattern = File.join('test','**','*_test.rb')
37
+ task.description += ": '#{task.pattern}'"
38
+ task.verbose = false
39
+ task.warning = true
40
+ end
41
+
42
+ YARD::Rake::YardocTask.new() do |task|
43
+ task.files = [File.join('lib','**','*.{rb}')]
44
+
45
+ task.options += ['--files','CHANGELOG.md,LICENSE.txt']
46
+ task.options += ['--readme','README.md']
47
+
48
+ task.options << '--protected' # Show protected methods
49
+ #task.options += ['--template-path',File.join('yard','templates')]
50
+ task.options += ['--title',"InitCopy v#{InitCopy::VERSION} Doc"]
51
+ end
data/init_copy.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ #--
5
+ # This file is part of InitCopy.
6
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
7
+ #
8
+ # InitCopy is free software: you can redistribute it and/or modify it under
9
+ # the terms of the MIT License.
10
+ #
11
+ # You should have received a copy of the MIT License along with InitCopy.
12
+ # If not, see <https://choosealicense.com/licenses/mit/>.
13
+ #++
14
+
15
+
16
+ lib = File.expand_path(File.join('..','lib'),__FILE__)
17
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
18
+
19
+ require 'init_copy'
20
+
21
+
22
+ Gem::Specification.new() do |spec|
23
+ spec.name = 'init_copy'
24
+ spec.version = InitCopy::VERSION
25
+ spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
26
+ spec.email = ['bradley@esotericpig.com']
27
+ spec.licenses = ['MIT']
28
+ spec.homepage = 'https://github.com/esotericpig/init_copy'
29
+ spec.summary = 'Easily use the appropriate clone/dup method in initialize_copy.'
30
+ spec.description = spec.summary
31
+
32
+ spec.metadata = {
33
+ 'bug_tracker_uri' => 'https://github.com/esotericpig/init_copy/issues',
34
+ 'changelog_uri' => 'https://github.com/esotericpig/init_copy/blob/master/CHANGELOG.md',
35
+ 'homepage_uri' => 'https://github.com/esotericpig/init_copy',
36
+ 'source_code_uri' => 'https://github.com/esotericpig/init_copy'
37
+ }
38
+
39
+ spec.require_paths = ['lib']
40
+
41
+ spec.files = Dir.glob(File.join("{#{spec.require_paths.join(',')}}",'**','*.{rb}')) +
42
+ %W( Gemfile #{spec.name}.gemspec Rakefile ) +
43
+ %w( LICENSE.txt )
44
+
45
+ # Lowest version that isn't eol (end-of-life).
46
+ # - https://www.ruby-lang.org/en/downloads/branches/
47
+ spec.required_ruby_version = '>= 2.4'
48
+
49
+ spec.add_development_dependency 'bundler' ,'~> 2.1'
50
+ spec.add_development_dependency 'minitest','~> 5.14'
51
+ spec.add_development_dependency 'rake' ,'~> 13.0'
52
+ spec.add_development_dependency 'yard' ,'~> 0.9' # For doc
53
+ end
data/lib/init_copy.rb ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of InitCopy.
7
+ # Copyright (c) 2020 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # InitCopy is free software: you can redistribute it and/or modify it under
10
+ # the terms of the MIT License.
11
+ #
12
+ # You should have received a copy of the MIT License along with InitCopy.
13
+ # If not, see <https://choosealicense.com/licenses/mit/>.
14
+ #++
15
+
16
+
17
+ ###
18
+ # @author Jonathan Bradley Whited (@esotericpig)
19
+ # @since 0.1.0
20
+ ###
21
+ module InitCopy
22
+ VERSION = '0.1.0'
23
+
24
+ DEFAULT_COPY_NAME=:dup
25
+
26
+ def self.new(default_name=DEFAULT_COPY_NAME)
27
+ return Copier.new(default_name)
28
+ end
29
+
30
+ def self.find_copy_name(default_name=DEFAULT_COPY_NAME)
31
+ copy_name = default_name
32
+
33
+ caller.each() do |name|
34
+ if name.end_with?(%q(clone'))
35
+ copy_name = :clone
36
+ break
37
+ end
38
+
39
+ if name.end_with?(%q(dup'))
40
+ copy_name = :dup
41
+ break
42
+ end
43
+ end
44
+
45
+ return copy_name
46
+ end
47
+
48
+ ###
49
+ # @author Jonathan Bradley Whited (@esotericpig)
50
+ # @since 0.1.0
51
+ ###
52
+ class Copier
53
+ attr_accessor :default_name
54
+ attr_accessor :name
55
+
56
+ def initialize(default_name=DEFAULT_COPY_NAME)
57
+ super()
58
+
59
+ @default_name = default_name
60
+
61
+ update_name()
62
+ end
63
+
64
+ def copy(var)
65
+ return var.__send__(@name)
66
+ end
67
+
68
+ def safe_copy(var)
69
+ return var.respond_to?(@name) ? var.__send__(@name) : var
70
+ end
71
+
72
+ def update_name()
73
+ @name = InitCopy.find_copy_name(@default_name)
74
+ end
75
+ end
76
+
77
+ Copyer = Copier # Alias
78
+
79
+ ###
80
+ # The instance variable name is long and obnoxious to reduce conflicts.
81
+ #
82
+ # @author Jonathan Bradley Whited (@esotericpig)
83
+ # @since 0.1.0
84
+ ###
85
+ module Copyable
86
+ def initialize_clone(*)
87
+ @init_copy_method_name = :clone
88
+ super
89
+ end
90
+
91
+ def initialize_dup(*)
92
+ @init_copy_method_name = :dup
93
+ super
94
+ end
95
+
96
+ def clone(*)
97
+ @init_copy_method_name = :clone
98
+ super
99
+ end
100
+
101
+ def dup(*)
102
+ @init_copy_method_name = :dup
103
+ super
104
+ end
105
+
106
+ private
107
+
108
+ def copy(var)
109
+ return var.__send__(@init_copy_method_name)
110
+ end
111
+
112
+ def safe_copy(var)
113
+ @init_copy_method_name = DEFAULT_COPY_NAME if @init_copy_method_name.nil?()
114
+
115
+ return var.respond_to?(@init_copy_method_name) ?
116
+ var.__send__(@init_copy_method_name) : var
117
+ end
118
+ end
119
+
120
+ Copiable = Copyable # Alias
121
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: init_copy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Bradley Whited (@esotericpig)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-06 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: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ description: Easily use the appropriate clone/dup method in initialize_copy.
70
+ email:
71
+ - bradley@esotericpig.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - Rakefile
79
+ - init_copy.gemspec
80
+ - lib/init_copy.rb
81
+ homepage: https://github.com/esotericpig/init_copy
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ bug_tracker_uri: https://github.com/esotericpig/init_copy/issues
86
+ changelog_uri: https://github.com/esotericpig/init_copy/blob/master/CHANGELOG.md
87
+ homepage_uri: https://github.com/esotericpig/init_copy
88
+ source_code_uri: https://github.com/esotericpig/init_copy
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '2.4'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.1.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Easily use the appropriate clone/dup method in initialize_copy.
108
+ test_files: []