effective_datatables 4.4.1 → 4.4.2

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: 7efc5c4ebe5adbadcf46a1368c3034601e32ba38
4
- data.tar.gz: c167f47e82261487b9fa1574c75dc116216314c5
3
+ metadata.gz: d2e589bf3b121ec3ec0286dc8c1e94169a26edd9
4
+ data.tar.gz: f35b96216db08d011c858c3876b4e94cefbafada
5
5
  SHA512:
6
- metadata.gz: 6aaa13c5b1b4e90d3b3c7d00090c44482753541a0fdd8feb02bab110223e6e7222bab2bef886900f5fa222292f6ec767634e87d94b0ac37855f60b3f765293ee
7
- data.tar.gz: 6f1dcd266204fca3f546c5dfcbf43e56e3ece6f089dc8efa8ae12b63e237951d0d3cd1dd1ea162818b43499b834b8b059343c38087a456a86e106bb42c66f0ef
6
+ metadata.gz: 4181de92a46520e05f875cd0b2d650a7f9cd304f44605e72d858fecf1688578a85f53d93f9a5597a99dd2b950c482201cfa848ff248ad4e32a1d65c7755dce83
7
+ data.tar.gz: 142a507377e8340ae1a9f1bee1881c351295f4f05e53748750a8ab216cda05682c5bf6bbc9b13482a9ee0961e367afd48f202c08ff9141a908352271fd1631b8
@@ -55,6 +55,7 @@ module Effective
55
55
  raise 'expected view to respond to params' unless @view.respond_to?(:params)
56
56
 
57
57
  load_cookie!
58
+ assert_cookie!
58
59
  load_attributes!
59
60
 
60
61
  # We need early access to filter and scope, to define defaults from the model first
@@ -11,13 +11,8 @@ module Effective
11
11
 
12
12
  def load_attributes!
13
13
  if datatables_ajax_request? || datatables_inline_request?
14
- raise 'expected cookie to be present' unless cookie
15
- raise 'expected attributes cookie to be present' unless cookie[:attributes]
16
-
17
14
  @attributes = cookie.delete(:attributes)
18
- end
19
-
20
- unless datatables_ajax_request? || datatables_inline_request?
15
+ else
21
16
  @attributes[:_n] ||= view.controller_path.split('/')[0...-1].join('/').presence
22
17
  end
23
18
  end
@@ -48,15 +48,27 @@ module Effective
48
48
  end
49
49
  end
50
50
 
51
+ def assert_cookie!
52
+ if datatables_ajax_request? || datatables_inline_request?
53
+ raise 'expected cookie to be present' unless cookie
54
+ raise 'expected attributes cookie to be present' unless cookie[:attributes]
55
+ end
56
+ end
57
+
51
58
  def save_cookie!
52
59
  @dt_cookie ||= []
53
60
  @dt_cookie << [cookie_key, cookie_payload]
54
61
 
55
- while @dt_cookie.to_s.size > EffectiveDatatables.max_cookie_size.to_i
62
+ while @dt_cookie.to_s.size > EffectiveDatatables.cookie_max_size.to_i
56
63
  @dt_cookie.shift((@dt_cookie.length / 3) + 1)
57
64
  end
58
65
 
59
- view.cookies.signed['_effective_dt'] = { value: Base64.encode64(Marshal.dump(@dt_cookie)), domain: :all, tld_length: 2 }
66
+ # Generate cookie
67
+ domain = EffectiveDatatables.cookie_domain || :all
68
+ tld_length = EffectiveDatatables.cookie_tld_length
69
+ tld_length ||= (view.request.host == 'localhost' ? nil : view.request.host.to_s.split('.').count)
70
+
71
+ view.cookies.signed['_effective_dt'] = { value: Base64.encode64(Marshal.dump(@dt_cookie)), domain: domain, tld_length: tld_length }.compact
60
72
  end
61
73
 
62
74
  def cookie_payload
@@ -7,8 +7,7 @@ module Effective
7
7
  def datatables_ajax_request?
8
8
  return @_datatables_ajax_request unless @_datatables_ajax_request.nil?
9
9
 
10
- @_datatables_ajax_request =
11
- (view && view.params[:draw] && view.params[:columns] && cookie_keys.include?(view.params[:cookie])) == true
10
+ @_datatables_ajax_request = (view.present? && view.params.key?(:draw) && view.params.key?(:columns) && view.params.key?(:cookie))
12
11
  end
13
12
 
14
13
  def datatables_inline_request?
@@ -35,7 +35,9 @@ EffectiveDatatables.setup do |config|
35
35
  # Irregardless of this setting, effective_datatables still uses a cookie to function
36
36
  config.save_state = true
37
37
 
38
- # String size. Final byte size is about 1.5 times bigger, after rails signs it
39
- config.max_cookie_size = 2000
38
+ # Configure the _effective_dt cookie.
39
+ config.cookie_max_size = 2000 # String size. Final byte size is about 1.5 times bigger, after rails signs it
40
+ config.cookie_domain = :all # Should usually be :all
41
+ config.cookie_tld_length = nil # Leave nil to autodetect, or set to probably 2
40
42
 
41
43
  end
@@ -9,10 +9,16 @@ module EffectiveDatatables
9
9
  mattr_accessor :default_length
10
10
  mattr_accessor :html_class
11
11
  mattr_accessor :save_state
12
- mattr_accessor :max_cookie_size
12
+
13
+ mattr_accessor :cookie_max_size
14
+ mattr_accessor :cookie_domain
15
+ mattr_accessor :cookie_tld_length
13
16
 
14
17
  mattr_accessor :debug
15
18
 
19
+ alias_method :max_cookie_size, :cookie_max_size
20
+ alias_method :max_cookie_size=, :cookie_max_size=
21
+
16
22
  def self.setup
17
23
  yield self
18
24
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.4.1'.freeze
2
+ VERSION = '4.4.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-21 00:00:00.000000000 Z
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails