activeadmin_settings_cached 2.2.0 → 2.3.1

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
- SHA1:
3
- metadata.gz: 603aca9e3f4f9203e5615d4d1a6de0971c712bd0
4
- data.tar.gz: 9479bedf926819b92387a229c3a86f82d0bc47d3
2
+ SHA256:
3
+ metadata.gz: 6a36186f3620c9f433f3ae6623aee9ac7f41aa6eba6f09c1d6258e3c85fff4ff
4
+ data.tar.gz: 8df7671e910503777e8db5ef684ccbe75188e7ff813f57f8674fcbdbbf7dc67f
5
5
  SHA512:
6
- metadata.gz: 93838c32f20dffc07cd5089f91b5c95587286b078ca8769b0768b55c40d90c36b22b332edcb6c58805a6fd6bf58bb4504e58b5bfcecf49c1f1faa644255ad17b
7
- data.tar.gz: 2c7b7968c14440954dce41f50b02ac8b3f2e2ef787e02512212a6c2df7fb9fc38d56928b4ad17c39726037e9e6dde55a849191edc1d863667500ffbb1f53560e
6
+ metadata.gz: 62a56fafb8fbc35413d980bcbc4e56c8ed8651adb51f9c5af9431f312d30d9b7b3b0f6594d09e53342c236b3721a846ad0c4eae820fd6553031b51efe380c242
7
+ data.tar.gz: 18fa494be363505eb265ea9031a4eca53931f2f23e222681d0449caac04fa3d1097fa4f6c27587b51c00c93df5ca272230d44b8ca8fa9048ba16dd5a4fce9871
@@ -1,3 +1,12 @@
1
+ # v2.3.1 2018-05-22
2
+
3
+ ## Changed
4
+
5
+ - Remove dry-types dependency
6
+
7
+ ## Fixed
8
+ - Breaking change in dry-types: Rename Types::Form to Types::Params (Julien FLAJOLLET)
9
+
1
10
  # v2.2.0 2017-12-22
2
11
 
3
12
  ## Added
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  group :test do
6
6
  gem 'pry-byebug'
7
+ gem 'puma'
7
8
  gem 'therubyracer'
8
9
  end
9
10
 
data/Makefile CHANGED
@@ -1,5 +1,11 @@
1
+ RUN := run --rm
2
+ DOCKER_COMPOSE_RUN := docker-compose $(RUN)
3
+
1
4
  default: test
2
5
 
6
+ compose-bash:
7
+ ${DOCKER_COMPOSE_RUN} app bash
8
+
3
9
  rake:
4
10
  bundle exec rake ${T}
5
11
 
data/README.md CHANGED
@@ -84,7 +84,7 @@ You can localize settings keys in local file
84
84
  en:
85
85
  settings:
86
86
  attributes:
