marfa 0.4.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/marfa/cache.rb +1 -0
- data/lib/marfa/helpers/controller.rb +30 -0
- data/lib/marfa/models/api_model.rb +28 -6
- data/lib/marfa/version.rb +1 -1
- data/marfa.gemspec +1 -1
- 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: c0759f81941c873aa1735687444f031c919ea122
|
4
|
+
data.tar.gz: 5a395cc867d247b1524bc8447b168296fdb8065a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f396b685edab492541f969c49cc10e83ae1e9a5685c1c7addee2cd87a311f0c8aa16c9594b3bc44c89e5c36c68bb8d87284c8209bc18a940c397c20c68f1196
|
7
|
+
data.tar.gz: a00519de9f1b9ed6c32c04e3e61391585a6b2c22ed75306750e702d058abc18adef2205cc7850ad3e4df1058e67f35fc0b04a453109d7dbe2d88b00dda2db14c
|
data/lib/marfa/cache.rb
CHANGED
@@ -167,6 +167,36 @@ module Marfa
|
|
167
167
|
haml :"#{template}", locals: data
|
168
168
|
end
|
169
169
|
|
170
|
+
# Render block with data from cache, return html
|
171
|
+
# @param options [Hash] - options hash
|
172
|
+
# @example
|
173
|
+
# render_block_with_data({ path: 'index/index', tags: ['tag1', 'tag2'] })
|
174
|
+
# @return [String] rendered block
|
175
|
+
def render_block_with_data(options)
|
176
|
+
# TODO: Improve caching with parameters
|
177
|
+
cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
|
178
|
+
tags = options[:tags] || []
|
179
|
+
|
180
|
+
kind = 'block'
|
181
|
+
kind += "-#{@device}" if Marfa.config.cache[:use_device]
|
182
|
+
tags += query_to_tags(options[:query])
|
183
|
+
|
184
|
+
if cache_time.positive?
|
185
|
+
content = get_cached_content(kind, options[:path], tags)
|
186
|
+
return content unless content.nil?
|
187
|
+
end
|
188
|
+
|
189
|
+
data = options[:data]
|
190
|
+
data = data.merge(options[:locals]) unless options[:locals].nil?
|
191
|
+
|
192
|
+
full_path = Marfa.config.block_templates_path + '/' + options[:path]
|
193
|
+
|
194
|
+
return render_content(full_path, data) if cache_time.zero?
|
195
|
+
|
196
|
+
cache_key = Marfa.cache.create_key(kind, options[:path], tags)
|
197
|
+
render_cached_content(cache_key, full_path, data)
|
198
|
+
end
|
199
|
+
|
170
200
|
alias_method :render_component, :render_block
|
171
201
|
alias_method :render_static_component, :render_static_block
|
172
202
|
end
|
@@ -37,10 +37,16 @@ module Marfa
|
|
37
37
|
def self.get_raw_data(params)
|
38
38
|
result = {}
|
39
39
|
path = params[:path]
|
40
|
+
cache_key = "data_#{path}#{params[:query]}".scan(/\w+/).join('_')
|
40
41
|
|
41
42
|
begin
|
42
|
-
|
43
|
-
|
43
|
+
if Marfa.cache.exist?(cache_key)
|
44
|
+
result = JSON.parse(Marfa.cache.get(cache_key), symbolize_names: true)
|
45
|
+
else
|
46
|
+
response = RestClient.get("#{Marfa.config.api_server}#{path}", { params: params[:query], headers: {} })
|
47
|
+
Marfa.cache.set(cache_key, response.body, params[:cache_time] || 7200)
|
48
|
+
result = JSON.parse(response.body, symbolize_names: true)
|
49
|
+
end
|
44
50
|
rescue => exception
|
45
51
|
if [:development, :test].include? Marfa.config.environment
|
46
52
|
_log_exception(exception, path, params)
|
@@ -56,17 +62,33 @@ module Marfa
|
|
56
62
|
def self.get_raw_data_with_pagination(params)
|
57
63
|
result = {}
|
58
64
|
path = params[:path]
|
65
|
+
cache_key = "data_with_pagination_#{path}#{params[:query]}".scan(/\w+/).join('_')
|
59
66
|
|
60
67
|
begin
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
68
|
+
if Marfa.cache.exist?(cache_key)
|
69
|
+
result = JSON.parse(Marfa.cache.get(cache_key), symbolize_names: true)
|
70
|
+
else
|
71
|
+
response = RestClient.get("#{Marfa.config.api_server}#{path}", { params: params[:query], headers: {} })
|
72
|
+
result[:data] = JSON.parse(response.body, symbolize_names: true)
|
73
|
+
result[:data_count] = response.headers[:x_count].to_i unless response.headers[:x_count].nil?
|
74
|
+
result[:data_pages] = response.headers[:x_pages].to_i unless response.headers[:x_pages].nil?
|
75
|
+
Marfa.cache.set(cache_key, result.to_json, params[:cache_time] || 7200)
|
76
|
+
end
|
65
77
|
rescue => exception
|
66
78
|
if [:development, :test].include? Marfa.config.environment
|
67
79
|
_log_exception(exception, path, params)
|
68
80
|
end
|
69
81
|
end
|
82
|
+
# begin
|
83
|
+
# response = RestClient.get("#{Marfa.config.api_server}#{path}", { params: params[:query], headers: {} })
|
84
|
+
# result[:data] = JSON.parse(response.body, symbolize_names: true)
|
85
|
+
# result[:data_count] = response.headers[:x_count].to_i unless response.headers[:x_count].nil?
|
86
|
+
# result[:data_pages] = response.headers[:x_pages].to_i unless response.headers[:x_pages].nil?
|
87
|
+
# rescue => exception
|
88
|
+
# if [:development, :test].include? Marfa.config.environment
|
89
|
+
# _log_exception(exception, path, params)
|
90
|
+
# end
|
91
|
+
# end
|
70
92
|
|
71
93
|
result
|
72
94
|
end
|
data/lib/marfa/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Version constant
|
2
2
|
module Marfa
|
3
3
|
# The version constant for the current version of Marfa
|
4
|
-
VERSION = '0.
|
4
|
+
VERSION = '0.5.0' unless defined?(Marfa::VERSION)
|
5
5
|
|
6
6
|
# The current Marfa version.
|
7
7
|
# @return [String] The version number
|
data/marfa.gemspec
CHANGED