mincer 0.2.14 → 0.2.15

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: 596cff7167053281b57a50ee49b6d201a6c3481d
4
- data.tar.gz: 6040bf0e675643a66ed39573172dcf770fac77c1
3
+ metadata.gz: f22e8f584ffd32b05cbf70b9e8dd5fe41ed7e9ba
4
+ data.tar.gz: 356141e6b9aedfcd17932f0e7384373e44dbd5e5
5
5
  SHA512:
6
- metadata.gz: d4bcf26e32eae3d1d0b31b4a4fe45b0cdd2b2fa812cdc26197986c304d3363c4f00dfbd2fa6e2effb7efabaad122ada725ce3e4dee4852b736de0aea3da4274b
7
- data.tar.gz: 36a7cf9e5c1ff79f8398cc2590af4afc690eac1e37f22aab969d66a48395b7f6a93350b967607030a6937402150f4545ab5222f3a3708582790f476062edcab2
6
+ metadata.gz: 94af085a7d14e719218f240ff468200ed742074f68622d9e8ebda69ef3b6f3493fc3e73fc0949d649dd05296581a2c9f76f760651f803266d0ab140bf4fd1e58
7
+ data.tar.gz: 07d17eddcc5e834a27211fec0702b29e3c3daad2af2ec672cc37192d48d18fdfb1915f11177f7d602af0b18639c34dbc0b7ef11edb06990589b0cc84cea7fb04
@@ -30,7 +30,7 @@ module Mincer
30
30
 
31
31
  def json_query
32
32
  if @options[:root]
33
- json_query_with_root(@options[:root])
33
+ json_query_with_root(@options[:root], @options[:meta])
34
34
  else
35
35
  basic_json_query
36
36
  end
@@ -41,17 +41,23 @@ module Mincer
41
41
  end
42
42
 
43
43
  # Query for basic json generation. Ex: [{'id': 1}, {...}]
44
- def basic_json_query(root = 'json')
44
+ def basic_json_query(root = 'json', meta = false)
45
+ meta_sql = if meta
46
+ ", #{@mincer.total_pages} AS total_pages, #{@mincer.total_count} AS total_count, #{@mincer.current_page} AS current_page, #{@mincer.limit_value} AS per_page"
47
+ else
48
+ ''
49
+ end
45
50
  <<-SQL
46
- SELECT COALESCE(array_to_json(array_agg(row_to_json(subq))), '[]') AS #{root}
51
+ SELECT COALESCE(array_to_json(array_agg(row_to_json(subq))), '[]') AS #{root} #{meta_sql}
47
52
  FROM (#{base_sql}) as subq
48
53
  SQL
49
54
  end
50
55
 
51
56
  # Generates json with root. Ex: If root = 'items' resulting json will be { 'items' => [...] }
52
- def json_query_with_root(root)
57
+ # When `meta` passed will add pagination data(Experimental!!!)
58
+ def json_query_with_root(root, meta)
53
59
  <<-SQL
54
- SELECT row_to_json(t) as json FROM ( #{basic_json_query(root)} ) as t
60
+ SELECT row_to_json(t) as json FROM ( #{basic_json_query(root, meta)} ) as t
55
61
  SQL
56
62
  end
57
63
 
@@ -1,7 +1,7 @@
1
1
  module Mincer
2
2
 
3
3
  def self.version
4
- Gem::Version.new '0.2.14'
4
+ Gem::Version.new '0.2.15'
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mincer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Krasinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.6.10
199
+ rubygems_version: 2.4.5.1
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: ActiveRecord::Relation wrapper for pagination, order, json, search, cache_digest