87
- my_awesome_settings: 'My Awesome Lolaized Setting'
87
+ my_awesome_settings: 'My Awesome Localized Setting'
88
88
  ```
89
89
  ## Model name
90
90
 
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ['lib']
21
21
 
22
22
  s.add_dependency 'activeadmin'
23
- s.add_dependency 'dry-types', '>= 0.8.1'
24
23
  s.add_dependency 'rails-settings-cached', '>= 0.5.3', '< 0.6.7'
25
24
 
26
25
  s.add_development_dependency 'appraisal'
@@ -1,4 +1,4 @@
1
- version: '2'
1
+ version: '3.3'
2
2
 
3
3
  services:
4
4
  app:
@@ -6,8 +6,7 @@ services:
6
6
  command: 'make test'
7
7
  volumes:
8
8
  - '.:/app'
9
- - gems:/usr/local/bundle
9
+ - bundler-data:/usr/local/bundle/:cached
10
10
 
11
11
  volumes:
12
- gems:
13
- external: true
12
+ bundler-data:
@@ -6,6 +6,7 @@ gem "rails", "~> 4.2.0"
6
6
 
7
7
  group :test do
8
8
  gem "pry-byebug"
9
+ gem "puma"
9
10
  gem "therubyracer"
10
11
  end
11
12
 
@@ -8,6 +8,7 @@ gem "listen"
8
8
 
9
9
  group :test do
10
10
  gem "pry-byebug"
11
+ gem "puma"
11
12
  gem "therubyracer"
12
13
  end
13
14
 
@@ -8,6 +8,7 @@ gem "listen"
8
8
 
9
9
  group :test do
10
10
  gem "pry-byebug"
11
+ gem "puma"
11
12
  gem "therubyracer"
12
13
  end
13
14
 
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-types'
4
-
5
3
  module ActiveadminSettingsCached
6
4
  # Coerce user input values to defined types
7
5
  #
8
6
  # @api private
9
7
  class Coercions
8
+ TRUE_VALUES = %w[1 on On ON t true True TRUE T y yes Yes YES Y].freeze
9
+ FALSE_VALUES = %w[0 off Off OFF f false False FALSE F n no No NO N].freeze
10
+ BOOLEAN_MAP = ::Hash[
11
+ TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
12
+ ].freeze
13
+
10
14
  attr_reader :defaults, :display
11
15
 
12
16
  def initialize(defaults, display)
13
17
  @defaults = defaults
14
- @display = display
18
+ @display = display
15
19
  end
16
20
 
17
21
  def cast_params(params)
@@ -28,14 +32,14 @@ module ActiveadminSettingsCached
28
32
 
29
33
  private
30
34
 
31
- def cast_value(name, value)
35
+ def cast_value(name, value) # rubocop:disable Metrics/MethodLength
32
36
  case defaults[name]
33
37
  when TrueClass, FalseClass
34
- -> { value_or_default('bool', value, false) }
38
+ -> { BOOLEAN_MAP.fetch(value, false) }
35
39
  when Integer
36
- -> { value_or_default('int', value, 0) }
40
+ -> { value_or_default(0) { Integer(value) } }
37
41
  when Float
38
- -> { value_or_default('float', value, 0.0) }
42
+ -> { value_or_default(0.0) { Float(value) } }
39
43
  when Hash, 'ActiveSupport::HashWithIndifferentAccess'
40
44
  nil
41
45
  when Symbol
@@ -45,13 +49,10 @@ module ActiveadminSettingsCached
45
49
  end
46
50
  end
47
51
 
48
- def value_or_default(type, value, default)
49
- result = Dry::Types["form.#{type}"].call(value)
50
- if Dry::Types[type].valid?(result)
51
- result
52
- else
53
- default
54
- end
52
+ def value_or_default(default)
53
+ yield
54
+ rescue ArgumentError, TypeError
55
+ default
55
56
  end
56
57
  end
57
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveadminSettingsCached
4
- VERSION = '2.2.0'
4
+ VERSION = '2.3.1'.freeze
5
5
  end
@@ -21,60 +21,66 @@ RSpec.describe ActiveadminSettingsCached::Coercions do
21
21
  'base.five_setting' => :aaa,
22
22
  'second.first_setting' => false,
23
23
  'second.second_setting' => 'BBB',
24
- 'some' => Hash.new
24
+ 'some' => {}
25
25
  ].with_indifferent_access
26
26
  end
27
27
 
28
- let(:right_params) do
29
- ActionController::Parameters.new(
30
- Hash[
31
- 'base.first_setting' => 'BBB',
32
- 'base.second_setting' => 'false',
33
- 'base.third_setting' => '155',
34
- 'base.four_setting' => '55.5',
35
- 'base.five_setting' => 'bbb',
36
- 'second.first_setting' => 'true',
37
- 'second.second_setting' => 'AAA'
38
- ]
39
- )
40
- end
41
-
42
- let(:wrong_params) do
43
- ActionController::Parameters.new(
44
- Hash['base.second_setting' => 'hjgj',
45
- 'base.third_setting' => 'fhfh',
46
- 'base.four_setting' => 'gjfhg',
47
- 'second.first_setting' => 'ggf',
48
- 'some' => Hash.new
49
- ])
50
- end
51
-
52
- let(:no_params) { ActionController::Parameters.new(Hash[]) }
53
-
54
28
  subject(:coercions) do
55
29
  ActiveadminSettingsCached::Coercions.new(defaults, display)
56
30
  end
57
31
 
58
- it 'when good params' do
59
- expect { |b| coercions.cast_params(right_params, &b) }
60
- .to yield_successive_args(['base.first_setting', 'BBB'],
61
- ['base.second_setting', false],
62
- ['base.third_setting', 155],
63
- ['base.four_setting', 55.5],
64
- ['base.five_setting', :bbb],
65
- ['second.first_setting', true],
66
- ['second.second_setting', 'AAA'])
32
+ context 'when params is valid' do
33
+ let(:params) do
34
+ ActionController::Parameters.new(
35
+ Hash[
36
+ 'base.first_setting' => 'BBB',
37
+ 'base.second_setting' => 'false',
38
+ 'base.third_setting' => '155',
39
+ 'base.four_setting' => '55.5',
40
+ 'base.five_setting' => 'bbb',
41
+ 'second.first_setting' => 'true',
42
+ 'second.second_setting' => 'AAA'
43
+ ]
44
+ )
45
+ end
46
+
47
+ it 'casts params' do
48
+ expect { |b| coercions.cast_params(params, &b) }
49
+ .to yield_successive_args(['base.first_setting', 'BBB'],
50
+ ['base.second_setting', false],
51
+ ['base.third_setting', 155],
52
+ ['base.four_setting', 55.5],
53
+ ['base.five_setting', :bbb],
54
+ ['second.first_setting', true],
55
+ ['second.second_setting', 'AAA'])
56
+ end
67
57
  end
68
58
 
69
- it 'when wrong params' do
70
- expect { |b| coercions.cast_params(wrong_params, &b) }
71
- .to yield_successive_args(['base.second_setting', false],
72
- ['base.third_setting', 0],
73
- ['base.four_setting', 0.0],
74
- ['second.first_setting', false])
59
+ context 'when params is wrong' do
60
+ let(:params) do
61
+ ActionController::Parameters.new(
62
+ Hash[
63
+ 'base.second_setting' => 'hjgj',
64
+ 'base.third_setting' => 'fhfh',
65
+ 'base.four_setting' => 'gjfhg',
66
+ 'second.first_setting' => 'ggf',
67
+ 'some' => {}
68
+ ]
69
+ )
70
+ end
71
+
72
+ it 'returns default values' do
73
+ expect { |b| coercions.cast_params(params, &b) }
74
+ .to yield_successive_args(['base.second_setting', false],
75
+ ['base.third_setting', 0],
76
+ ['base.four_setting', 0.0],
77
+ ['second.first_setting', false])
78
+ end
75
79
  end
76
80
 
77
- it 'when no params' do
78
- expect { |b| coercions.cast_params(no_params, &b) }.not_to yield_control
81
+ context 'when params is empty' do
82
+ let(:params) { ActionController::Parameters.new(Hash[]) }
83
+
84
+ it { expect { |b| coercions.cast_params(params, &b) }.not_to yield_control }
79
85
  end
80
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_settings_cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Semyon Pupkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: dry-types
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.8.1
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 0.8.1
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rails-settings-cached
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -262,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
248
  version: '0'
263
249
  requirements: []
264
250
  rubyforge_project:
265
- rubygems_version: 2.6.13
251
+ rubygems_version: 2.7.6
266
252
  signing_key:
267
253
  specification_version: 4
268
254
  summary: UI interface for rails-settings-cached in active admin