From 753b5722b71f2fd907d9e4ada81233e828b833d1 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 1 Apr 2019 01:19:01 +1300 Subject: [PATCH 1/5] Allow Bundler 2.x --- formalist.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formalist.gemspec b/formalist.gemspec index 0455a8d..163c153 100644 --- a/formalist.gemspec +++ b/formalist.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "dry-types", "~> 0.13" spec.add_runtime_dependency "inflecto" - spec.add_development_dependency "bundler", "~> 1.10" + spec.add_development_dependency "bundler", ">= 1.10", "< 3" spec.add_development_dependency "rake", "~> 10.4.2" spec.add_development_dependency "rspec", "~> 3.3.0" spec.add_development_dependency "simplecov", "~> 0.13.0" From 529a63da83464df0586580c3d70faf151c24cafb Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 1 Apr 2019 01:19:17 +1300 Subject: [PATCH 2/5] Switch Dry::Types::Object to Dry::Types['any'] This was updated in https://github.com/dry-rb/dry-types/commit/70007ef442681a9b2ab390ff48d15b18e1dd91ef\#diff-eb310b9f51700ccb1cb335c0dad7b7ff --- lib/formalist/types.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/formalist/types.rb b/lib/formalist/types.rb index 029f15d..0aff6b3 100644 --- a/lib/formalist/types.rb +++ b/lib/formalist/types.rb @@ -25,7 +25,7 @@ module Types Validation = Types::Strict::Hash - Dependency = Types::Object + Dependency = Dry::Types['any'] Function = Dependency.constrained(respond_to: :call) end end From 822e7933a4a13bbc14d2dc481bd53e5d9d118cf8 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 1 Apr 2019 01:57:21 +1300 Subject: [PATCH 3/5] Remove respond_to predicate, using case: --- lib/formalist/elements/standard/rich_text_area.rb | 2 +- lib/formalist/types.rb | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/formalist/elements/standard/rich_text_area.rb b/lib/formalist/elements/standard/rich_text_area.rb index 11b6607..2683644 100644 --- a/lib/formalist/elements/standard/rich_text_area.rb +++ b/lib/formalist/elements/standard/rich_text_area.rb @@ -9,7 +9,7 @@ class RichTextArea < Field attribute :box_size, Types::String.enum("single", "small", "normal", "large", "xlarge"), default: "normal" attribute :inline_formatters, Types::Array attribute :block_formatters, Types::Array - attribute :embeddable_forms, Types::Dependency.constrained(respond_to: :to_h) + attribute :embeddable_forms, Types::Dependency.constrained(case: -> x { x.respond_to?(:call) }) # FIXME: it would be tidier to have a reader method for each attribute def attributes diff --git a/lib/formalist/types.rb b/lib/formalist/types.rb index 0aff6b3..febc35b 100644 --- a/lib/formalist/types.rb +++ b/lib/formalist/types.rb @@ -1,11 +1,6 @@ # coding: utf-8 require "dry/types" -# TODO: Find a way to avoid registering this globally -Dry::Logic::Predicates.predicate :respond_to? do |method_name, value| - value.respond_to?(method_name) -end - module Formalist module Types include Dry::Types.module @@ -26,6 +21,7 @@ module Types Validation = Types::Strict::Hash Dependency = Dry::Types['any'] - Function = Dependency.constrained(respond_to: :call) + Function = Dependency.constrained(case: -> x { x.respond_to?(:call) }) end end + From b4623b386b15852db054aa10553694a1a6fe5ff8 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 1 Apr 2019 02:03:03 +1300 Subject: [PATCH 4/5] Test on non-EOL rubies --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c1fce8e..2d1b385 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,12 @@ script: - bundle exec rake after_success: # Send coverage report from the job #1 == current MRI release -- '[ "${TRAVIS_JOB_NUMBER#*.}" = "1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter' + - '[ "${TRAVIS_JOB_NUMBER#*.}" = "1" ] && [ "$TRAVIS_BRANCH" = "master" ] && bundle exec codeclimate-test-reporter' rvm: - - 2.4.0 - - 2.3.3 - - 2.2.6 - - jruby-9.1.6.0 + - 2.6.2 + - 2.5.5 + - 2.4.5 + - jruby-9.2.6.0 addons: code_climate: repo_token: 2c2c7c253435c02667371778ca886b069d4d24590748fbd7396b9b080016bfa7 From d1c8aa6edb0e6fd8869884c2928dc8b26904ed9a Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 1 Apr 2019 02:21:44 +1300 Subject: [PATCH 5/5] Switch Types:Hash.weak to Types::Hash.schema().safe --- lib/formalist/element.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/formalist/element.rb b/lib/formalist/element.rb index 089902a..03f6cd7 100644 --- a/lib/formalist/element.rb +++ b/lib/formalist/element.rb @@ -30,9 +30,9 @@ def initialize(name: nil, attributes: {}, children: [], input: nil, errors: []) } # Then run them through the schema - @attributes = Types::Hash.weak( - self.class.attributes_schema.map { |name, defn| [name, defn[:type]] }.to_h - )[all_attributes] + @attributes = Types::Hash.schema( + self.class.attributes_schema.map { |name, defn| [name, defn[:type]] }.to_h, + ).safe[all_attributes] @children = children @input = input