typed-class 0.5.0 → 0.5.1
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.
- data/lib/typed_class/typed_class.rb +5 -4
- metadata +3 -3
@@ -1,7 +1,6 @@
|
|
1
1
|
class TypedClass
|
2
2
|
|
3
3
|
@@map = {}
|
4
|
-
@@metadata = nil
|
5
4
|
|
6
5
|
def after_initialize
|
7
6
|
metadata = @@map[self.class.to_s.to_sym]
|
@@ -15,6 +14,7 @@ class TypedClass
|
|
15
14
|
::TypedClassInternal::Util.assert_class(child, Class)
|
16
15
|
::TypedClassInternal::Util.check_state(child.superclass == TypedClass,
|
17
16
|
"Class must extend TypedClass directly")
|
17
|
+
|
18
18
|
@@metadata = @@map[child.to_s.to_sym]
|
19
19
|
if @@metadata.nil?
|
20
20
|
@@map[child.to_s.to_sym] = @@metadata = TypedClassInternal::Metadata.new(child)
|
@@ -28,7 +28,8 @@ class TypedClass
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def TypedClass.field(attr_name, attr_klass, opts={})
|
31
|
-
|
31
|
+
metadata = @@map[self.to_s.to_sym]
|
32
|
+
::TypedClassInternal::Util.check_state(metadata, "No metadata for klass[%s]" % self)
|
32
33
|
::TypedClassInternal::Util.assert_class(attr_name, Symbol)
|
33
34
|
default = opts.delete(:default)
|
34
35
|
::TypedClassInternal::Util.assert_empty_opts(opts)
|
@@ -49,8 +50,8 @@ class TypedClass
|
|
49
50
|
"Required fields cannot have defaults. Class[%s] Field[%s] Default[%s]" % [klass.name, attr_name, default])
|
50
51
|
|
51
52
|
attr = ::TypedClassInternal::Attribute.new(attr_name, klass, :default => default, :optional => optional)
|
52
|
-
|
53
|
-
TypedClass.rewrite_constructor(
|
53
|
+
metadata.add_attribute(attr)
|
54
|
+
TypedClass.rewrite_constructor(metadata)
|
54
55
|
end
|
55
56
|
|
56
57
|
def TypedClass.get_default(klass, attr_name)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed-class
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Bryzek
|