kindah 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzkwOGY0YWQ3YTZiYjA0Yzc3MmY0NjY0MTNlMmZjOWYzMTI5MjNlYw==
4
+ ODY0NDc2MWNjZDM0YjUxZDU2MTZlOWIyMjQ1ZTY5ZjU0ODE4NjZkNA==
5
5
  data.tar.gz: !binary |-
6
- Zjk3MTgyZDFlMGFkNTliMzRhY2Q0MWEwYzY5YTlmZjUyM2MzZTYwMQ==
6
+ YjZhMWEwNDRlMTJlNzA0YTU5YjU0MTU5ZGMzOTFiOTY1NGZkNTU5Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTZlZmI1OGZlNWQ1NjU2NmY3MzJkYzM2MmY0NDQ1MWIzMDI0NmQ0NzQ1NzE2
10
- Nzc0MDBjZTY4MTQyYmU1ZTg2ZDU3OGYzNDUyZTAzNDlmNzc2NzA0MTQ5Y2Fi
11
- MDM0MWMwNzBmOTY2MWVjOTEzOGM1ZjEzYTE3ZDhmMTkyYWQwYWQ=
9
+ YWVmMDcyZjM3MGRhZmM2NzcxOWRhMDcyZDg3ZDgyNTVkMzlhMWU5OGNkOGUx
10
+ NjMyMDU5OTk0NTI5YTAzZWRmZjgzODJlMjljZGU0NjUxZTg3YjkyYmQxYjgz
11
+ MmFiZDkzMjUzN2E2ZjdhMTFiZWVhNmU1NjMxM2ZjYjBmYzU1ZjE=
12
12
  data.tar.gz: !binary |-
13
- YzI1M2FkZTUyOWVhMjVlOWE3MzlmZDAwZDYxY2RjZTk4YTY0OGJiZDM4YjE4
14
- YTE5YTZhZTNiYzAwZGJjYWZlNTZhY2IzY2E2NjEwZDE5NzNjZjVjOGRmNWIy
15
- MjdhMWE2ZmVlNmNiYzM1ZmFiZDM4ODlmZjU5ZjU1Y2UzYmQ3MGY=
13
+ ZmE4ZDljOGFlZWRhZWIyMTVkMjlhODAxMzFmYzM4MjIyNzgxZjY5NGRjODY2
14
+ ZDUxMmVlNTE3MjJkMWY1MGM3NWUzMmNmMjNjMmUxZDMyYmMyYjljNDU3ZWFk
15
+ NzQ1OTJmYTY4ZmNkYmRiNmQ0YjQ0ZjNmMWExY2QzZGFmZjRjMGU=
@@ -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] ||= Class.new do
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)
@@ -1,3 +1,3 @@
1
1
  module Kindah
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-05 00:00:00.000000000 Z
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katuv