Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Andy Holland
@AMHOL
@jodosha you're in luck then, it's all supported already
Luca Guidi
@jodosha
@AMHOL ;)
Piotr Solnica
@solnic
@jodosha do you like to provide mixins in a similar way like with validations?
Luca Guidi
@jodosha
@AMHOL @solnic yes, for instance, I will probably make this https://gist.github.com/AMHOL/83796ede7e3e3219c6f6c934823dfd3e#file-rom-repo-starter-rb-L29-L45 to happen behind the scenes
Piotr Solnica
@solnic
yep, I think getting setup in place would be a good first step
Andy Holland
@AMHOL
@jodosha would that mean exposing a generalised querying API via relation? That kind of defeats the object of the relation being there
Piotr Solnica
@solnic
ie provide config API for hanami-model where you set connection options and then it would set up ROM behind the scenes
Andy Holland
@AMHOL
The relation should make use of the dataset API to expose a domain specific query interface
Piotr Solnica
@solnic
it should also auto-require relations and optional custom mappers and commands
Andy Holland
@AMHOL
:+1: That works
Luca Guidi
@jodosha
@solnic yes
Andy Holland
@AMHOL
@solnic could this just be a plugin for rom-sql?
Piotr Solnica
@solnic
nah, it’s all there already in rom core, it’s a matter of configuring it
Andy Holland
@AMHOL
Ahh OK
Luca Guidi
@jodosha
@solnic @AMHOL I'll probably ask questions on specific topics. ;)
Andy Holland
@AMHOL
Cool :)
Piotr Solnica
@solnic
@jodosha let’s chat in rom-rb room, I’m there
Luca Guidi
@jodosha
:+1:
Piotr Solnica
@solnic
Andrew Kozin
@nepalez
@timriley I've made last 3 commits (at various times) directly to master
Aditya Tiwari
@aditya01933
Hi, I have a small question.
How can I remove code duplication in following Schemas:
Ahh .. I don't know how to paste code block in gitter
Piotr Solnica
@solnic
@aditya01933 use triple `
like that:
\`\`\`
your code
\`\`\`
oh well
Aditya Tiwari
@aditya01933
require 'dry-validation'
UserSchema = Dry::Validation.Schema do

  key(:username).required(:unique?)
  key(:name).required
  key(:email).required
  key(:password).confirm
  configure do
      config.messages_file = 'config/validations/errors.yml'
      config.input_processor = :sanitizer
     def unique?(value)
         User.find_by(username: value).nil?  
     end
  end
end
UserUpdateSchema = Dry::Validation.Schema do

  optional(:username).required(:unique?)
  optional(:name).required
  configure do
   config.messages_file = 'config/validations/errors.yml'
   config.input_processor = :sanitizer
    def unique?(value)
       User.find_by(username: value).nil?
    end
  end
end
@solnic its not perfect but better
Any solution please ???
I want to remove code duplication of configuration block and "unique" custom predicate
Piotr Solnica
@solnic
class MySchema < Dry::Validation::Schema
  configure do |config|
    config.messages = :i18n
  end

  def unique?(value)
    false
  end

  def self.define(&block)
    Dry::Validation.Schema(self, &block)
  end
end

UserSchema = MySchema.define do
  key(:email).required(:unique?)
  key(:name).required
end
@aditya01933 like that ^
Aditya Tiwari
@aditya01933
@sonic Perfect!!!!!
Thanks its exactly what i was looking for :)
Piotr Solnica
@solnic
cool :)
Aditya Tiwari
@aditya01933
@solnic one more small question..
Currently i m testing uniqueness of username like
 def unique?(value)
      User.find_by(username: value)
  end
How can i write unique? in such a way that it can test uniqueness of other keys like name, email etc too ...
?
Piotr Solnica
@solnic
there’s no built-in conveniences for this type of predicates yet
you could parameterize it for now
Aditya Tiwari
@aditya01933
like ?
Piotr Solnica
@solnic
unique?(field_name, value)
Aditya Tiwari
@aditya01933
ok
Piotr Solnica
@solnic
then key(:email).required(unique?: :email)
we’ll improve this soon, but for now that’s the only option
Aditya Tiwari
@aditya01933
ok
Thanks .. I am trying it
Chase Gilliam
@Ch4s3
Are there any examples of how to use dry-validation to validate params and/or in place of strong params?
Aditya Tiwari
@aditya01933
@Ch4s3 my above code is doing that
Piotr Solnica
@solnic
@Ch4s3 there’s nothing special about this, just replace it with dry-v schemas :)
Aditya Tiwari
@aditya01933
require 'dry-validation'

class MySchema < Dry::Validation::Schema
  configure do |config|
    config.messages_file = 'config/validations/errors.yml'
    config.input_processor = :sanitizer
  end

  def unique?(value)
    User.find_by(username: value)
  end

  def self.define(&block)
    Dry::Validation.Schema(self, &block)
  end
end

UserSchema = MySchema.define do
  key(:username).required(:unique?)
  key(:name).required 
  key(:email).required
  key(:password).required.confirm 
end


UserUpdateSchema = MySchema.define do    
  optional(:username).required(:unique?)
  optional(:name).required  
end