venduitz 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80f34a1cbbf57c1d06e78db230249cee6e79beb6
4
- data.tar.gz: 6f29221c7a63222cc9d49e4a139df36d99deb1f0
3
+ metadata.gz: d731579d5ab45c36f5817e0c32e81316392ee1ec
4
+ data.tar.gz: a333a6bdc74cec51e07740e22ce40092074c92de
5
5
  SHA512:
6
- metadata.gz: c308204513cab0b54ffa29cb823d93912966d22cbcfa15e30e7df4c2ba6b838c84e9ba89178a3baf8efd1cb5a4f3acf34fa30cb0ea365018d198135b8bf63fd7
7
- data.tar.gz: c0571ecf9d32aeb25a5c15a31e6fdae6d274a120225cd1e5f0304f15cfdb9ad1ff463b0fd1797c304224fe500384bfca9d6b2608768d53472d934e21f639d9ca
6
+ metadata.gz: b2e273ad146d03b28e72f35ef7b161c88cb5fc0558a86bd6f8e6566ec331aa4795b3f200b6c3db1162c19a54e9af5f2434091bf378d990120511ea3fbcd722c2
7
+ data.tar.gz: aa4272307be01665b92bd760616b51edb5e5a896def521c7a824bfb6e86c7a427ae7ee4a5c111a3dadfbf62dde72fa7ca4c72cf0cdb9a254aecdf589736f87b9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- venduitz (0.3.1)
4
+ venduitz (0.4.0)
5
5
  multi_json
6
6
  oj
7
7
 
data/README.md CHANGED
@@ -72,7 +72,7 @@ res = SearchView.to_json(search, [:images])
72
72
 
73
73
  ### Using Cache
74
74
  To use cache you have to define a Driver for the Venduitz:
75
- ```
75
+ ```ruby
76
76
  # Defining the CacheDriver
77
77
  Venduitz::Cache.driver = CacheDriver
78
78
 
@@ -6,7 +6,7 @@ module Venduitz
6
6
  # Static methods
7
7
  class << self
8
8
  #
9
- attr_accessor :digestor, :driver, :namespace
9
+ attr_accessor :digestor, :driver, :namespace, :enabled, :config
10
10
 
11
11
  # Before use it you have to specify the driver used by
12
12
  # this module. The driver must define the following
@@ -70,6 +70,12 @@ module Venduitz
70
70
  @namespace.respond_to(:call) ? @namespace.call : @namespace
71
71
  end
72
72
 
73
+ # Config
74
+ def config
75
+ return {} if @config.nil?
76
+ @config
77
+ end
78
+
73
79
  private
74
80
 
75
81
  def _driver
@@ -4,14 +4,21 @@ module Venduitz
4
4
  module Grape
5
5
  # Call method
6
6
  def self.call(object, env)
7
- # Define the Venduitz representer
8
- representer = env['api.endpoint'].options.fetch(:route_options, {})[:venduitz]
7
+ # Route Options
8
+ options = env['api.endpoint'].options.fetch :route_options, {}
9
9
 
10
10
  # Must define the Representer in the endpoint
11
- raise 'Must define the Venduitz in the endpoind' if representer.nil?
11
+ raise 'Must define the Venduitz in the endpoind' if options[:venduitz].nil?
12
+
13
+ # Representer options
14
+ options[:exclude] ||= []
15
+
16
+ # Define the Cache options
17
+ options[:cache] ||= Venduitz::Cache.enabled
18
+ options[:cache_options] ||= Venduitz::Cache.config
12
19
 
13
20
  # Render it!
14
- representer.to_json object
21
+ options[:venduitz].to_json object, options[:exclude], options[:cache], options[:cache_options]
15
22
  end
16
23
  end
17
24
  end
@@ -2,6 +2,6 @@
2
2
  module Venduitz
3
3
  # Gem version
4
4
  def self.version
5
- '0.3.1'.freeze
5
+ '0.4.0'.freeze
6
6
  end
7
7
  end
data/lib/venduitz/view.rb CHANGED
@@ -40,7 +40,7 @@ module Venduitz
40
40
  # @param {Boolean} cache This flag indicates if cache will be performed
41
41
  # @param {Hash} cache_options Cache options
42
42
  # @return {Hash} JSON ready hash containing the specified view fields
43
- def generate(obj, excluded = [], cache = false, cache_options = {})
43
+ def generate(obj, excluded = [], cache = Cache.enabled, cache_options = Cache.config)
44
44
  # Generate the cache key if cache is enabled
45
45
  key = cache_key(obj, excluded, :generate) if cache
46
46
 
@@ -84,7 +84,7 @@ module Venduitz
84
84
  # @param {Boolean} cache This flag indicates if cache will be performed
85
85
  # @param {Hash} cache_options Cache options
86
86
  # @return {Hash} The JSON string itself
87
- def to_json(obj, excluded = [], cache = false, cache_options = {})
87
+ def to_json(obj, excluded = [], cache = Cache.enabled, cache_options = Cache.config)
88
88
  # Generate the cache key if cache is enabled
89
89
  key = cache_key(obj, excluded, :json) if cache
90
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: venduitz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Corado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json