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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmExYmM3NGQ1MTVhOWM3NTI3OWExZjFkYWFiZDBiZDUwMTc0ZmViNA==
4
+ ZGMzNTYyYmRmMzZiN2I2NjAzZWVjZDJkNTRhMzQwOGUyMjFmZThhZA==
5
5
  data.tar.gz: !binary |-
6
- ZmRhYjg3MmY4ZWI2NzM3YTdiMTc1MDIxNTExY2Y4MWE3OWY5ODg2NA==
6
+ MmM4MmM4NjM3NTE1M2I3YTdmYjdlOGQwOTJiNmMyZTAyYzQzNDNkMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODk0ZmQzZGVmYzE2MDk5MjQ4MTIzNDlmNDVlZmNkYjJlMmYyZTJjMWZmNGZi
10
- MzIyZThhYTEzMDNhOGZiNGQwYjhkNjkyYWY2OTczMDEwZjExZDMxZTcxODU1
11
- YzM2ZGFkODc0MmRlNzQ2YmYyNjY0OWU4MWJiOWViZjFhOTgxNDc=
9
+ ZTI4NzMxMDZlNDI1OTA2Y2JiMTE2OThmMGY4MTg3NjY3ZTI4YmQ0NzcwYWEx
10
+ N2FhYzUyNzhiNTlkOWJlZmEzYTE5OWVkMzk0YTY5MTNjMGE1NWVjMTQ1ODdh
11
+ ZmQ5ZTczNDQ0MTZjMjU4ODY3ODhlY2U3MDc1NDk5ZjY1NTg1ODk=
12
12
  data.tar.gz: !binary |-
13
- MDQ4NWUxYmEzMTEyNWJiYmI1ZjczZDgwNGU2OTU1N2YyY2E2OTU3YTcwOWM4
14
- OGUzZjUyZjZhMGI5NmExZTRkOTI2Y2YwMmM5NzljNDlkYWUwMmNhNDJkMTJi
15
- ODdkOTIxMzg1OTYxZTk5MDFmNzNlMmZiZDkwZWVjM2YzYmZiZjY=
13
+ ZTIwNGY4MjFkMmZkNmM2NWY0YzdhY2FkNmVmOTUxNmZkNjdkYTZkZjUxMTJm
14
+ MzgxMDQ2MDRjZWNjYjYzZjdmYzhkOTNhZDUyZmNhMDczYWUxMGVkYmQxOTAz
15
+ NTkzM2JkNmZkZjcxZTNlNTU5YzZmYmJmNmVjYTNkNGFmY2ViZTY=
@@ -1,4 +1,5 @@
1
1
  require 'kindah/ast/instance_methods'
2
2
  require 'kindah/ast/class_methods'
3
+ require 'kindah/ast/superklass'
3
4
 
4
5
  require 'kindah/ast/class_template'
@@ -2,6 +2,7 @@ module Kindah
2
2
  class ClassTemplate
3
3
  include Katuv::Node
4
4
 
5
+ terminal Superklass
5
6
  terminal ClassMethods
6
7
  terminal InstanceMethods
7
8
  end
@@ -0,0 +1,11 @@
1
+ module Kindah
2
+ class Superklass
3
+ include Katuv::Node
4
+
5
+ terminal!
6
+
7
+ def self.name
8
+ 'superclass'
9
+ end
10
+ end
11
+ end
@@ -11,5 +11,9 @@ module Kindah
11
11
  def self.storage
12
12
  @storage ||= {}
13
13
  end
14
+
15
+ def self.clear!
16
+ @storage = {}
17
+ end
14
18
  end
15
19
  end
@@ -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 proc {} unless children.has_key?(klass)
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
@@ -1,3 +1,3 @@
1
1
  module Kindah
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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 }
@@ -22,6 +22,10 @@ describe Kindah do
22
22
  end
23
23
  end
24
24
  end
25
+ after :all do
26
+ Object.class_eval { undef Test }
27
+ Kindah::Cache.clear!
28
+ end
25
29
 
26
30
  subject(:test_instance) { Test(1).new }
27
31
 
@@ -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.3
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