Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Tim Riley
@timriley
right, OK. So if you’re providing a container and it’s a Dry::System::Container, then I’d expect a boot sequence for the container to be something like this when running in a production-like environment:
# Require the container
require_relative "main/container"

# Load files with manually registered dependencies
Main::Container.require "component/container/persistence"

# Finalize the container, which does auto-registration if you've configured it
Main::Container.finalize!
That way your container reaches a reliable state right up front and is frozen from there
the lazy loading feature of non-finalized dry-system containers is really meant for isolated unit testing, where you want it to be fast, so you load up an empty container (don’t finalize) and then rely on the lazy loading to get just the right combination of components you need for your unit test to run
Tim Riley
@timriley
If you don’t want to require your consumers to undergo a “boot” process like this, then maybe dry-system is not what you want. (But then you’d do without features like auto-registration etc., but I’m not sure how important they are for you in this thing you’re building)
Andrew Thauer
@andrewthauer
I think, I’d be fine having the consumer go through a boot process. The initial consumer will be a rails application. So my initial thought is to have config/initializer that does the boot process your suggesting (where the middle line loading the rails defined repositories, etc.). I’ll have to try out a couple things to see what works. Thanks for you help!
George Millo
@georgemillo
is there any documentation for dry-view?
Valentin Trinqué
@ValentinTrinque

Hi guys, I have some trouble using dry-validation. I am trying to ensure that some ids I receive from my API are actually valid records in my database. In my form I have this :

property sender_ids
required(:sender_ids) do
  filled? & array?
end
rule(valid_senders: [:sender_ids]) do |sender_ids|
   Contact.exists?(id: value(:sender_ids))
end

But it raises the following error :

POST /letters with valid data returns the new letter
Failure/Error:
  rule(valid_senders: [:sender_ids]) do |sender_ids|
    Contact.exists?(id: value(:sender_ids))
  end

NoMethodError: undefined method `with' for false:FalseClass
# ./.gems/gems/dry-validation-0.10.4/lib/dry/validation/schema/value.rb:96:in `rule'
# ./app/forms/letter/create_form.rb:31:in `block in <class:CreateForm>’

Do you have any idea ?

Valentin Trinqué
@ValentinTrinque
I fixed the problem by creating a valid_contacts? function inside configure hook and call it from the required statement
Tim Riley
@timriley
@georgemillo unfortunately no docs right now, we’re still figuring dry-view out a little bit. I hope to spend some of January on it and hopefully doc some things up then too.
Christopher Dennl-Ortega Arrieta
@cdennl
@ValentinTrinque for arbitrary boolean checks you dont want to use rule but validate, see dry-v docs
rule just works on predicates
Andriy Tyurnikov
@andriytyurnikov
Hello. @timriley do you have some plans about dry-web-roda || icelab/dry-web-skeleton ?
Andriy Tyurnikov
@andriytyurnikov
Basicaly it would be nice to know if you guys fundamentally opposed to idea of adding foreman and dotenv to the dry-web-roda default stack
Ilya Bylich
@iliabylich
Hi there. Currently I'm trying to replace AM::Validations with dry-validations but I can't generate correct error message. Let's say I have a scheme with attribute
optional(:attribute_name) { eql?('') | none? | (str? & format?(/\w+/) & max_size?(10)) }
By calling
MyScheme.call(attribute_name: 'some invalid value').messages
I'm getting errors as a single string
{:attribute_name=>["must be equal to or must be a string or is in invalid format or size cannot be greater than 10"]}
I need to have one error message for all kind of errors, like "Attribute name must contain < 10 symbols from the following list: ..."
Is it possible?
After a quick look at Dry::Validation::MessageCompiler I guess it doesn't support any options for switching generating strategies...
Christopher Dennl-Ortega Arrieta
@cdennl
@iliabylich write a custom predicate/rule and make a message for it
Ilya Bylich
@iliabylich
This is the default behavior in my system (which means that I have to write custom predicate for each attribute)
I've tried to read the source code of dry-validation and it seems that | (Or) is the only node in produced AST that gets converted to a non-array value
By using &, > or ^ my errors messages are not joined. This code is a problem for me - https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/message.rb#L35 - and I have no idea how to solve it without patching
Christopher Dennl-Ortega Arrieta
@cdennl
@iliabylich no you write ONE predicate which does aggregates all the single validations and call this one, and this predicate you can give a custom message
def my_predicate
  return eql? || none? || ... #this is pseudo code
end

my_predicate: 'custom message'

