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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5703250dc3600052cdd2e94d6398ff4fca22869e
4
- data.tar.gz: efae7bf1cddb58c243efd6fab692a36c4211a4af
3
+ metadata.gz: 753af569b03c348e343dfb8c565eda73738eb6e9
4
+ data.tar.gz: e4b930a8283dec3c1dc2947db8586029abe3f4c5
5
5
  SHA512:
6
- metadata.gz: ff2d98a02deecc13e60facc13b2131237fb9f985c1693d59b2f1d5951e3246a07fd59b9aa28da3404e264465cfed98dab5e317cdb74af9726a855019adcf56d9
7
- data.tar.gz: f9ac267230d2ac56f9087ef31a39aa68fcb31bcacd299c4aee60cc9f295ae52761f7380fa992b5052124ac9bd0b49bbfb4ceec183617a1b77e1b6362da4e813a
6
+ metadata.gz: acd69c80921e7c6e3e450a9f86603699e89b149601bbe2731cbba1f60945284480294004fca34ce3e47de6ba64bc18457353045b250efa3298c7b18eca20d5a6
7
+ data.tar.gz: 92e3df591da83882e052d07204362c8ea72ab368ab0014ebfc3864566916805a58b70cd30183f4cde85552e65d4f088a5843a13b0f63e40e7ab0f07f10daf868
data/CHANGELOG CHANGED
@@ -0,0 +1,3 @@
1
+ 0.1.1 / August 28, 2015
2
+
3
+ * automatically include gem without placing include call in the Class
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 include **StoreMethod** module to our model class, and add store_method call with a method name
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`.`avatar_url` = 'http://www.gravatar.com/avatar/fc383b8294226d72f3a7828eeef86987?d=https%3A%2F%2Fidenticons.github.com%2Ffc383b8294226d72f3a7828eeef86987.png&s=42' WHERE `users`.`id` = 1
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
- ## Caveats
68
+ ## Handling Arguments
70
69
 
71
- Arguments are also supported
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
@@ -1,3 +1,3 @@
1
1
  module StoreMethod
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/user.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
- include StoreMethod
3
2
  store_method :name
4
3
 
5
4
  def process(s)
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.0
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-25 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord