Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Piotr Solnica
@solnic
yeah but travis is weird with caching so…maybe remove cache and restart
Ralf Schmitz Bongiolo
@mrbongiolo
@solnic the build passed on Travis, for some reason my local build doesn't want to update dry-types or is just not using the version from master, gonna check out later what's going on
Oskar Szrajer
@gotar

Another probably stupid question ;]

require "dry-validation"

module Validations
  PostValidator = Dry::Validation.Form do
    required(:title) { filled? & str? }
    required(:body){ filled? & str? }
  end
end

if I have Validator like this how I can use it with AutoInject? There is no method new to call by it, t's just a function. I need to mark it somehow or do sth else?

Blog::Container["validations.post_validator"]
NoMethodError: undefined method `new' for #<#<Class:0x007fdbb0c8b1b0>:0x007fdbb0bf2898>
    from /Users/gotar/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/dry-component-0bebc656b625/lib/dry/component/loader.rb:42:in `instance'
Nikita Shilnikov
@flash-gordon
@gotar I know @timriley had a similar issue. I don't use dry-component atm so I don't know how to handle it properly, too high level for me :)
Oskar Szrajer
@gotar
ok I have solution
just pack class around it
require "dry-validation"

module Validations
  class PostValidator
    PostSchema = Dry::Validation.Form do
      required(:title) { filled? & str? }
      required(:body){ filled? & str? }
    end

    def call(args)
      PostSchema.call(args)
    end
  end
end
Piotr Solnica
@solnic
I don't register schemas in containers
just set them as constants
Andy Holland
@AMHOL
@gotar you can pass a block to auto_register!
And use that to determine how to construct the objects
@solnic perhaps we should have a configuration and delegate that to an object
Piotr Solnica
@solnic
better to skip auto-registering schemas
just define them as constants
that's why I added block syntax for building an object
Andy Holland
@AMHOL
How come @solnic ?
Oskar Szrajer
@gotar
it will be the best if AutoInject recognize it's class or not and then defind as contant not call new on it
Andy Holland
@AMHOL
@gotar just watching your wroc_love.rb talk BTW :)
Piotr Solnica
@solnic
link pls?
Oskar Szrajer
@gotar
nothing to see :p
:cat2:
Andy Holland
@AMHOL
lol I'm sure you're being humble
Piotr Solnica
@solnic
@AMHOL it didn't feel right to use a container for things like schemas or data classes like structs and values, they are treated as app boundaries, not some "abstract service objects" that your app relies on
Andy Holland
@AMHOL
Interesting
What about using them in dry-transaction?
Piotr Solnica
@solnic
so ie whenever I see a require "some_app/validation/some_schema" I know that this thing works at a specific boundary of my system
I never used as a schema as a separate step
Andy Holland
@AMHOL
Ahh OK
You just use them in commands?
Piotr Solnica
@solnic
it's always an object that uses a schema internally and typically talks to a db through a repo or command or sutin
Andy Holland
@AMHOL
That makes sense
Piotr Solnica
@solnic
a...service object :P
one thing I still don't like is that this still mixes an http-specific schema with a lower-level app stuff
not sure how to make this nicer
w/o any duplication
Andy Holland
@AMHOL
Still not sure about the not registering them, it's still a dependency, but I don't have experience using dry-component yet
A separate transaction step? :joy:
Piotr Solnica
@solnic
@AMHOL for me it's not an abstract dependency, that's where I draw the line
think about an ActiveRecord model, it's also a boundary, and a really huge one, everywhere your code references an AR model it makes it clear that a given part of your app is coupled to a database
it's the same here, everywhere you use a schema that validates data coming from an http request it's pretty clear that this is part of your system that deals with http stuff
fwiw you could treat that as an abstract concept and only rely on its interface but I think it's an overkill
Andy Holland
@AMHOL
Yeah, I've backed myself into a corner many times trying to be too strict about things, and past experience would indicate that when I disagree with you I'm wrong lol
But I was still thinking in terms of the interface
Still not sure on that one, will have to try it out sometime I guess
Piotr Solnica
@solnic
well, we can both be right :D
I can make dry-v schemas work with auto-registration, but I don't want to ;)
Andy Holland
@AMHOL
BTW, what do you think of pre-configuring a key mapping in component?
Piotr Solnica
@solnic
wdym?
Andy Holland
@AMHOL
To allow registration under keys that don't have any relation to the class name