kindah 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/kindah/compiler.rb +27 -11
- data/lib/kindah/version.rb +1 -1
- data/lib/kindah.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODY0NDc2MWNjZDM0YjUxZDU2MTZlOWIyMjQ1ZTY5ZjU0ODE4NjZkNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjZhMWEwNDRlMTJlNzA0YTU5YjU0MTU5ZGMzOTFiOTY1NGZkNTU5Nw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWVmMDcyZjM3MGRhZmM2NzcxOWRhMDcyZDg3ZDgyNTVkMzlhMWU5OGNkOGUx
|
10
|
+
NjMyMDU5OTk0NTI5YTAzZWRmZjgzODJlMjljZGU0NjUxZTg3YjkyYmQxYjgz
|
11
|
+
MmFiZDkzMjUzN2E2ZjdhMTFiZWVhNmU1NjMxM2ZjYjBmYzU1ZjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmE4ZDljOGFlZWRhZWIyMTVkMjlhODAxMzFmYzM4MjIyNzgxZjY5NGRjODY2
|
14
|
+
ZDUxMmVlNTE3MjJkMWY1MGM3NWUzMmNmMjNjMmUxZDMyYmMyYjljNDU3ZWFk
|
15
|
+
NzQ1OTJmYTY4ZmNkYmRiNmQ0YjQ0ZjNmMWExY2QzZGFmZjRjMGU=
|
data/lib/kindah/compiler.rb
CHANGED
@@ -26,24 +26,40 @@ module Kindah
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def compile!(location = Object)
|
29
|
-
compiler = self
|
29
|
+
compiler = self # this trick carries the outer scope past ruby's stupid block-scoping rules.
|
30
30
|
|
31
31
|
location.send(:define_method, compiler.class_name) do |*args|
|
32
|
-
Kindah::Cache[compiler.class_name, *args] ||=
|
33
|
-
compiler.each_parameter do |name, idx|
|
34
|
-
define_singleton_method(name) { args[idx] }
|
35
|
-
define_method(name) { self.class.send(name) }
|
36
|
-
end
|
37
|
-
|
38
|
-
#because ruby is weird...
|
39
|
-
instance_eval &compiler.class_methods
|
40
|
-
class_eval &compiler.instance_methods
|
41
|
-
end
|
32
|
+
Kindah::Cache[compiler.class_name, *args] ||= compiler.create_klass_with_args *args
|
42
33
|
end
|
43
34
|
|
44
35
|
nil
|
45
36
|
end
|
46
37
|
|
38
|
+
def create_klass_with_args(*args)
|
39
|
+
compiler = self # this trick carries the outer scope past ruby's stupid block-scoping rules.
|
40
|
+
|
41
|
+
Class.new do
|
42
|
+
compiler.install_template_arg_methods(self, *args)
|
43
|
+
compiler.install_class_methods(self)
|
44
|
+
compiler.install_instance_methods(self)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def install_template_arg_methods(target, *args)
|
49
|
+
each_parameter do |name, idx|
|
50
|
+
target.define_singleton_method(name) { args[idx] }
|
51
|
+
target.send(:define_method, name) { self.class.send(name) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def install_class_methods(target)
|
56
|
+
target.instance_eval &class_methods
|
57
|
+
end
|
58
|
+
|
59
|
+
def install_instance_methods(target)
|
60
|
+
target.class_eval &instance_methods
|
61
|
+
end
|
62
|
+
|
47
63
|
private
|
48
64
|
|
49
65
|
def safe_fetch(klass)
|
data/lib/kindah/version.rb
CHANGED
data/lib/kindah.rb
CHANGED
@@ -14,10 +14,10 @@ module Kindah
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.class_template!(name, opts={}, &block)
|
17
|
-
compile! class_template(name, opts, &block)
|
17
|
+
compile! class_template(name, opts, &block), opts.delete(:location) || Object
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.compile!(template)
|
21
|
-
Kindah::Compiler.new(template).compile!
|
20
|
+
def self.compile!(template, location = Object)
|
21
|
+
Kindah::Compiler.new(template).compile!(location)
|
22
22
|
end
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Fredette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katuv
|