cachethod 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzBhZGIxMGYzMDQxMDY1ZjJmZDRlOGQyZTRjMjg2MWVhM2UxNzA2OQ==
5
- data.tar.gz: !binary |-
6
- Yjc1Nzc1MGQ1MGNjZDE4OGUxMmE2MGI5MjIwNzQ4ODBhMTM3NmVlZA==
2
+ SHA1:
3
+ metadata.gz: 6ae6f370ef22bcd730734e8b47c157eddbb2d0a8
4
+ data.tar.gz: abaed30fc1104703aac1089307486d3bd72392cd
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGQ5N2JiOWM0MGU2N2VkZWFlODQ0Y2NjZGQ1Y2E0N2Y1ZjA2MmQ4NDhhMjFm
10
- MjFjYjA5MDdlYzgyNjA3NjFiYzE3OWZmMjBkZTYxNDk2MTVlZjdiMGY5YTI4
11
- YmE3ODFlNWZjOTdmZDk1ZTY3YThmMmM3NTBlODhhZmY3ZWNiNjM=
12
- data.tar.gz: !binary |-
13
- NWFiOTZjMTYwMWRlNjk5NTAwMDk2MTM0MmIxZThiZWViM2E3Y2FlYTA5Yjc1
14
- ZmUyYmRjOGE3ODUyN2IwNTVjYmZhNzRiZmFiMGViMjRmNjVhMzA4MmYwZDAw
15
- YWE2MGZiMWE2MDIxMGYyNzJmYWUxOTQ4ZjdhMWJmNzJjZTdiNTQ=
6
+ metadata.gz: d91634138c74a0f2385c99a367fa029b1aac6859aa45c16a03f914d549b1bb6f46734c45af355e526603ef6c09fd3489fa57dafbdd294758954b4b5ab8dfaffa
7
+ data.tar.gz: b97b5c0b93c060384921dc749c823c40884b214d0f09557b708827c144e5e2ac3d4ce275f30cc8d12b5248e8f591db19c4688416bfb3c9400fe51f0219d88497
data/README.md CHANGED
@@ -19,7 +19,7 @@ will be reflected also on Cachethod methods.
19
19
  In Gemfile
20
20
 
21
21
  ```ruby
22
- gem 'cachethod', '~> 0.1.2'
22
+ gem 'cachethod', '~> 0.2.0'
23
23
  ```
24
24
 
25
25
  Then run
@@ -87,6 +87,22 @@ If you want to access uncached version of your method then you can do:
87
87
  user.some_io_method!
88
88
  ```
89
89
 
90
+ ## Caching class methods
91
+
92
+ ```ruby
93
+ class Apple < ActiveRecord::Base
94
+ class << self
95
+ include Cachethod
96
+
97
+ def kinds
98
+ ...
99
+ end
100
+ end
101
+
102
+ cache_class_method :kinds, expires_in: 10.minutes
103
+ end
104
+ ```
105
+
90
106
  ## Result
91
107
 
92
108
  For example it translates following code:
data/lib/cachethod.rb CHANGED
@@ -4,6 +4,23 @@ module Cachethod
4
4
  end
5
5
 
6
6
  module ClassMethods
7
+ def cache_class_method names, *args
8
+ [*names].each do |name|
9
+ define_singleton_method "#{name}_cached" do
10
+ cache_key = "cachethod.#{self.class.to_s.underscore}.self."
11
+ cache_key += "#{hash}.#{name}."
12
+ cache_key += args.hash.to_s
13
+
14
+ Rails.cache.fetch(cache_key, *args) do
15
+ send("#{name}!")
16
+ end
17
+ end
18
+
19
+ self.singleton_class.send(:alias_method, "#{name}!", name)
20
+ self.singleton_class.send(:alias_method, name, "#{name}_cached")
21
+ end
22
+ end
23
+
7
24
  def cache_method names, *args
8
25
  @methods_to_cache ||= {}
9
26
 
@@ -19,6 +36,7 @@ module Cachethod
19
36
  alias_method :cache_methods, :cache_method
20
37
  alias_method :cachethod, :cache_method
21
38
  alias_method :cachethods, :cache_method
39
+ alias_method :cache_class_methods, :cache_class_method
22
40
 
23
41
  def method_added name
24
42
  super
@@ -1,3 +1,3 @@
1
1
  module Cachethod
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachethod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene Klacan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3'
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
26
  version: '3'
27
27
  - !ruby/object:Gem::Dependency
@@ -45,13 +45,13 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - LICENSE
49
- - README.md
50
- - Rakefile
51
48
  - lib/cachethod.rb
52
49
  - lib/cachethod/version.rb
53
- - test/cachethod_test.rb
50
+ - LICENSE
51
+ - Rakefile
52
+ - README.md
54
53
  - test/test_helper.rb
54
+ - test/cachethod_test.rb
55
55
  homepage: https://github.com/reneklacan/cachethod
56
56
  licenses:
57
57
  - MIT
@@ -62,17 +62,17 @@ require_paths:
62
62
  - lib
63
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ! '>='
65
+ - - '>='
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.9'
68
68
  required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ! '>='
70
+ - - '>='
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
74
  rubyforge_project:
75
- rubygems_version: 2.2.2
75
+ rubygems_version: 2.0.14
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Rails plugin for caching model methods