active_store_accessor 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -3
- data/Gemfile +4 -4
- data/README.md +4 -4
- data/active_store_accessor.gemspec +2 -2
- data/lib/active_store_accessor.rb +6 -1
- data/tests/lib/active_store_accessor_test.rb +8 -1
- data/tests/test_helper.rb +10 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21798f125f793a3a4f664dd3c005871f64228658
|
4
|
+
data.tar.gz: 8c0f9fabb18aa63200c14889911b86a346f3603d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30bd5cc30e6d13bc183c0889d2f19ebb9163e0bdf69c163ff63481ace00f76a4e9f3b2c460fc0ec1349b72be28ada3e2a214c17d885764135ae6b75ece8684f5
|
7
|
+
data.tar.gz: d513515b3108bf6d697b59112e58f16f2cbcfce679d3fa9c4fadc3505f36e8ecd930ebe3b9459766b9fe80ad87e87753e01139ad16596a36ed32bf0dfd00c624
|
data/.travis.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
env:
|
2
|
-
- "
|
3
|
-
- "
|
4
|
-
- "RAILS_VERSION=master"
|
2
|
+
- "AR_VERSION=4.0"
|
3
|
+
- "AR_VERSION=4.1"
|
5
4
|
rvm:
|
6
5
|
- 1.9.3
|
7
6
|
- 2.0.0
|
8
7
|
- 2.1.2
|
8
|
+
addons:
|
9
|
+
postgresql: "9.3"
|
10
|
+
before_script:
|
11
|
+
- psql -c 'create database asa_test;' -U rails
|
data/Gemfile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in active_store_accessor.gemspec
|
4
|
-
gemspec
|
5
4
|
|
6
5
|
ar_version = ENV["AR_VERSION"]
|
7
6
|
ar_version = case ar_version
|
8
|
-
when "3.2" then "~> 3.2.0"
|
9
7
|
when "4.0" then "~> 4.0.0"
|
10
8
|
else
|
11
9
|
"~> 4.1.0"
|
12
10
|
end
|
13
|
-
gem "activerecord", ar_version
|
14
|
-
gem "
|
11
|
+
gem "activerecord", ar_version, require: ["active_record", "active_support/all"]
|
12
|
+
gem "pg"
|
13
|
+
|
14
|
+
gemspec
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/active_store_accessor.svg)](http://badge.fury.io/rb/active_store_accessor)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/jalkoby/active_store_accessor.png)](https://codeclimate.com/github/jalkoby/active_store_accessor)
|
6
6
|
|
7
|
-
With `active_store_accessor` you can have boolean, integer, float, time store attributes which would act like a regular schema columns.
|
7
|
+
With `active_store_accessor` you can have boolean, integer, float, time store attributes which would act like a regular schema columns.
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
@@ -16,7 +16,7 @@ class Profile < ActiveRecord::Base
|
|
16
16
|
active_store_accessor :info, age: :integer, birthday: :time
|
17
17
|
|
18
18
|
# with default values
|
19
|
-
active_store_accessor :info, score: { type: :float, default: 0.0 },
|
19
|
+
active_store_accessor :info, score: { type: :float, default: 0.0 },
|
20
20
|
active: { type: :boolean, default: true }
|
21
21
|
end
|
22
22
|
|
@@ -39,10 +39,10 @@ Add this line to your application's Gemfile:
|
|
39
39
|
And then execute:
|
40
40
|
|
41
41
|
$ bundle
|
42
|
-
|
42
|
+
|
43
43
|
## Requirements & dependencies
|
44
44
|
|
45
|
-
This library has been tested on ruby 1.9.3+ and activerecord
|
45
|
+
This library has been tested on ruby 1.9.3+ and activerecord 4.0+. Any other configurations might have potential issues. `active_store_accessor` doesn't have any external dependency(expect activerecord) and contains only one file with one module.
|
46
46
|
|
47
47
|
## Contributing
|
48
48
|
|
@@ -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.1.
|
7
|
+
spec.version = "0.1.2"
|
8
8
|
spec.authors = ["Sergey Pchelincev"]
|
9
9
|
spec.email = ["mail@sergeyp.me"]
|
10
10
|
spec.summary = %q{Get more from ActiveRecord::Store}
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "activerecord", ">=
|
20
|
+
spec.add_dependency "activerecord", ">= 4.0"
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "minitest", ">= 4.7"
|
@@ -6,7 +6,12 @@ module ActiveStoreAccessor
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def active_store_accessor(column_name, attrs)
|
9
|
-
|
9
|
+
if columns.detect { |column| column.name == column_name.to_s }.text?
|
10
|
+
serialize(column_name) unless serialized_attributes.include?(column_name.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
store_accessor column_name, *attrs.keys
|
14
|
+
|
10
15
|
attrs.each do |attr_name, options|
|
11
16
|
options = { type: options.to_s } unless options.is_a?(Hash)
|
12
17
|
type = options.fetch(:type) { raise ArgumentError, "please specify type of attribute" }.to_s
|
@@ -20,7 +20,7 @@ describe ActiveStoreAccessor do
|
|
20
20
|
assert_equal profile.score, 100
|
21
21
|
assert_equal profile.rank, 3213.312
|
22
22
|
assert_equal profile.birthday, Time.utc(2014, 5, 12)
|
23
|
-
|
23
|
+
assert profile.confirmed
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should support model inheritance" do
|
@@ -29,4 +29,11 @@ describe ActiveStoreAccessor do
|
|
29
29
|
assert_equal admin_profile.age, 23
|
30
30
|
assert_equal admin_profile.level, 5
|
31
31
|
end
|
32
|
+
|
33
|
+
it "handles properly hstore" do
|
34
|
+
profile = Profile.create(active: true, pi: 3.14)
|
35
|
+
|
36
|
+
assert profile.active
|
37
|
+
assert_equal profile.pi, 3.14
|
38
|
+
end
|
32
39
|
end
|
data/tests/test_helper.rb
CHANGED
@@ -2,12 +2,18 @@ require "minitest/autorun"
|
|
2
2
|
require "active_record"
|
3
3
|
require "active_store_accessor"
|
4
4
|
|
5
|
-
ActiveRecord::Base.establish_connection(adapter: '
|
5
|
+
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'asa_test', user: 'rails')
|
6
6
|
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
7
|
+
ActiveRecord::Base.connection.execute "drop schema public cascade"
|
8
|
+
ActiveRecord::Base.connection.execute "create schema public"
|
9
|
+
ActiveRecord::Base.connection.execute "CREATE EXTENSION IF NOT EXISTS hstore"
|
7
10
|
|
8
11
|
ActiveRecord::Schema.define do
|
12
|
+
enable_extension "hstore"
|
13
|
+
|
9
14
|
create_table :profiles do |t|
|
10
15
|
t.text :info
|
16
|
+
t.hstore :keys
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
@@ -16,6 +22,9 @@ class Profile < ActiveRecord::Base
|
|
16
22
|
active_store_accessor :info, rank: :float
|
17
23
|
active_store_accessor :info, birthday: :time
|
18
24
|
active_store_accessor :info, confirmed: :boolean
|
25
|
+
|
26
|
+
active_store_accessor :keys, active: :boolean
|
27
|
+
active_store_accessor :keys, pi: :float
|
19
28
|
end
|
20
29
|
|
21
30
|
class AdminProfile < Profile
|
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.1.
|
4
|
+
version: 0.1.2
|
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-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|