cistern 2.8.2 → 2.10.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
  SHA256:
3
- metadata.gz: 13428a2696bc1c11c76ec323e498a73268070325702dac6b5107ac16786537a8
4
- data.tar.gz: 58c19d84a3d6f0b9fd347a10c916aa925136896f91f49634a9c2bbbcc011ed26
3
+ metadata.gz: 5694e3c035882e211fed481448edf7d039a885fe8873426fad6c03e09e28e6e5
4
+ data.tar.gz: 1c989dab18e74848c0162c7c54a4b4768b6a9057e23792f0309d10ca6e7f2c04
5
5
  SHA512:
6
- metadata.gz: 4f8642906b69eb047b6f907b786a3a42c14e6313ba177f5c314994abdc652285dabbba8cd594e8661c651f3fbf4e926dd82d788bf8a3ae2fb9a902e25a3ad604
7
- data.tar.gz: 406ed32508a96668915a3485e61dc9f7abd9fc68a9989ff9c1f2ccfb16d5646400501fbad4c29cfdd8d6ee82ef3fe9fffc577d947bcdff4eaf510529e090b22f
6
+ metadata.gz: dc91cc89774987f5856a5c815a9afb64763febe9c025edd11f4f11437d1ca07eafa11868081211d4811540f4fec8c271be8c7b5482f91e226a30def1529d3756
7
+ data.tar.gz: 9be18655d0d71b1c0e6583854ec13e109924feb1586cc116b32da723edd6740f27d90ee9dca9940362bb500f7bf8dcfe497b1168e5ca2057aac7fd374e727a1c
data/README.md CHANGED
@@ -613,12 +613,12 @@ class Blog::GetPost
613
613
  [post_id, stringify_keys(parameters)]
614
614
  end
615
615
 
616
- def _mock(*args)
617
- mock(*setup(*args))
616
+ def _mock(*args, **kwargs)
617
+ mock(*setup(*args, **kwargs))
618
618
  end
619
619
 
620
620
  def _real(post_id, parameters)
621
- real(*setup(*args))
621
+ real(*setup(*args, **kwargs))
622
622
  end
623
623
  end