optional(:attr) { my_predicate }
Tim Riley
@timriley
@andriytyurnikov dry-web already has some sort of application config system, but I’m interested in making it behave a little more like dotenv instead of using a .yml file. As for foreman, this seems like something that’s better suited to people’s own skeletons or applications rather than being built in?
Pol Miro
@polmiro

hi! I'm running into a struggle with dry-transaction and I wonder if it is something any of you have run into.

1)The interface expected is always in the form call(input) but since we have been using dry-initializer a lot, our callable objects are initialized with the input, and called with call() without any arguments.
I can wrap the registered methods so they get called correctly but seems a bit of an overhead. Step adapters don't really solve anything since they adapt the handling of the output but not the way the method is called.
Is there any way to streamline this? Has any of you felt this need before?

Pol Miro
@polmiro
2) In a similar fashion, the schemas from dry-validation return a Dry::Validation::Result, which resembles a lot to a Dry::Monads::Either class but it's not, so dry-transaction does not work when chaining a dry-validation schema directly. I wonder if the dry-transaction contract could accept results in a more dynamically typed way so that this would not happen.
Tim Riley
@timriley
@polmiro I haven’t run into someone using dry-transaction with objects like yours before. I’d really recommend against setting your input as state via the initializer, because that means your objects become stateful, non-reusable, and you effectively have to throw them away after #call-ing them once.
the kind of object that dry-transaction is designed to work with is one that receives static things in its initializer (config or collaborating objects, i.e. things that never need to change), and then #call is receives the variable input.
This means you can have the same object and #call on it many times over.
As for (2), there’s actually a “monads” extension for dry-validation that lets you return either objects: https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/extensions/monads.rb
you could provie a base validation schema class for your app with a #call method that does that to_either conversion for you
(or I suppose write a step adapter to do it)
Pol Miro
@polmiro
cool that makes sense, thanks for the explanation Tim :thumbsup:
Pol Miro
@polmiro
it's great to hear about that monads extension, did not realize it existed
Pol Miro
@polmiro
where could I find more usage examples of dry-transaction?
Tim Riley
@timriley
A couple of releases this morning!
Lonnie VanZandt
@lonniev

newbie here. I watched @timriley's Singapore presentation and really liked the functional-ity and separation of concerns. I'm looking for some convention to surround me as I get started with these new-to-me dry and rom capabilities. Something like a "click here to download Trailblazer with skeleton support for a Riley-like dry/rom app".Is there any getting-started resource like that? Maybe @fran-worley can recommend where someone new to both dry/rom and Trailblazer should start if they have no legacy app to evolve?

I'm really interested in the ROM Relations concept that allows architect/developers to work with objects that look like business objects rather than detailed database scaffolding because the kind of applications that I work on have complex object-with-object relationships and all relational database repositories eventually so pollute the network-graph business concepts that the business services often have to be simplified or be reduced in flexibility if the relational-model details are implemented in the business objects themselves. Therefore, the dry/rom architecture of separating out associations as proper objects, of separating out repository query handlers, of separating out functional dependency-injected command objects, from the business objects themselves is intoxicating.

Lonnie VanZandt
@lonniev
Hmm, may be "...dry-web-roda gem and then generate a new project via the dry-web-roda new my_app_name..." from a recent reply by @timriley . Back to googling.
Oskar Szrajer
@gotar
generating new project might by a good idea, but a lot strange (new) ideas you will find there. So go directory -> file by file and ask.
asking here might be the best idea to understand it @lonniev
Tim Riley
@timriley
@lonniev you can also check out icelab/Berg on github for a real functioning app
I plan to make some improvements to dry-web this Jan and Feb, too, including docs.
Oskar Szrajer
@gotar
berg can be really hard to understand but of course it's wonderful source of knowleadge I used it many times
Eger Andreas
@andreaseger
hi, is there a way to make dry-validation care about unknown keys, meaning adding a UnknownKeysError?
Lonnie VanZandt
@lonniev
@timriley, yes, I spotted Berg in your github repos and thought that might be a good starter sample. Now, both you and @solnic have mentioned that your cool dry-system and rom components could or do work with Trailblazer and Hanami. I'd like to see an example of that. Got one? @gotar, yes, there's often nothing better than taking time to RTFC(ode). :-)
Piotr Solnica
@solnic
@lonniev berg is pretty big so I agree with @gotar that it could feel overwhelming a bit
We just need a Todo app or a blog app examples. Something very basic but complex enough to show off some important features
Steve
@dnd
is there any kind of built in predicate to check whether a field is true or not? I have a form that has a valid? method, and rather than make a custom predicate or something, I was hoping something already existed to do it in a generic way