storext 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/storext/class_methods.rb +6 -6
- data/lib/storext/instance_methods.rb +31 -10
- data/lib/storext/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 575cadf889b06670fee076e367dbdd98f65dacdd
|
4
|
+
data.tar.gz: 9f16efe7dbfae9cd8c5982d84c2e8fc78f53c9bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 095db2aa2daefcd5b1f9202e43a9eccae3a7cd7341aa0ac335457c3560fb84456ffc88b21144fa7cac518cf4c6f044321568af3649783bbfb3f7f8ef9113d148
|
7
|
+
data.tar.gz: be9f734f099a4597ef6a8bf4b1862f1484598edb5d563fb6bf9e083cc24eb239098a207c9dfd72a3d0833ee072cfb5aedc9ecd5f4e649c3b8006c6c0637aaf75
|
@@ -3,10 +3,10 @@ module Storext
|
|
3
3
|
|
4
4
|
def storext_define_writer(column, attr)
|
5
5
|
define_method "#{attr}=" do |value|
|
6
|
-
storext_cast_proxy(attr).send("
|
6
|
+
storext_cast_proxy(attr).send("#{attr}=", value)
|
7
7
|
send("#{column}=", send(column) || {})
|
8
8
|
|
9
|
-
attr_value = storext_cast_proxy(attr).send(
|
9
|
+
attr_value = storext_cast_proxy(attr).send(attr)
|
10
10
|
write_store_attribute column, attr, value
|
11
11
|
send(column)[attr.to_s] = value
|
12
12
|
end
|
@@ -16,9 +16,9 @@ module Storext
|
|
16
16
|
define_method attr do
|
17
17
|
if send(column) && send(column).has_key?(attr.to_s)
|
18
18
|
store_val = read_store_attribute(column, attr)
|
19
|
-
storext_cast_proxy(attr).send("
|
19
|
+
storext_cast_proxy(attr).send("#{attr}=", store_val)
|
20
20
|
end
|
21
|
-
storext_cast_proxy(attr).send("
|
21
|
+
storext_cast_proxy(attr).send("#{attr}")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -60,8 +60,8 @@ module Storext
|
|
60
60
|
|
61
61
|
def storext_check_attr_validity(attr, type, opts)
|
62
62
|
storext_cast_proxy_class = Class.new { include Virtus.model }
|
63
|
-
storext_cast_proxy_class.attribute
|
64
|
-
unless storext_cast_proxy_class.instance_methods.include?
|
63
|
+
storext_cast_proxy_class.attribute attr, type, opts
|
64
|
+
unless storext_cast_proxy_class.instance_methods.include? attr
|
65
65
|
raise ArgumentError, "problem defining `#{attr}`. `#{type}` may not be a valid type."
|
66
66
|
end
|
67
67
|
end
|
@@ -38,7 +38,7 @@ module Storext
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def default_store_value(attr)
|
41
|
-
storext_cast_proxy(attr).send(
|
41
|
+
storext_cast_proxy(attr).send(attr)
|
42
42
|
end
|
43
43
|
|
44
44
|
def storext_cast_proxy(attr)
|
@@ -47,18 +47,39 @@ module Storext
|
|
47
47
|
else
|
48
48
|
@storext_cast_proxies ||= {}
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
50
|
+
definition = self.class.storext_definitions[attr]
|
51
|
+
klass = storext_create_proxy_class(attr, definition)
|
53
52
|
|
54
|
-
klass.
|
55
|
-
|
56
|
-
|
57
|
-
self.class.storext_definitions[attr][:opts],
|
58
|
-
)
|
53
|
+
@storext_cast_proxies[attr] = klass.new(source: self)
|
54
|
+
end
|
55
|
+
end
|
59
56
|
|
60
|
-
|
57
|
+
def storext_create_proxy_class(attr, definition)
|
58
|
+
klass = Class.new do
|
59
|
+
include Virtus.model
|
60
|
+
|
61
|
+
attribute :source
|
61
62
|
end
|
63
|
+
|
64
|
+
klass.attribute(
|
65
|
+
attr,
|
66
|
+
definition[:type],
|
67
|
+
definition[:opts].merge(default: :compute_default),
|
68
|
+
)
|
69
|
+
|
70
|
+
klass.send :define_method, :compute_default do
|
71
|
+
default_value = definition[:opts][:default]
|
72
|
+
if default_value.is_a?(Symbol)
|
73
|
+
source.send(default_value)
|
74
|
+
elsif default_value.respond_to?(:call)
|
75
|
+
attribute = self.class.attribute_set[attr]
|
76
|
+
default_value.call(source, attribute)
|
77
|
+
else
|
78
|
+
default_value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
klass
|
62
83
|
end
|
63
84
|
|
64
85
|
end
|
data/lib/storext/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- G5
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-04-
|
13
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|