active_store_accessor 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile +1 -0
- data/active_store_accessor.gemspec +1 -1
- data/lib/active_store_accessor.rb +23 -11
- 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: 3d80e0a2c9f3bf1d6fde04802b05c5d01f89f179
|
4
|
+
data.tar.gz: 92665c56d16926a3b909c0d45650f0a6032ffe26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b91de091930c91921061b8dd70713b3c568bb6e4c8c29009fa191f49ceac194782e27e2c3132cbff2ac542b97b6e563da4d54e73a5bd7e6d94772a567f29ed87
|
7
|
+
data.tar.gz: 82ea8763e58340fe731de04f2db72a2f6ed6bab7e1b1bfbba98199e89b9fee93a7e58639943bf8279f29734b2aeb2368951947b242690ecbd644583b9ac4f17d
|
data/.travis.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
env:
|
2
2
|
- "AR_VERSION=4.0"
|
3
3
|
- "AR_VERSION=4.1"
|
4
|
+
- "AR_VERSION=4.2"
|
4
5
|
rvm:
|
5
6
|
- 1.9.3
|
6
7
|
- 2.0.0
|
@@ -8,4 +9,4 @@ rvm:
|
|
8
9
|
addons:
|
9
10
|
postgresql: "9.3"
|
10
11
|
before_script:
|
11
|
-
- psql -c 'create database asa_test;' -U rails
|
12
|
+
- psql -c 'create database asa_test;' -U rails -d postgres
|
data/Gemfile
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "active_store_accessor"
|
7
|
-
spec.version = "0.2.
|
7
|
+
spec.version = "0.2.1"
|
8
8
|
spec.authors = ["Sergey Pchelincev"]
|
9
9
|
spec.email = ["mail@sergeyp.me"]
|
10
10
|
spec.summary = %q{Get more from ActiveRecord::Store}
|
@@ -6,7 +6,10 @@ module ActiveStoreAccessor
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def active_store_accessor(column_name, attrs)
|
9
|
-
|
9
|
+
column = columns.detect { |column| column.name == column_name.to_s }
|
10
|
+
if !column
|
11
|
+
raise "[active_store_accessor] The column '#{column_name}' does not exist in the model #{name}."
|
12
|
+
elsif column.type == :text
|
10
13
|
serialize(column_name) unless serialized_attributes.include?(column_name.to_s)
|
11
14
|
end
|
12
15
|
|
@@ -16,22 +19,31 @@ module ActiveStoreAccessor
|
|
16
19
|
options = { type: options.to_s } unless options.is_a?(Hash)
|
17
20
|
type = options.fetch(:type) { raise ArgumentError, "please specify type of `#{ attr_name }` attribute" }.to_s
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
config = if connection.respond_to?(:lookup_cast_type)
|
23
|
+
column = connection.lookup_cast_type(type)
|
24
|
+
[column.method(:type_cast_from_database), column.method(:type_cast_for_database)]
|
25
|
+
else
|
26
|
+
# time for activerecord is only a hours and minutes without date part
|
27
|
+
# but for most rubist and rails developer it should contains a date too
|
28
|
+
type = 'datetime' if type == 'time'
|
29
|
+
args = [attr_name.to_s, options[:default], type]
|
30
|
+
column = ActiveRecord::ConnectionAdapters::Column.new(*args)
|
31
|
+
[column.method(:type_cast), column.method(:type_cast_for_write)]
|
32
|
+
end
|
33
|
+
|
34
|
+
config << options[:default]
|
35
|
+
active_store_attributes[attr_name] = config
|
25
36
|
|
26
37
|
_active_store_accessor_module.module_eval <<-RUBY
|
27
38
|
def #{ attr_name }
|
28
|
-
|
29
|
-
value =
|
30
|
-
value.nil? ?
|
39
|
+
getter, _, default = self.class.active_store_attributes[:#{ attr_name }]
|
40
|
+
value = getter.call(super)
|
41
|
+
value.nil? ? default : value
|
31
42
|
end
|
32
43
|
|
33
44
|
def #{ attr_name }=(value)
|
34
|
-
|
45
|
+
_, setter, _ = self.class.active_store_attributes[:#{ attr_name }]
|
46
|
+
super setter.call(value)
|
35
47
|
end
|
36
48
|
RUBY
|
37
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_store_accessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pchelincev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|