store_method 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/CHANGELOG +3 -0
- data/README.markdown +34 -5
- data/lib/store_method.rb +2 -4
- data/lib/version.rb +1 -1
- data/spec/user.rb +0 -1
- 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: 753af569b03c348e343dfb8c565eda73738eb6e9
|
4
|
+
data.tar.gz: e4b930a8283dec3c1dc2947db8586029abe3f4c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acd69c80921e7c6e3e450a9f86603699e89b149601bbe2731cbba1f60945284480294004fca34ce3e47de6ba64bc18457353045b250efa3298c7b18eca20d5a6
|
7
|
+
data.tar.gz: 92e3df591da83882e052d07204362c8ea72ab368ab0014ebfc3864566916805a58b70cd30183f4cde85552e65d4f088a5843a13b0f63e40e7ab0f07f10daf868
|
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -37,11 +37,10 @@ rails g migration AddGravatarURLToUsers gravatar_url:string
|
|
37
37
|
|
38
38
|
(Notice that database column type should match the type that our method returns, any valid column type is supported)
|
39
39
|
|
40
|
-
Then
|
40
|
+
Then add store_method call with a method name
|
41
41
|
|
42
42
|
```ruby
|
43
43
|
class User < ActiveRecord::Base
|
44
|
-
include StoreMethod
|
45
44
|
store_method :gravatar_url
|
46
45
|
|
47
46
|
def gravatar_url
|
@@ -61,14 +60,44 @@ In case if you need to refresh stored value, call stored method with "refresh_"
|
|
61
60
|
```ruby
|
62
61
|
user = User.first
|
63
62
|
user.refresh_gravatar_url
|
64
|
-
SQL (5.7ms) UPDATE `users` SET `users`.`
|
63
|
+
SQL (5.7ms) UPDATE `users` SET `users`.`gravatar_url` = 'http://www.gravatar.com/avatar/fc383b8294226d72f3a7828eeef86987?d=https%3A%2F%2Fidenticons.github.com%2Ffc383b8294226d72f3a7828eeef86987.png&s=42' WHERE `users`.`id` = 1
|
65
64
|
=> "http://www.gravatar.com/avatar/fc383b8294226d72f3a7828eeef86987?d=https%3A%2F%2Fidenticons.github.com%2Ffc383b8294226d72f3a7828eeef86987.png&s=42"
|
66
65
|
```
|
67
66
|
|
68
67
|
|
69
|
-
##
|
68
|
+
## Handling Arguments
|
70
69
|
|
71
|
-
|
70
|
+
Calling stored method with arguments passes these arguments to original method:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
class Item < ActiveRecord::Base
|
74
|
+
store_method :friends_count
|
75
|
+
|
76
|
+
def friends_count(degree = 1)
|
77
|
+
...
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
This call returns default (stored) value:
|
83
|
+
```ruby
|
84
|
+
user.friends_count
|
85
|
+
=>
|
86
|
+
100
|
87
|
+
```
|
88
|
+
|
89
|
+
This call returns new value calculated using degree argument:
|
90
|
+
```ruby
|
91
|
+
user.friends_count(5)
|
92
|
+
=>
|
93
|
+
100500
|
94
|
+
```
|
95
|
+
|
96
|
+
Notice that passing argument won't update stored value.
|
97
|
+
|
98
|
+
## ToDo List
|
99
|
+
* Implement some checks to ensure that method names match DB columns
|
100
|
+
* Implement some automation for adding new DB fields
|
72
101
|
|
73
102
|
## Contributing to store_method
|
74
103
|
|
data/lib/store_method.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
module StoreMethod
|
2
|
-
def self.included base
|
3
|
-
base.extend ClassMethods
|
4
|
-
end
|
5
|
-
|
6
2
|
module ClassMethods
|
7
3
|
def store_method *names
|
8
4
|
@methods_to_store ||= {}
|
@@ -57,3 +53,5 @@ module StoreMethod
|
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|
56
|
+
|
57
|
+
ActiveRecord::Base.send(:extend, StoreMethod::ClassMethods)
|
data/lib/version.rb
CHANGED
data/spec/user.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaly Fomichov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|