raw_column 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/raw_column.rb +1 -1
- data/lib/raw_column/json_proxy.rb +7 -1
- data/lib/raw_column/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9d8db6b41c727a5c50f518652950c08b288099a
|
4
|
+
data.tar.gz: d414574955de138c130dd16e4c4e59ffc4332240
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcdec41913e1c0b7d2971257be40c229e2c63be1598d5858b59a6a3c159dd379122bb8307f3ac04fac896fd43f31f21ca0e560ccb658322cff8ff19362d81a75
|
7
|
+
data.tar.gz: 5fe00480f826961c3769022ed47f849e0ac04b97c103b5004059f2968c7f100fbf335c0b360d13f2ffdd03ecc1f5c2526e94ad8c5d97f280e43c5bf4e82eac34
|
data/lib/raw_column.rb
CHANGED
@@ -9,7 +9,7 @@ module RawColumn
|
|
9
9
|
|
10
10
|
def raw_column(*column_names)
|
11
11
|
class_eval do
|
12
|
-
column_names = [:content] if column_names.
|
12
|
+
column_names = [:content] if column_names.blank?
|
13
13
|
column_names.each do |column_name|
|
14
14
|
define_method :"raw_#{column_name}" do
|
15
15
|
JsonProxy.new(self, column_name)
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module RawColumn
|
2
2
|
|
3
|
+
class TypeCastError < StandardError; end
|
4
|
+
|
3
5
|
class JsonProxy
|
4
6
|
|
5
7
|
def initialize(record, column_name)
|
6
|
-
|
8
|
+
method = :"#{column_name}_before_type_cast"
|
9
|
+
unless record.respond_to?(method)
|
10
|
+
raise BeforeTypeCastError.new("your column must respond to #{method}")
|
11
|
+
end
|
12
|
+
@raw_content = record.send(method)
|
7
13
|
end
|
8
14
|
|
9
15
|
def as_json(*args)
|
data/lib/raw_column/version.rb
CHANGED