624
624
  ```
@@ -2,18 +2,19 @@
2
2
 
3
3
  module Cistern::Attributes
4
4
  PROTECTED_METHODS = [:cistern, :service, :identity, :collection].freeze
5
- TRUTHY = ['true', '1'].freeze
5
+ TRUTHY = [true, 'On', 'ON', 'on', 'True', 'TRUE', 'true', '1', 1].freeze
6
6
 
7
7
  module ClassMethods
8
8
  def parsers
9
9
  @parsers ||= {
10
- array: ->(v, _) { [*v] },
11
- boolean: ->(v, _) { TRUTHY.include?(v.to_s.downcase) },
12
- date: ->(v, _) { v.is_a?(Date) ? v : v && Date.parse(v.to_s) },
13
- float: ->(v, _) { v && v.to_f },
14
- integer: ->(v, _) { v && v.to_i },
15
- string: ->(v, _) { v && v.to_s },
16
- time: ->(v, _) { v.is_a?(Time) ? v : v && Time.parse(v.to_s) },
10
+ array: ->(v, _) { [*v] },
11
+ boolean: ->(v, _) { TRUTHY.include?(v) },
12
+ date: ->(v, _) { v.is_a?(Date) ? v : v && Date.parse(v.to_s) },
13
+ float: ->(v, _) { v&.to_f },
14
+ integer: ->(v, _) { v&.to_i },
15
+ strict_integer: ->(v, _) { Integer(v) },
16
+ string: ->(v, _) { v&.to_s },
17
+ time: ->(v, _) { v.is_a?(Time) ? v : v && Time.parse(v.to_s) },
17
18
  }
18
19
  end
19
20
 
@@ -64,11 +65,11 @@ module Cistern::Attributes
64
65
  name_sym
65
66
  end
66
67
 
67
- def identity(*args)
68
- args.any? ? @identity = attribute(*args) : (@identity ||= parent_identity)
68
+ def identity(*args, **kwargs)
69
+ args.any? ? @identity = attribute(*args, **kwargs) : (@identity ||= parent_identity)
69
70
  end
70
71
 
71
- def ignore_attributes(*args)
72
+ def ignore_attributes(*args, **kwargs)
72
73
  @ignored_attributes = args
73
74
  end
74
75
 
@@ -228,7 +229,7 @@ module Cistern::Attributes
228
229
  #
229
230
  # @raise [ArgumentError] if any requested attribute does not have a value
230
231
  # @return [Hash] of matching attributes
231
- def requires(*args)
232
+ def requires(*args, **kwargs)
232
233
  missing, required = missing_attributes(args)
233
234
 
234
235
  if missing.length == 1
@@ -244,7 +245,7 @@ module Cistern::Attributes
244
245
  #
245
246
  # @raise [ArgumentError] if no requested attributes have values
246
247
  # @return [Hash] of matching attributes
247
- def requires_one(*args)
248
+ def requires_one(*args, **kwargs)
248
249
  missing, required = missing_attributes(args)
249
250
 
250
251
  if missing.length == args.length
@@ -248,11 +248,11 @@ module Cistern::Client
248
248
  @_requests ||= []
249
249
  end
250
250
 
251
- def requires(*args)
251
+ def requires(*args, **kwargs)
252
252
  required_arguments.concat(args)
253
253
  end
254
254
 
255
- def recognizes(*args)
255
+ def recognizes(*args, **kwargs)
256
256
  recognized_arguments.concat(args)
257
257
  end
258
258
 
data/lib/cistern/data.rb CHANGED
@@ -30,7 +30,7 @@ module Cistern::Data
30
30
  data.clear
31
31
  end
32
32
 
33
- def store_in(*args)
33
+ def store_in(*args, **kwargs)
34
34
  @storage = *args
35
35
  @data = nil
36
36
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cistern::HashSupport
4
- def hash_slice(*args); Cistern::Hash.slice(*args); end
5
- def hash_except(*args); Cistern::Hash.except(*args); end
6
- def hash_except!(*args); Cistern::Hash.except!(*args); end
7
- def hash_stringify_keys(*args); Cistern::Hash.stringify_keys(*args); end
4
+ def hash_slice(*args, **kwargs); Cistern::Hash.slice(*args, **kwargs); end
5
+ def hash_except(*args, **kwargs); Cistern::Hash.except(*args, **kwargs); end
6
+ def hash_except!(*args, **kwargs); Cistern::Hash.except!(*args, **kwargs); end
7
+ def hash_stringify_keys(*args, **kwargs); Cistern::Hash.stringify_keys(*args, **kwargs); end
8
8
  end
data/lib/cistern/model.rb CHANGED
@@ -14,7 +14,7 @@ module Cistern::Model
14
14
  def self.cistern_model(cistern, klass, name)
15
15
  cistern.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
16
16
  def #{name}(attributes={})
17
- #{klass.name}.new(attributes.merge(cistern: self))
17
+ #{klass.name}.new({cistern: self}.merge(attributes))
18
18
  end
19
19
  EOS
20
20
  end
@@ -24,8 +24,8 @@ module Cistern::Request
24
24
  end
25
25
 
26
26
  method = <<-EOS
27
- def #{name}(*args)
28
- #{klass}.new(self).call(*args)
27
+ def #{name}(*args, **kwargs)
28
+ #{klass}.new(self).call(*args, **kwargs)
29
29
  end
30
30
  EOS
31
31
 
@@ -34,12 +34,12 @@ module Cistern::Request
34
34
  cistern::Real.module_eval method, __FILE__, __LINE__
35
35
  end
36
36
 
37
- def self.service_request(*args)
37
+ def self.service_request(*args, **kwargs)
38
38
  Cistern.deprecation(
39
39
  '#service_request is deprecated. Please use #cistern_request',
40
40
  caller[0]
41
41
  )
42
- cistern_request(*args)
42
+ cistern_request(*args, **kwargs)
43
43
  end
44
44
 
45
45
  attr_reader :cistern
@@ -56,8 +56,8 @@ module Cistern::Request
56
56
  @cistern = cistern
57
57
  end
58
58
 
59
- def call(*args)
60
- dispatch(*args)
59
+ def call(*args, **kwargs)
60
+ dispatch(*args, **kwargs)
61
61
  end
62
62
 
63
63
  def real(*)
@@ -71,7 +71,7 @@ module Cistern::Request
71
71
  protected
72
72
 
73
73
  # @fixme remove _{mock,real} methods and call {mock,real} directly before 3.0 release.
74
- def dispatch(*args)
74
+ def dispatch(*args, **kwargs)
75
75
  to = cistern.mocking? ? :mock : :real
76
76
 
77
77
  legacy_method = :"_#{to}"
@@ -82,9 +82,9 @@ module Cistern::Request
82
82
  caller[0]
83
83
  )
84
84
 
85
- public_send(legacy_method, *args)
85
+ public_send(legacy_method, *args, **kwargs)
86
86
  else
87
- public_send(to, *args)
87
+ public_send(to, *args, **kwargs)
88
88
  end
89
89
  end
90
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cistern
4
- VERSION = '2.8.2'
4
+ VERSION = '2.10.0'
5
5
  end
@@ -204,14 +204,23 @@ describe Cistern::Attributes, 'parsing' do
204
204
  expect(subject.new(list: 'item').list).to eq(['item'])
205
205
  end
206
206
 
207
- it 'should parse an integer' do
208
- subject.class_eval do
209
- attribute :int, type: :integer
207
+ context 'with type integer' do
208
+ before do
209
+ subject.class_eval do
210
+ attribute :int, type: :integer
211
+ end
210
212
  end
211
213
 
212
- expect(subject.new(int: '42.5').int).to eq(42)
213
- expect(subject.new(int: '42').int).to eq(42)
214
- expect(subject.new(int: 42).int).to eq(42)
214
+ [
215
+ ['42.5', 42],
216
+ ['42', 42],
217
+ [42, 42],
218
+ ["4f", 4],
219
+ ].each do |input, output|
220
+ specify("input of #{input.inspect} casts to #{output.inspect}") do
221
+ expect(subject.new(int: input).int).to eq(output)
222
+ end
223
+ end
215
224
  end
216
225
 
217
226
  it 'should parse a float' do
@@ -250,7 +259,8 @@ describe Cistern::Attributes, 'parsing' do
250
259
  expect(subject.new({ 'squash' => { 'type' => 'fred' } }).butternut_id).to be_nil
251
260
 
252
261
  # override intermediate processing
253
- expect(subject.new({ 'squash' => { 'id' => '12', 'type' => 'fred' } }).squash).to eq({ 'id' => '12', 'type' => 'fred' })
262
+ expect(subject.new({ 'squash' => { 'id' => '12', 'type' => 'fred' } }).squash)
263
+ .to eq({ 'id' => '12', 'type' => 'fred' })
254
264
 
255
265
  # alias of override
256
266
  expect(subject.new({ 'squash' => { 'id' => '12', 'type' => 'fred' } }).vegetable).to eq({ 'id' => '12', 'type' => 'fred' })
data/spec/hash_spec.rb CHANGED
@@ -72,11 +72,13 @@ describe Cistern::Collection do
72
72
  end
73
73
 
74
74
  describe Cistern::Singular do
75
- subject { Class.new(Sample::Singular) do
76
- def reload
77
- attributes
78
- end
79
- end.new({}) }
75
+ subject do
76
+ Class.new(Sample::Singular) do
77
+ def reload
78
+ attributes
79
+ end
80
+ end.new({})
81
+ end
80
82
 
81
83
  include_examples 'hash_support'
82
84
  end
@@ -51,20 +51,22 @@ describe 'mock data' do
51
51
  include_examples 'mock_data#backend', :hash
52
52
  end
53
53
 
54
- describe 'Cistern::Data::Redis' do
55
- include_examples 'mock_data#backend', :redis
56
-
57
- context 'with an explicit client' do
58
- before(:each) do
59
- @other = Redis::Namespace.new('other_cistern', Redis.new)
60
- @other.set('x', 'y')
61
- end
62
-
63
- include_examples 'mock_data#backend', :redis, client: Redis::Namespace.new('cistern', Redis.new)
64
-
65
- after(:each) do
66
- expect(@other.get('x')).to eq('y')
67
- @other.del('x')
54
+ if ENV.key?('REDIS_URI')
55
+ describe 'Cistern::Data::Redis' do
56
+ include_examples 'mock_data#backend', :redis
57
+
58
+ context 'with an explicit client' do
59
+ before(:each) do
60
+ @other = Redis::Namespace.new('other_cistern', Redis.new)
61
+ @other.set('x', 'y')
62
+ end
63
+
64
+ include_examples 'mock_data#backend', :redis, client: Redis::Namespace.new('cistern', Redis.new)
65
+
66
+ after(:each) do
67
+ expect(@other.get('x')).to eq('y')
68
+ @other.del('x')
69
+ end
68
70
  end
69
71
  end
70
72
  end
data/spec/request_spec.rb CHANGED
@@ -11,7 +11,7 @@ describe 'Cistern::Request' do
11
11
  Sample::Real.class_eval do
12
12
  attr_reader :service_args
13
13
 
14
- def initialize(*args)
14
+ def initialize(*args, **kwargs)
15
15
  @service_args = args
16
16
  end
17
17
  end
@@ -30,11 +30,11 @@ describe 'Cistern::Request' do
30
30
 
31
31
  it 'calls the appropriate method' do
32
32
  class GetSamples < Sample::Request
33
- def real(*args)
33
+ def real(*args, **kwargs)
34
34
  cistern.service_args + args + ['real']
35
35
  end
36
36
 
37
- def mock(*args)
37
+ def mock(*args, **kwargs)
38
38
  args + ['mock']
39
39
  end
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cistern
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.2
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: API client framework extracted from Fog
14
14
  email:
@@ -75,7 +75,7 @@ homepage: http://joshualane.com/cistern
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}
78
- post_install_message:
78
+ post_install_message:
79
79
  rdoc_options: []
80
80
  require_paths:
81
81
  - lib
@@ -90,9 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.7.6
95
- signing_key:
93
+ rubygems_version: 3.4.10
94
+ signing_key:
96
95
  specification_version: 4
97
96
  summary: API client framework
98
97
  test_files: