timriley on prefer-local-components-when-importing
Prefer local components when im… (compare)
timriley on support-deeper-provider-source-class-hierarchies
Allow deeper Provider::Source h… (compare)
timriley on nil-import-namespaces
Import root components via `nil… Rename spec (compare)
timriley on add-file-path-to-component
timriley on main
Expose Component#file_name Thi… Merge pull request #237 from dr… (compare)
@/all hey, after 2 weeks of testing we decided to switch to Zulip and we are saying "good bye" to Gitter. From April 1st (no kidding) we'll be hanging out in Zulip and stop paying attention to this Gitter chat. You can join our Zulip organization here: https://dry-rb.zulipchat.com/register/
ps. rom-rb gitter chat will move too
require 'spec_helper'
module CRUD
class Update
include Dry::Transaction
step :validate
step :persist
def validate(input)
Success(input.to_s + model_class.to_s)
end
def persist(input)
Success(input.to_s + model_class.to_s)
end
end
class ORMModel1
end
class Update1 < Update
def model_class
ORMModel1
end
end
end
describe 'ParamOverride' do
context 'update1' do
subject { CRUD::Update1.new.call params }
let(:params) { {a:1,b:2} }
context 'negative cases' do
specify 'inheritance just does not work' do
expect(subject).to be_success
expect(subject.value!).to_not eq('{}ORMModel1')
end
end
end
end
@/all hey, after 2 weeks of testing we decided to switch to Zulip and we are saying "good bye" to Gitter. From April 1st (no kidding) we'll be hanging out in Zulip and stop paying attention to this Gitter chat. You can join our Zulip organization here: https://dry-rb.zulipchat.com/register/
ps. rom-rb gitter chat will move too
2.5.3p105> require "dry-types"
=> true
2.5.3p105> include Dry.Types()
=> Object
2.5.3p105> Params::Integer["1"]
=> 1
2.5.3p105> Params::Integer[1]
=> 1
2.5.3p105> Params::Time["2019-11-26 15:50:12 +0000"]
=> 2019-11-26 15:50:12 +0000
2.5.3p105> Params::Time[Time.new]
Traceback (most recent call last):
16: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/cli.rb:13:in `start'
15: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
14: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/cli.rb:22:in `dispatch'
13: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
12: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
11: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
10: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/cli.rb:362:in `exec'
9: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:27:in `run'
8: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `kernel_load'
7: from /var/lib/gems/2.5.0/gems/bundler-1.15.4/lib/bundler/cli/exec.rb:74:in `load'
6: from /usr/bin/irb:11:in `<top (required)>'
5: from (irb):6
4: from /var/bundler/gems/dry-types-1.2.1/lib/dry/types/type.rb:49:in `call'
3: from /var/bundler/gems/dry-types-1.2.1/lib/dry/types/constructor.rb:59:in `call_unsafe'
2: from /var/bundler/gems/dry-types-1.2.1/lib/dry/types/constructor/function.rb:61:in `call'
1: from /var/bundler/gems/dry-types-1.2.1/lib/dry/types/coercions.rb:87:in `to_time'
Dry::Types::CoercionError (2019-11-26 16:16:50 +0000 is not a string)
obj.class == Time ? obj : coerce(obj, Time)
module Types
include Dry::Types(default: :nominal)
CompactArray = Types::Coercible::Array.constructor { |vs| vs.map(&:presence).compact.map }
SplittingCompactArray = Types::Coercible::Array.constructor do |vs|
vs
.flat_map { |v| v.is_a?(::String) ? v.split(',') : v }
.map(&:presence)
.compact
.map
end
end
Hey guys, I'm trying to wrap my head around the difference between
optional(:age).filled(:integer, gt?: 18)
optional(:age).maybe(:integer, gt?: 18)
To me this reads that age
is optional in both cases and that when the value is present it should be typecasted as integer and be greater than 18. I Feels like the two statements are identical - or am I missing something?
@lenart the latter one allows to pass NIL:
contract = MyContract.new
contract.call(age: nil, age2:nil)
#<Dry::Validation::Result{:age=>nil, :age2=>nil} errors={:age=>["must be filled"]}>
The optional keyword allows you to completely SKIP the key, so it would be valid for validator.call({})
because you can omit both of them. But if you pass any value, only one can be nil, and the other one needs to be present and castable to Integer.
include Dry::Transaction
class AdminService << ApplicationService
step :validation
step :check_active
step :privileges
def validation; end
def check_active; end
def privileges; and
end
class UserService << AdminService
step :validation
step :check_active
step :privileges
def privileges; and
end
class UserService << AdminService
def privileges; and
end