kindah 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/kindah/ast.rb +1 -0
- data/lib/kindah/ast/class_template.rb +1 -0
- data/lib/kindah/ast/superklass.rb +11 -0
- data/lib/kindah/cache.rb +4 -0
- data/lib/kindah/compiler.rb +7 -3
- data/lib/kindah/version.rb +1 -1
- data/spec/integration/namespaced_parameterized_class_spec.rb +6 -0
- data/spec/integration/parameterized_class_spec.rb +4 -0
- data/spec/integration/with_nondefault_superclass_spec.rb +57 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGMzNTYyYmRmMzZiN2I2NjAzZWVjZDJkNTRhMzQwOGUyMjFmZThhZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmM4MmM4NjM3NTE1M2I3YTdmYjdlOGQwOTJiNmMyZTAyYzQzNDNkMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTI4NzMxMDZlNDI1OTA2Y2JiMTE2OThmMGY4MTg3NjY3ZTI4YmQ0NzcwYWEx
|
10
|
+
N2FhYzUyNzhiNTlkOWJlZmEzYTE5OWVkMzk0YTY5MTNjMGE1NWVjMTQ1ODdh
|
11
|
+
ZmQ5ZTczNDQ0MTZjMjU4ODY3ODhlY2U3MDc1NDk5ZjY1NTg1ODk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTIwNGY4MjFkMmZkNmM2NWY0YzdhY2FkNmVmOTUxNmZkNjdkYTZkZjUxMTJm
|
14
|
+
MzgxMDQ2MDRjZWNjYjYzZjdmYzhkOTNhZDUyZmNhMDczYWUxMGVkYmQxOTAz
|
15
|
+
NTkzM2JkNmZkZjcxZTNlNTU5YzZmYmJmNmVjYTNkNGFmY2ViZTY=
|
data/lib/kindah/ast.rb
CHANGED
data/lib/kindah/cache.rb
CHANGED
data/lib/kindah/compiler.rb
CHANGED
@@ -14,6 +14,10 @@ module Kindah
|
|
14
14
|
safe_fetch InstanceMethods
|
15
15
|
end
|
16
16
|
|
17
|
+
def superklass
|
18
|
+
safe_fetch(Superklass, proc { Object }).call
|
19
|
+
end
|
20
|
+
|
17
21
|
delegate [:arity, :block, :children] => :@ast
|
18
22
|
def class_name
|
19
23
|
@ast.name
|
@@ -40,7 +44,7 @@ module Kindah
|
|
40
44
|
def create_klass_with_args(*args)
|
41
45
|
compiler = self # this trick carries the outer scope past ruby's stupid block-scoping rules.
|
42
46
|
|
43
|
-
Class.new do
|
47
|
+
Class.new(compiler.superklass) do
|
44
48
|
compiler.install_template_arg_methods(self, *args)
|
45
49
|
compiler.install_class_methods(self)
|
46
50
|
compiler.install_instance_methods(self)
|
@@ -64,8 +68,8 @@ module Kindah
|
|
64
68
|
|
65
69
|
private
|
66
70
|
|
67
|
-
def safe_fetch(klass)
|
68
|
-
return
|
71
|
+
def safe_fetch(klass, default = proc {})
|
72
|
+
return default unless children.has_key?(klass)
|
69
73
|
children[klass].block
|
70
74
|
end
|
71
75
|
end
|
data/lib/kindah/version.rb
CHANGED
@@ -24,6 +24,12 @@ describe Kindah do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
after :all do
|
28
|
+
TestModule.instance_eval { undef Test }
|
29
|
+
Object.send(:remove_const, :TestModule)
|
30
|
+
Kindah::Cache.clear!
|
31
|
+
end
|
32
|
+
|
27
33
|
subject(:test_instance) { TestModule::Test(1).new }
|
28
34
|
|
29
35
|
it { should respond_to :bar }
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kindah do
|
4
|
+
before :all do
|
5
|
+
module TestModule; end
|
6
|
+
|
7
|
+
Kindah.class_template! :Test, location: TestModule do
|
8
|
+
superclass { Super }
|
9
|
+
|
10
|
+
class_methods do |bar|
|
11
|
+
def foo_class
|
12
|
+
bar + 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
instance_methods do
|
17
|
+
def foo_instance
|
18
|
+
bar + 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@ivar = 1
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :ivar
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Super
|
30
|
+
def supermethod
|
31
|
+
:super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after :all do
|
37
|
+
TestModule.instance_eval { undef Test }
|
38
|
+
Object.send(:remove_const, :Super)
|
39
|
+
Object.send(:remove_const, :TestModule)
|
40
|
+
Kindah::Cache.clear!
|
41
|
+
end
|
42
|
+
|
43
|
+
subject(:test_instance) { TestModule::Test(1).new }
|
44
|
+
|
45
|
+
it { should respond_to :bar }
|
46
|
+
it { should respond_to :foo_instance }
|
47
|
+
it { should respond_to :ivar }
|
48
|
+
|
49
|
+
it { should respond_to :supermethod }
|
50
|
+
its(:supermethod) { should == :super }
|
51
|
+
|
52
|
+
its(:ivar) { should == 1 }
|
53
|
+
|
54
|
+
its(:class) { should < Super }
|
55
|
+
its(:class) { should respond_to :bar }
|
56
|
+
its(:class) { should respond_to :foo_class }
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Fredette
|
@@ -45,11 +45,13 @@ files:
|
|
45
45
|
- lib/kindah/ast/class_methods.rb
|
46
46
|
- lib/kindah/ast/class_template.rb
|
47
47
|
- lib/kindah/ast/instance_methods.rb
|
48
|
+
- lib/kindah/ast/superklass.rb
|
48
49
|
- lib/kindah/cache.rb
|
49
50
|
- lib/kindah/compiler.rb
|
50
51
|
- lib/kindah/version.rb
|
51
52
|
- spec/integration/namespaced_parameterized_class_spec.rb
|
52
53
|
- spec/integration/parameterized_class_spec.rb
|
54
|
+
- spec/integration/with_nondefault_superclass_spec.rb
|
53
55
|
- spec/spec_helper.rb
|
54
56
|
homepage: ''
|
55
57
|
licenses:
|
@@ -78,4 +80,5 @@ summary: Kindah is an implementation of Parameterized Classes for Ruby.
|
|
78
80
|
test_files:
|
79
81
|
- spec/integration/namespaced_parameterized_class_spec.rb
|
80
82
|
- spec/integration/parameterized_class_spec.rb
|
83
|
+
- spec/integration/with_nondefault_superclass_spec.rb
|
81
84
|
- spec/spec_helper.rb
|