covercache 0.2.1 → 0.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDc3NGNkYmExMmJlMzJkYWExM2ZkZWFmYWQ4OTk4OGIyNjRmOTVjOA==
4
+ NGZmODIwZWVlNGQzZWM2ODlkOTU3OTg5NjhlZTk2ODMzMGZiNTM1NA==
5
5
  data.tar.gz: !binary |-
6
- ZDRmYzdhNzc4YmE0NDI3MTE0MzE5OGYyMjMxNTE1NjY3N2RjZjBlYg==
6
+ NWNjNGYwZGYzZWMyZDllY2VlNjYxMWZjZWQ5MTM4Y2QyNmNjM2ZiMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MGQyYWExYzdmZmNiODAzM2ZhOTA3ZjVlOTZiNmFlNzkzMGY0NjczNDRiNDM1
10
- ZWYxYzBlZjRiY2ZjNWNkMzg2ZTgwNDM2ZGRjZWM5NGQxOTVhY2I0ZjJlZGQw
11
- YzdkOTEzMTk5Y2VhN2YwNTgwMWU5YWRmZWRhMTU2YmE1ZDZmOGQ=
9
+ YWJlYzZlODI3ZWJiODEyYWE1ZWVhZTY4NzZkYWJjODhlYjAwOGEwYjhmZDJm
10
+ NzUwM2FmM2UyZjJmZTBiYTAwZTA0ODlhZWFhMTMyZjk4YWM1OTJhMTA0YzVi
11
+ NTdkMTBhODYzNTliYjM5NWMzMGE1MjVhYmRmOWYyY2Q5ZDk1ZmQ=
12
12
  data.tar.gz: !binary |-
13
- YTc0Yzk5ZDVhZTg3NzBkMzQxODQ5OGYwMzMyYjRmNDU0Mzc2OTYxNGFlMGQx
14
- OTA3NGI2YjI0NGJjZWEwMzIzZGFlMTcxYWNlYmMwNTFkNjQ1MmIyNWUxYzhj
15
- ZTk1YTNlYTVlMzBiNzMyNzg4N2UzMDkxOTI1OTJiNDg4ZTgyY2U=
13
+ OTA2ZmNiMmQwODJlNGMyNTUwODRiYTA2OTgzYmUzOTI4ZTUyZGQxMzY1MWFh
14
+ YTkzOGIyODY1ZDZjZmMwNjA0NDMwYzgyYTg3Y2UwYzU4NTg0NmE2YTllYWFm
15
+ ZjZjOWRkYmJlNzMzNjRlYTRjNzk0NWQ4N2RmYzIyNzg4ZmY4ZjQ=
@@ -1,3 +1,3 @@
1
1
  module Covercache
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
data/lib/covercache.rb CHANGED
@@ -106,14 +106,14 @@ module Covercache
106
106
  self.is_a?(Class) ? self : self.class
107
107
  end
108
108
 
109
- def extract_cache_key_from(*args)
110
- Array.wrap((args.last.delete(:cache_key) if args.last.is_a?(Hash)))
109
+ def extract_cache_key(*args)
110
+ [*(args.last.delete :cache_key if args.last.is_a?(Hash))]
111
111
  end
112
112
  end
113
113
 
114
114
  # == Defining Helper
115
115
  #
116
- module DefiningHelper
116
+ module DefiningHelper
117
117
  # Define and wrap methods or blocks
118
118
  def define_cached(method, *args, &block)
119
119
  options = args.extract_options!
@@ -123,7 +123,7 @@ module Covercache
123
123
  line = line.to_i
124
124
 
125
125
  covercache_method_arguments method, args, options, &block
126
- covercache_define_wrapper method, file, line, block_given?, is_class_method
126
+ covercache_define_wrapper method, file, line, is_class_method
127
127
  end
128
128
 
129
129
  def class_define_cached(method, *args, &block)
@@ -133,35 +133,31 @@ module Covercache
133
133
  end
134
134
 
135
135
  private
136
- def covercache_define_wrapper(method, file, line, with_block=false, is_class_method=false)
137
- cached_method = "cached_#{method}"
136
+ def covercache_define_wrapper(original_method, file, line, is_class_method = false)
137
+ method = "#{'self.' if is_class_method}cached_#{ original_method }"
138
138
 
139
- class_eval(<<-EOS, file, line - 2)
140
- def #{'self.' if is_class_method}#{cached_method}(*args, &block)
141
- settings = Array.wrap(#{cached_method}_settings[:args]) + extract_cache_key_from(*args)
142
- covercache(*settings, #{cached_method}_settings[:opts]) do
143
- if #{with_block}
144
- #{cached_method}_settings[:block].call(#{'self,' unless is_class_method}*args)
145
- else
146
- self.__send__ :#{method}, *args, &block
147
- end
148
- end
149
- end
139
+ class_eval <<-EOS, file, line - 2
140
+ def #{method}(*args, &block) # def cached_example(*args, &block)
141
+ options = Array(#{method}_data[:args]) + extract_cache_key(*args) # options = Array(cached_example_data[:args]) + extract_cache_key_from(*args)
142
+ covercache *options, #{method}_data[:opts] do # covercache *options, cached_example_data[:opts] do
143
+ cache_block = #{method}_data[:block] # cache_block = cached_example_data[:block]
144
+ if cache_block.present? # if cache_block.present?
145
+ cache_block.(#{'self,' unless is_class_method} *args) # cache_block.(self, *args)
146
+ else # else
147
+ self.send :#{original_method}, *args, &block # self.send :example, *args, &block
148
+ end # end
149
+ end # end
150
+ end # env
150
151
  EOS
151
152
  end
152
153
 
153
154
  def covercache_method_arguments(method, *args, &block)
154
- settings = collect_method_args_to_hash(*args, &block)
155
- puts settings.inspect
156
- class_attribute :"cached_#{method}_settings"
157
- self.send(:"cached_#{method}_settings=", settings)
155
+ class_attribute :"cached_#{method}_data"
156
+ self.send :"cached_#{method}_data=", organize_cached_method_data(*args, &block)
158
157
  end
159
158
 
160
- def collect_method_args_to_hash(*args, &block)
161
- puts args.inspect
162
- Hash[ %w{args opts block}.map do |x|
163
- [ x, (args.shift || block) ]
164
- end].to_options
159
+ def organize_cached_method_data(*args, &block)
160
+ Hash[%w{args opts block}.map { |key| [key, (args.shift || block)] }].to_options
165
161
  end
166
162
  end
167
163
 
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covercache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tõnis Simo