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 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" 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 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 029f15d..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 @@ -25,7 +20,8 @@ module Types Validation = Types::Strict::Hash - Dependency = Types::Object - Function = Dependency.constrained(respond_to: :call) + Dependency = Dry::Types['any'] + Function = Dependency.constrained(case: -> x { x.respond_to?(:call) }) end end +