storext 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 +4 -4
- data/MIT-LICENSE +1 -1
- data/lib/storext.rb +5 -47
- data/lib/storext/attribute_proxy.rb +19 -0
- data/lib/storext/class_methods.rb +49 -0
- data/lib/storext/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22c7d4f570b492d0b65ab410d07666166d5f7000
|
4
|
+
data.tar.gz: bb7d5731d7bac0767f0d9f2d507d3797c362cf5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf6a0cc7a094a5618171ca25e2fd6615cbafcb949eab5e6f5e0692b8dbc91edd77c47b7fe2ec0423f145149f6d680122495995122e2c9abf884bdfe71801adec
|
7
|
+
data.tar.gz: 4c6186c3626901832e5f212cbb048ca9193fc22b6dbab4c995559d4ff8e64c37050945a3f55fc93ab543d7e1ffa53ab93d721de0d210dc89e047ee895570abd2
|
data/MIT-LICENSE
CHANGED
data/lib/storext.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "active_support/concern"
|
2
2
|
require "virtus"
|
3
|
+
require "storext/attribute_proxy"
|
4
|
+
require "storext/class_methods"
|
3
5
|
|
4
6
|
module Storext
|
5
7
|
|
@@ -12,53 +14,9 @@ module Storext
|
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
|
-
def
|
16
|
-
return @
|
17
|
-
@
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
def store_attribute(column, attr, type=nil, opts={})
|
22
|
-
store_attribute_defs[column] ||= []
|
23
|
-
store_attribute_defs[column] << attr
|
24
|
-
|
25
|
-
storext_proxy_class.attribute "_casted_#{attr}", type, opts
|
26
|
-
|
27
|
-
define_method "#{attr}=" do |value|
|
28
|
-
storext_proxy.send("_casted_#{attr}=", value)
|
29
|
-
write_store_attribute column, attr, storext_proxy.send("_casted_#{attr}")
|
30
|
-
end
|
31
|
-
|
32
|
-
define_method attr do
|
33
|
-
if store_val = read_store_attribute(column, attr)
|
34
|
-
storext_proxy.send("_casted_#{attr}=", store_val)
|
35
|
-
end
|
36
|
-
storext_proxy.send("_casted_#{attr}")
|
37
|
-
end
|
38
|
-
|
39
|
-
store_accessor column, *store_attribute_defs[column]
|
40
|
-
end
|
41
|
-
|
42
|
-
def store_attributes(column, &block)
|
43
|
-
storext_proxy_class.define_store_attributes self, column, &block
|
44
|
-
end
|
45
|
-
|
46
|
-
def storext_proxy_class
|
47
|
-
@storext_proxy_class ||= Class.new do
|
48
|
-
include Virtus.model
|
49
|
-
|
50
|
-
def self.define_store_attributes(source_class, column, &block)
|
51
|
-
@source_class = source_class
|
52
|
-
@column = column
|
53
|
-
instance_eval &block
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.method_missing(method_name, *args, &block)
|
57
|
-
@source_class.store_attribute @column, method_name, *args
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
17
|
+
def storext_cast_proxy
|
18
|
+
return @storext_cast_proxy if @storext_cast_proxy
|
19
|
+
@storext_cast_proxy ||= self.class.storext_cast_proxy_class.new
|
62
20
|
end
|
63
21
|
|
64
22
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Storext
|
2
|
+
class AttributeProxy
|
3
|
+
|
4
|
+
def initialize(source_class, column, &block)
|
5
|
+
@source_class = source_class
|
6
|
+
@column = column
|
7
|
+
@block = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_store_attribute
|
11
|
+
instance_eval &@block
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method_name, *args, &block)
|
15
|
+
@source_class.store_attribute @column, method_name, *args
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Storext
|
2
|
+
module ClassMethods
|
3
|
+
|
4
|
+
def storext_define_writer(column, attr)
|
5
|
+
define_method "#{attr}=" do |value|
|
6
|
+
storext_cast_proxy.send("_casted_#{attr}=", value)
|
7
|
+
write_store_attribute(column,
|
8
|
+
attr,
|
9
|
+
storext_cast_proxy.send("_casted_#{attr}"))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def storext_define_reader(column, attr)
|
14
|
+
define_method attr do
|
15
|
+
if store_val = read_store_attribute(column, attr)
|
16
|
+
storext_cast_proxy.send("_casted_#{attr}=", store_val)
|
17
|
+
end
|
18
|
+
storext_cast_proxy.send("_casted_#{attr}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def store_attribute(column, attr, type=nil, opts={})
|
23
|
+
track_store_attribute(column, attr)
|
24
|
+
|
25
|
+
storext_cast_proxy_class.attribute "_casted_#{attr}", type, opts
|
26
|
+
|
27
|
+
storext_define_writer(column, attr)
|
28
|
+
storext_define_reader(column, attr)
|
29
|
+
|
30
|
+
store_accessor column, *store_attribute_defs[column]
|
31
|
+
end
|
32
|
+
|
33
|
+
def store_attributes(column, &block)
|
34
|
+
AttributeProxy.new(self, column, &block).define_store_attribute
|
35
|
+
end
|
36
|
+
|
37
|
+
def track_store_attribute(column, attr)
|
38
|
+
store_attribute_defs[column] ||= []
|
39
|
+
store_attribute_defs[column] << attr
|
40
|
+
end
|
41
|
+
|
42
|
+
def storext_cast_proxy_class
|
43
|
+
@storext_cast_proxy_class ||= Class.new do
|
44
|
+
include Virtus.model
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
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: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2014-11-
|
13
|
+
date: 2014-11-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- MIT-LICENSE
|
81
81
|
- Rakefile
|
82
82
|
- lib/storext.rb
|
83
|
+
- lib/storext/attribute_proxy.rb
|
84
|
+
- lib/storext/class_methods.rb
|
83
85
|
- lib/storext/version.rb
|
84
86
|
- lib/tasks/storext_tasks.rake
|
85
87
|
homepage: http://github.com/g5/storext
|