active_store_accessor 0.1.0 → 0.1.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 +0 -1
- data/Gemfile +1 -0
- data/README.md +32 -14
- data/active_store_accessor.gemspec +1 -1
- data/lib/active_store_accessor.rb +5 -0
- 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: 4292ddb949e1408e098e6b011b793712fac73aab
|
4
|
+
data.tar.gz: be546cf4e8bfc20c9ac95b42adaff2e45de4c29e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5430d75c6d0b771b4221b60356c7388881da5233b57815d1381ab170bb874a18a7eed652bbb7d730870c6056a08a5d861d81807329b765fd99e8d13f3d2e1f70
|
7
|
+
data.tar.gz: ee4f46f15a41cc510c488ea0cbb8a75629315bad8b1550b976e6bcfba01d16a58ace185ed205031a98f6764eb0df06eed4f95ea05e71c2e2b9c7d797fdf7bb9e
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
# ActiveStoreAccessor
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/jalkoby/active_store_accessor)
|
4
|
+
[](http://badge.fury.io/rb/active_store_accessor)
|
5
|
+
[](https://codeclimate.com/github/jalkoby/active_store_accessor)
|
6
|
+
|
7
|
+
With `active_store_accessor` you can have boolean, integer, float, time store attributes which would act like a regular schema columns.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
After you add gem into Gemfile everything is done for you. Now you can declare your serialized properties in a next way:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class Profile < ActiveRecord::Base
|
15
|
+
# basic usage(where `info` is a store column)
|
16
|
+
active_store_accessor :info, age: :integer, birthday: :time
|
17
|
+
|
18
|
+
# with default values
|
19
|
+
active_store_accessor :info, score: { type: :float, default: 0.0 },
|
20
|
+
active: { type: :boolean, default: true }
|
21
|
+
end
|
22
|
+
|
23
|
+
profile = Profile.new
|
24
|
+
profile.age = "23"
|
25
|
+
profile.age # => 23
|
26
|
+
profile.birthday = Time.new(2014, 5, 31)
|
27
|
+
profile.birthday # => 2014-05-31 00:00:00
|
28
|
+
profile.score # => 0.0
|
29
|
+
profile.score = 4.5
|
30
|
+
profile.score # => 4.5
|
31
|
+
```
|
4
32
|
|
5
33
|
## Installation
|
6
34
|
|
@@ -11,20 +39,10 @@ Add this line to your application's Gemfile:
|
|
11
39
|
And then execute:
|
12
40
|
|
13
41
|
$ bundle
|
42
|
+
|
43
|
+
## Requirements & dependencies
|
14
44
|
|
15
|
-
|
16
|
-
|
17
|
-
$ gem install active_store_accessor
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
After you add gem into Gemfile everything is done for you. Now you can declare your serialized properties in a next way:
|
22
|
-
|
23
|
-
# basic usage(where `info` is a store column)
|
24
|
-
active_store_accessor :info, age: :integer, birthday: :time
|
25
|
-
|
26
|
-
# with default values
|
27
|
-
active_store_accessor :info, score: { type: :float, default: 0.0 }, active: { type: :boolean, default: true }
|
45
|
+
This library has been tested on ruby 1.9.3+ and activerecord 3.2+. 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.
|
28
46
|
|
29
47
|
## Contributing
|
30
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.1"
|
8
8
|
spec.authors = ["Sergey Pchelincev"]
|
9
9
|
spec.email = ["mail@sergeyp.me"]
|
10
10
|
spec.summary = %q{Get more from ActiveRecord::Store}
|
@@ -10,6 +10,11 @@ module ActiveStoreAccessor
|
|
10
10
|
attrs.each do |attr_name, options|
|
11
11
|
options = { type: options.to_s } unless options.is_a?(Hash)
|
12
12
|
type = options.fetch(:type) { raise ArgumentError, "please specify type of attribute" }.to_s
|
13
|
+
|
14
|
+
# time for activerecord is only a hours and minutes without date part
|
15
|
+
# but for most rubist and rails developer it should contains a date too
|
16
|
+
type = :datetime if type == :time
|
17
|
+
|
13
18
|
args = [attr_name.to_s, options[:default], type]
|
14
19
|
active_store_attributes[attr_name] = ActiveRecord::ConnectionAdapters::Column.new(*args)
|
15
20
|
|