meta_instance 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +7 -0
- data/.gitignore +33 -16
- data/.travis.yml +8 -4
- data/Gemfile +2 -3
- data/Gemfile.lock +66 -0
- data/HISTORY.md +33 -0
- data/LICENSE.txt +23 -0
- data/README.md +56 -25
- data/docs/instance.md +201 -0
- data/docs/module.md +34 -0
- data/lib/meta_instance.rb +32 -53
- data/lib/meta_instance/freeze_method.rb +13 -0
- data/lib/meta_instance/instance_method_define.rb +61 -0
- data/lib/meta_instance/module_extensions.rb +61 -0
- data/lib/meta_instance/proxy.rb +270 -0
- data/lib/meta_instance/version.rb +2 -2
- data/meta_instance.gemspec +4 -3
- data/spec/instance_spec.rb +123 -0
- data/spec/{meta_instance_spec.rb → meta_instance/instance_method_define_spec.rb} +22 -15
- data/spec/module_spec.rb +0 -0
- data/spec/spec_helper.rb +1 -3
- metadata +35 -11
- data/.rspec +0 -2
- data/LICENSE +0 -22
- data/Rakefile +0 -1
- data/spec/support/foo.rb +0 -5
@@ -1,3 +1,3 @@
|
|
1
1
|
module MetaInstance
|
2
|
-
VERSION = "1.0
|
3
|
-
end
|
2
|
+
VERSION = "1.1.0"
|
3
|
+
end
|
data/meta_instance.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.version = MetaInstance::VERSION
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.license = "MIT"
|
12
|
-
s.authors = ["L. Preston Sego III"]
|
12
|
+
s.authors = ["Thomas Sawyer", "L. Preston Sego III"]
|
13
13
|
s.email = "LPSego3+dev@gmail.com"
|
14
14
|
s.homepage = "https://github.com/NullVoxPopuli/MetaInstance"
|
15
15
|
s.summary = "MetaInstance-#{MetaInstance::VERSION}"
|
@@ -21,10 +21,11 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
+
s.add_runtime_dependency "activesupport"
|
25
|
+
|
24
26
|
|
25
27
|
s.add_development_dependency "bundler"
|
26
28
|
s.add_development_dependency "rspec"
|
27
29
|
s.add_development_dependency "pry-byebug"
|
28
30
|
s.add_development_dependency "codeclimate-test-reporter"
|
29
|
-
|
30
|
-
end
|
31
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Song
|
4
|
+
attr_accessor :title
|
5
|
+
attr_accessor :artist
|
6
|
+
attr_accessor :year
|
7
|
+
|
8
|
+
def initialize(title, artist, year)
|
9
|
+
@title = title
|
10
|
+
@artist = artist
|
11
|
+
@year = year
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe MetaInstance do
|
16
|
+
|
17
|
+
let(:song){ Song.new("Paranoid", "Black Sabbath", 1970) }
|
18
|
+
|
19
|
+
describe '#variables' do
|
20
|
+
|
21
|
+
it 'returns instance variables as an array of symbols' do
|
22
|
+
actual = song.instance.variables
|
23
|
+
expected = [:@title, :@artist, :@year]
|
24
|
+
expect(actual).to eq expected
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#get' do
|
30
|
+
it 'gets the instance variable' do
|
31
|
+
actual = song.instance.get(:title)
|
32
|
+
expect(actual).to eq 'Paranoid'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#set' do
|
37
|
+
it 'sets the instance varibale' do
|
38
|
+
expected = song.instance.get(:title) + '!!!'
|
39
|
+
song.instance.set(:title, expected)
|
40
|
+
actual = song.instance.get(:title)
|
41
|
+
|
42
|
+
expect(actual).to eq expected
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#[]' do
|
47
|
+
it 'retrieves an instance variable' do
|
48
|
+
actual = song.instance[:title]
|
49
|
+
expect(actual).to eq 'Paranoid'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#to_h' do
|
54
|
+
it 'converts the list of instance variables to a hash' do
|
55
|
+
actual = song.instance.to_h
|
56
|
+
expected = {:title => "Paranoid", :artist => "Black Sabbath", :year => 1970}
|
57
|
+
|
58
|
+
expect(actual).to eq expected
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'converts the list of instance variables to a hash with @ in the keys' do
|
62
|
+
actual = song.instance.to_h(true)
|
63
|
+
expected = {:@title => "Paranoid", :@artist => "Black Sabbath", :@year => 1970}
|
64
|
+
|
65
|
+
expect(actual).to eq expected
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#size' do
|
70
|
+
it 'counts the number of instance variables' do
|
71
|
+
actual = song.instance.size
|
72
|
+
expect(actual).to eq 3
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#<<' do
|
77
|
+
it 'sets an instance variable' do
|
78
|
+
song.instance << [:something, :else]
|
79
|
+
actual = song.instance.get(:something)
|
80
|
+
|
81
|
+
expect(actual).to eq :else
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#remove' do
|
86
|
+
it 'removes an instance variable' do
|
87
|
+
song.instance.remove(:title)
|
88
|
+
actual = song.instance.get(:title)
|
89
|
+
|
90
|
+
expect(actual).to eq nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#update' do
|
95
|
+
it 'updates an instance variable' do
|
96
|
+
song.instance.update(title: 'new title', other: 'var')
|
97
|
+
actual = song.instance.get(:title)
|
98
|
+
actual2 = song.instance.get(:other)
|
99
|
+
|
100
|
+
expect(actual).to eq 'new title'
|
101
|
+
expect(actual2).to eq 'var'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#names' do
|
106
|
+
it 'returns the list of instance variables' do
|
107
|
+
actual = song.instance.keys
|
108
|
+
|
109
|
+
expect(actual).to eq [:title, :artist, :year]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#values' do
|
114
|
+
it 'retrurns a list of values of the instance variables' do
|
115
|
+
actual = song.instance.values
|
116
|
+
expected = ["Paranoid", "Black Sabbath", 1970]
|
117
|
+
|
118
|
+
expect(actual).to eq expected
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
@@ -1,6 +1,13 @@
|
|
1
|
+
class Foo
|
2
|
+
include MetaInstance::InstanceMethodDefine
|
3
|
+
|
4
|
+
def bar; "bar"; end
|
5
|
+
end
|
6
|
+
|
7
|
+
|
1
8
|
require 'spec_helper'
|
2
9
|
|
3
|
-
describe MetaInstance do
|
10
|
+
describe MetaInstance::InstanceMethodDefine do
|
4
11
|
let(:original){"bar"}
|
5
12
|
let(:f){ Foo.new }
|
6
13
|
|
@@ -8,12 +15,12 @@ describe MetaInstance do
|
|
8
15
|
expect(f.bar).to eq original
|
9
16
|
end
|
10
17
|
|
11
|
-
context "
|
18
|
+
context "define_method" do
|
12
19
|
|
13
20
|
context "without args" do
|
14
21
|
|
15
22
|
before(:each) do
|
16
|
-
f.
|
23
|
+
f.define_method(:bar) do
|
17
24
|
"foo"
|
18
25
|
end
|
19
26
|
end
|
@@ -31,7 +38,7 @@ describe MetaInstance do
|
|
31
38
|
context "with args" do
|
32
39
|
|
33
40
|
before(:each) do
|
34
|
-
f.
|
41
|
+
f.define_method(:bar) do |number|
|
35
42
|
number * 2
|
36
43
|
end
|
37
44
|
|
@@ -42,22 +49,22 @@ describe MetaInstance do
|
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
45
|
-
context "
|
52
|
+
context "backup_method" do
|
46
53
|
before(:each) do
|
47
|
-
f.
|
54
|
+
f.backup_method(:bar)
|
48
55
|
end
|
49
56
|
|
50
57
|
it "has the original method accessible" do
|
51
|
-
name = "#{MetaInstance::METHOD_BACKUP_KEY}bar"
|
58
|
+
name = "#{MetaInstance::InstanceMethodDefine::METHOD_BACKUP_KEY}bar"
|
52
59
|
expect(f.send(name)).to eq original
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
56
|
-
context "
|
63
|
+
context "restore_method" do
|
57
64
|
before(:each) do
|
58
|
-
f.
|
59
|
-
f.
|
60
|
-
f.
|
65
|
+
f.backup_method(:bar)
|
66
|
+
f.define_method(:bar) { "different" }
|
67
|
+
f.restore_method(:bar)
|
61
68
|
end
|
62
69
|
|
63
70
|
it "returns the original" do
|
@@ -65,12 +72,12 @@ describe MetaInstance do
|
|
65
72
|
end
|
66
73
|
|
67
74
|
it "doesn't respond_to the backup method" do
|
68
|
-
expect(f).to_not respond_to "#{MetaInstance::METHOD_BACKUP_KEY}bar"
|
75
|
+
expect(f).to_not respond_to "#{MetaInstance::InstanceMethodDefine::METHOD_BACKUP_KEY}bar"
|
69
76
|
end
|
70
77
|
|
71
78
|
it "doesn't remove a method that isn't there" do
|
72
79
|
expect(f).to_not respond_to(:foobar)
|
73
|
-
expect(f.
|
80
|
+
expect(f.restore_method(:foobar)).to be_nil
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
@@ -86,7 +93,7 @@ describe MetaInstance do
|
|
86
93
|
end
|
87
94
|
|
88
95
|
it "has the original method accessible" do
|
89
|
-
name = "#{MetaInstance::METHOD_BACKUP_KEY}bar"
|
96
|
+
name = "#{MetaInstance::InstanceMethodDefine::METHOD_BACKUP_KEY}bar"
|
90
97
|
expect(f.send(name)).to eq original
|
91
98
|
end
|
92
99
|
|
@@ -102,7 +109,7 @@ describe MetaInstance do
|
|
102
109
|
end
|
103
110
|
|
104
111
|
it "does not re-backup the method" do
|
105
|
-
name = "#{MetaInstance::METHOD_BACKUP_KEY}bar"
|
112
|
+
name = "#{MetaInstance::InstanceMethodDefine::METHOD_BACKUP_KEY}bar"
|
106
113
|
expect(f.send(name)).to eq original
|
107
114
|
end
|
108
115
|
|
data/spec/module_spec.rb
ADDED
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require "rubygems"
|
3
2
|
require "bundler/setup"
|
4
3
|
|
@@ -6,13 +5,12 @@ require "pry-byebug" # binding.pry to debug!
|
|
6
5
|
|
7
6
|
# Coverage
|
8
7
|
require "codeclimate-test-reporter"
|
9
|
-
ENV['CODECLIMATE_REPO_TOKEN'] = "
|
8
|
+
ENV['CODECLIMATE_REPO_TOKEN'] = "97758529c5c06792d2f683e15e6ffe819ac16d140fe244640dcf103f1d172fc4"
|
10
9
|
CodeClimate::TestReporter.start
|
11
10
|
|
12
11
|
# This Gem
|
13
12
|
require "meta_instance"
|
14
13
|
|
15
|
-
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each {|file| require file }
|
16
14
|
|
17
15
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
18
16
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
metadata
CHANGED
@@ -1,15 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_instance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Thomas Sawyer
|
7
8
|
- L. Preston Sego III
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
13
28
|
- !ruby/object:Gem::Dependency
|
14
29
|
name: bundler
|
15
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,19 +87,27 @@ executables: []
|
|
72
87
|
extensions: []
|
73
88
|
extra_rdoc_files: []
|
74
89
|
files:
|
90
|
+
- ".codeclimate.yml"
|
75
91
|
- ".gitignore"
|
76
|
-
- ".rspec"
|
77
92
|
- ".travis.yml"
|
78
93
|
- Gemfile
|
79
|
-
-
|
94
|
+
- Gemfile.lock
|
95
|
+
- HISTORY.md
|
96
|
+
- LICENSE.txt
|
80
97
|
- README.md
|
81
|
-
-
|
98
|
+
- docs/instance.md
|
99
|
+
- docs/module.md
|
82
100
|
- lib/meta_instance.rb
|
101
|
+
- lib/meta_instance/freeze_method.rb
|
102
|
+
- lib/meta_instance/instance_method_define.rb
|
103
|
+
- lib/meta_instance/module_extensions.rb
|
104
|
+
- lib/meta_instance/proxy.rb
|
83
105
|
- lib/meta_instance/version.rb
|
84
106
|
- meta_instance.gemspec
|
85
|
-
- spec/
|
107
|
+
- spec/instance_spec.rb
|
108
|
+
- spec/meta_instance/instance_method_define_spec.rb
|
109
|
+
- spec/module_spec.rb
|
86
110
|
- spec/spec_helper.rb
|
87
|
-
- spec/support/foo.rb
|
88
111
|
homepage: https://github.com/NullVoxPopuli/MetaInstance
|
89
112
|
licenses:
|
90
113
|
- MIT
|
@@ -105,11 +128,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
128
|
version: '0'
|
106
129
|
requirements: []
|
107
130
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.4.
|
131
|
+
rubygems_version: 2.4.6
|
109
132
|
signing_key:
|
110
133
|
specification_version: 4
|
111
|
-
summary: MetaInstance-1.0
|
134
|
+
summary: MetaInstance-1.1.0
|
112
135
|
test_files:
|
113
|
-
- spec/
|
136
|
+
- spec/instance_spec.rb
|
137
|
+
- spec/meta_instance/instance_method_define_spec.rb
|
138
|
+
- spec/module_spec.rb
|
114
139
|
- spec/spec_helper.rb
|
115
|
-
- spec/support/foo.rb
|
data/.rspec
DELETED
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2014 L. Preston Sego III
|
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.
|
22
|
-
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|