ov 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/LICENSE.txt +1 -1
- data/README.md +24 -1
- data/lib/ov.rb +16 -3
- data/lib/ov/exception.rb +1 -1
- data/lib/ov/version.rb +1 -1
- data/samples/instances.rb +34 -0
- data/samples/pm.rb +1 -1
- data/spec/override_spec.rb +4 -4
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
N2UxYWIzMGI2ZGVmMTU4NjM4MDJiMDBiNWYyMjcyZTcxNjU2OGI3Mw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2fb8e560e4e2f7ebed892f926df1f81238781f3
|
4
|
+
data.tar.gz: 82cba6f07a2aee4fc5e0b959f655559bcb9134e6
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MWNhMWExM2ZkMWNhODAxZjllZTJkNGZjOTEyZmQxOGQ1YTRjYjc1NzIwNmQ3
|
11
|
-
OTBjMjhhNzljMmI5OWFmOWE2OWEzMTVkNDBiOGQ1YjNkOTQyNmY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OWI2OTcyOWZkZmMzM2JkMGFkMGU2M2I1ZTBkZmVmNjZjYTQ2OGE5NWJiNzY3
|
14
|
-
MWQ0NjMxNzZjMDY1ODhhYTkzYjAyODI1MTZlN2NhZDU5ZmQxNDJkYjgzZWYy
|
15
|
-
NWQ0MmM1YzVlOWIyY2U5ZTRmMThjNDM3M2Q2N2E3ZWRhZjNjNGM=
|
6
|
+
metadata.gz: b5fd66e11d9c6d638888c6e5a83e65f7f01d8ded65091f626c58eb6bb22aa6bba2d0152d21fa1cd838d8c06b5d91ec7982bd13255d697e82ee73693199cb7172
|
7
|
+
data.tar.gz: 19ba949b79b683f21dae23c05fd3162372b87fb955a49586d44953870578fe3bb96c4714b41b1fd8a6b205fbaeafff033fb9ab4540030213c1ecb8b64e5a0414
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -86,9 +86,32 @@ my_class.cool_method(1) => 1
|
|
86
86
|
my_class.cool_method("foo") => "foo"
|
87
87
|
```
|
88
88
|
|
89
|
+
|
90
|
+
Redefine methods
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
class A
|
94
|
+
def test(str)
|
95
|
+
p "A#test"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class B < A
|
100
|
+
include Ov
|
101
|
+
let :test, Fixnum do |num|
|
102
|
+
p "only for fixnum"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
b = B.new
|
107
|
+
b.test("asd") # => A#test
|
108
|
+
b.test(123) # => only for fixnum
|
109
|
+
|
110
|
+
```
|
111
|
+
|
89
112
|
Examples
|
90
113
|
--------
|
91
|
-
see [link](https://github.com/fntzr/ov/blob/master/samples
|
114
|
+
see [link](https://github.com/fntzr/ov/blob/master/samples)
|
92
115
|
|
93
116
|
## Contributing
|
94
117
|
|
data/lib/ov.rb
CHANGED
@@ -50,7 +50,8 @@ require "ov/exception"
|
|
50
50
|
# end
|
51
51
|
#
|
52
52
|
# my_class = MyClass.new
|
53
|
-
# my_class.cool_method(1)
|
53
|
+
# my_class.cool_method(1)
|
54
|
+
# => 1
|
54
55
|
# my_class.cool_method("foo") # => "foo"
|
55
56
|
#
|
56
57
|
# Is the same so ruby `def`
|
@@ -96,6 +97,13 @@ module Ov
|
|
96
97
|
# +types+ types for method
|
97
98
|
#
|
98
99
|
def let(name, *types, &block)
|
100
|
+
included = false
|
101
|
+
|
102
|
+
if self.instance_methods.include?(name)
|
103
|
+
included = true
|
104
|
+
class_eval "alias :ov_old_#{name.to_s} #{name}"
|
105
|
+
undef_method name
|
106
|
+
end
|
99
107
|
|
100
108
|
__overridable_methods << OverrideMethod.new(name, types, self, block)
|
101
109
|
|
@@ -121,9 +129,14 @@ module Ov
|
|
121
129
|
z = owner.send(:__overridable_methods).where(method)
|
122
130
|
|
123
131
|
if z.nil?
|
124
|
-
|
132
|
+
if included
|
133
|
+
send("ov_old_#{name.to_s}", *args, &block)
|
134
|
+
else
|
135
|
+
raise Ov::NotImplementError.new("Method `#{name}` in `#{self}` class with types `#{types.join(', ')}` not implemented.")
|
136
|
+
end
|
137
|
+
else
|
138
|
+
instance_exec(*args, &z.body)
|
125
139
|
end
|
126
|
-
instance_exec(*args, &z.body)
|
127
140
|
end
|
128
141
|
end
|
129
142
|
end
|
data/lib/ov/exception.rb
CHANGED
data/lib/ov/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "ov"
|
2
|
+
|
3
|
+
class A
|
4
|
+
def test(str)
|
5
|
+
p "A#test"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.class_test(str)
|
9
|
+
p "A#class_test"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class B < A
|
14
|
+
include Ov
|
15
|
+
let :test, Fixnum do |num|
|
16
|
+
p "only for fixnum"
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
include Ov
|
21
|
+
|
22
|
+
let :class_test, Fixnum do |num|
|
23
|
+
p "class method for fixnum"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
b = B.new
|
29
|
+
b.test("asd") # => A#test
|
30
|
+
b.test(123) # => only for fixnum
|
31
|
+
|
32
|
+
B.class_test("asd") # => "A#class_test"
|
33
|
+
B.class_test(123) # => "class method for fixnum"
|
34
|
+
|
data/samples/pm.rb
CHANGED
data/spec/override_spec.rb
CHANGED
@@ -44,7 +44,7 @@ describe Ov do
|
|
44
44
|
context "exceptions" do
|
45
45
|
let(:test){TestException.new}
|
46
46
|
it "throw NotImplementError when method not defined" do
|
47
|
-
expect { test.some_method("foo") }.to raise_error(NotImplementError)
|
47
|
+
expect { test.some_method("foo") }.to raise_error(Ov::NotImplementError)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -78,8 +78,8 @@ describe Ov do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it "exception when many arguments or without arguments" do
|
81
|
-
expect{ test.my_instance_method(1,2,3)}.to raise_error(NotImplementError)
|
82
|
-
expect{ test.my_instance_method()}.to raise_error(NotImplementError)
|
81
|
+
expect{ test.my_instance_method(1,2,3)}.to raise_error(Ov::NotImplementError)
|
82
|
+
expect{ test.my_instance_method()}.to raise_error(Ov::NotImplementError)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -130,7 +130,7 @@ describe Ov do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it "exception when not defined" do
|
133
|
-
expect{ test_ins.my_instance_method(1,2,3)}.to raise_error(NotImplementError)
|
133
|
+
expect{ test_ins.my_instance_method(1,2,3)}.to raise_error(Ov::NotImplementError)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fntzr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.14.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.14.0
|
55
55
|
description: write overridable methods for fun :)
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
63
63
|
- Gemfile
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/ov/version.rb
|
73
73
|
- ov.gemspec
|
74
74
|
- samples/class_methods.rb
|
75
|
+
- samples/instances.rb
|
75
76
|
- samples/myarray.rb
|
76
77
|
- samples/pm.rb
|
77
78
|
- samples/rack.rb
|
@@ -89,17 +90,17 @@ require_paths:
|
|
89
90
|
- lib
|
90
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
92
|
requirements:
|
92
|
-
- -
|
93
|
+
- - ">="
|
93
94
|
- !ruby/object:Gem::Version
|
94
95
|
version: '0'
|
95
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
97
|
requirements:
|
97
|
-
- -
|
98
|
+
- - ">="
|
98
99
|
- !ruby/object:Gem::Version
|
99
100
|
version: '0'
|
100
101
|
requirements: []
|
101
102
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.2.2
|
103
104
|
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: ov gem provides hacks for write polymorphic methods in Ruby.
|