These are chat archives for dry-rb/chat

16th
May 2016
Andrew Kozin
@nepalez
May 16 2016 07:41
What is the policy for gems plugins like this one https://github.com/nepalez/dry-initializer-rails ? Do we want them to be reposited at dry-rb?
Piotr Solnica
@solnic
May 16 2016 08:11
@nepalez yes assuming that one of dry-rb team members is willing to maintain it
Andrew Kozin
@nepalez
May 16 2016 11:11
one more question. I've updated docs for dry-initializer at dry-rb.org. How could I publish those updates?
Tim Riley
@timriley
May 16 2016 11:17
@nepalez bundle exec middleman deploy :)
Andrew Kozin
@nepalez
May 16 2016 11:18
@timriley thanks! will made a try
Tim Riley
@timriley
May 16 2016 11:18
Let me know how it goes!
Andrew Kozin
@nepalez
May 16 2016 11:21
@timriley
/dry-rb.org $ bundle exec middleman deploy
/home/nepalez/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_data.rb:170: warning: key :lang is duplicated and overwritten on line 170
== Executing: `./node_modules/webpack/bin/webpack.js --bail`
== External: Command failed with message: No such file or directory - ./node_modules/webpack/bin/webpack.js
Tim Riley
@timriley
May 16 2016 11:22
OK, so you’ll want to see if the whole thing works locally first
Andrew Kozin
@nepalez
May 16 2016 11:22
yes
Tim Riley
@timriley
May 16 2016 11:22
Looks like you need to npm install first
then you can bundle exec middleman build to see if it’ll build locally
if that succeeds, then you should be fine to deploy
what’s also handy is just bundle exec middleman, which will spin up a preview server
Andrew Kozin
@nepalez
May 16 2016 11:24
Hmm... thats tricky one. My mint (ubuntu 14) makes this npm install a hard thing to do. Will do it later on free time
Piotr Solnica
@solnic
May 16 2016 11:25
also don’t forget to stand on one foot, touch your nose with your left hand, and your left ear with your right hand, then curse node.js 3 times, this should make it work, at least worked for me
Tim Riley
@timriley
May 16 2016 11:28
@nepalez want me to deploy your changes?
@solnic I for one <something> our new front-end overlords
Andrew Kozin
@nepalez
May 16 2016 12:09
@timriley it would be great
Vasilis Spilka
@vasspilka
May 16 2016 12:10
This message was deleted
Tim Riley
@timriley
May 16 2016 12:10
@nepalez have you pushed them up into a branch or are they just on master?
@vasspilka I don’t think the Symbol#to_proc works like that when you have to supply an argument.
Vasilis Spilka
@vasspilka
May 16 2016 12:13
I see @timriley thanks, I'm deleting the question as its unrelated
Luca Guidi
@jodosha
May 16 2016 12:55
It's done!
Tim Riley
@timriley
May 16 2016 12:56
Nice work @jodosha!
Luca Guidi
@jodosha
May 16 2016 12:56
Thank you all! :green_heart:
Fran Worley
@fran-worley
May 16 2016 12:56
Thank you @jodosha, here's to the start of a long and happy alliance!
Luca Guidi
@jodosha
May 16 2016 12:56
@timriley @fran-worley :tada:
Piotr Solnica
@solnic
May 16 2016 12:59
:tada: :cocktail: :wine_glass: :beers: :tada:
Luca Guidi
@jodosha
May 16 2016 13:01
@solnic And as we speak, I'm starting to work on hanami-model w/ ROM ;)
Piotr Solnica
@solnic
May 16 2016 13:02
@jodosha ooh, thanks for the heads-up, gonna join rom-rb “just in case”
Luca Guidi
@jodosha
May 16 2016 13:03
@solnic Thank you. Any GH repo where to start? rom-repository? In my understanding the website doesn't report 2.0 changes yet.
Piotr Solnica
@solnic
May 16 2016 13:03
@jodosha tell me what you want to do, more or less
Luca Guidi
@jodosha
May 16 2016 13:04
@solnic for now just play with ROM + repository to refresh my memories, understand what's changed and what's possible to do.
Piotr Solnica
@solnic
May 16 2016 13:06
@jodosha grab rom-repo from master then and look at latest specs, these are pretty high-level tests so should give you an overview of what’s possible
Luca Guidi
@jodosha
May 16 2016 13:06
@solnic thank you! :)
Piotr Solnica
@solnic
May 16 2016 13:06
I was going to add a bin/console to rom-repo but ran out of time
basically to have the same setup as we have in specs loaded for you so it’s easy to open console and do stuff
The last two are quite old
Damn, forgot that Gitter would expand those, sorry for the flood :(
Luca Guidi
@jodosha
May 16 2016 13:27
@AMHOL Thank you! :green_heart:
Andy Holland
@AMHOL
May 16 2016 13:27
:+1:
Piotr Solnica
@solnic
May 16 2016 13:28
@jodosha do you have any ideas what kind of integration you’d want to have?
Luca Guidi
@jodosha
May 16 2016 13:29
@solnic My goals are: remove boilerplate as much as possible, SQL automapping, associations and command/queries.
Andy Holland
@AMHOL
May 16 2016 13:34
@jodosha you're in luck then, it's all supported already
Luca Guidi
@jodosha
May 16 2016 13:34
@AMHOL ;)
Piotr Solnica
@solnic
May 16 2016 13:37
@jodosha do you like to provide mixins in a similar way like with validations?
Luca Guidi
@jodosha
May 16 2016 13:38
@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
May 16 2016 13:39
yep, I think getting setup in place would be a good first step
Andy Holland
@AMHOL
May 16 2016 13:39
@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
May 16 2016 13:40
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
May 16 2016 13:40
The relation should make use of the dataset API to expose a domain specific query interface
Piotr Solnica
@solnic
May 16 2016 13:40
it should also auto-require relations and optional custom mappers and commands
Andy Holland
@AMHOL
May 16 2016 13:40
:+1: That works
Luca Guidi
@jodosha
May 16 2016 13:41
@solnic yes
Andy Holland
@AMHOL
May 16 2016 13:41
@solnic could this just be a plugin for rom-sql?
Piotr Solnica
@solnic
May 16 2016 13:41
nah, it’s all there already in rom core, it’s a matter of configuring it
Andy Holland
@AMHOL
May 16 2016 13:41
Ahh OK
Luca Guidi
@jodosha
May 16 2016 13:51
@solnic @AMHOL I'll probably ask questions on specific topics. ;)
Andy Holland
@AMHOL
May 16 2016 13:52
Cool :)
Piotr Solnica
@solnic
May 16 2016 13:54
@jodosha let’s chat in rom-rb room, I’m there
Luca Guidi
@jodosha
May 16 2016 13:54
:+1:
Piotr Solnica
@solnic
May 16 2016 14:26
Andrew Kozin
@nepalez
May 16 2016 14:53
@timriley I've made last 3 commits (at various times) directly to master
Aditya Tiwari
@aditya01933
May 16 2016 16:53
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
May 16 2016 16:55
@aditya01933 use triple `
like that:
\`\`\`
your code
\`\`\`
Aditya Tiwari
@aditya01933
May 16 2016 16:55
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
Piotr Solnica
@solnic
May 16 2016 16:55
oh well
Aditya Tiwari
@aditya01933
May 16 2016 16:57
@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
May 16 2016 17:05
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
May 16 2016 17:08
@sonic Perfect!!!!!
Thanks its exactly what i was looking for :)
Piotr Solnica
@solnic
May 16 2016 17:10
cool :)
Aditya Tiwari
@aditya01933
May 16 2016 17:21
@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
May 16 2016 17:23
there’s no built-in conveniences for this type of predicates yet
you could parameterize it for now
Aditya Tiwari
@aditya01933
May 16 2016 17:23
like ?
Piotr Solnica
@solnic
May 16 2016 17:23
unique?(field_name, value)
Aditya Tiwari
@aditya01933
May 16 2016 17:24
ok
Piotr Solnica
@solnic
May 16 2016 17:24
then key(:email).required(unique?: :email)
we’ll improve this soon, but for now that’s the only option
Aditya Tiwari
@aditya01933
May 16 2016 17:24
ok
Thanks .. I am trying it
Chase Gilliam
@Ch4s3
May 16 2016 17:25
Are there any examples of how to use dry-validation to validate params and/or in place of strong params?
Aditya Tiwari
@aditya01933
May 16 2016 17:25
@Ch4s3 my above code is doing that
Piotr Solnica
@solnic
May 16 2016 17:25
@Ch4s3 there’s nothing special about this, just replace it with dry-v schemas :)
Aditya Tiwari
@aditya01933
May 16 2016 17:25
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
config.input_processor = :sanitizer
Chase Gilliam
@Ch4s3
May 16 2016 17:26
are you including that or writing it directly in the controller?
Aditya Tiwari
@aditya01933
May 16 2016 17:26
i am including it in controller. I am writing above code in separate file under app/validations folder
In my controller I have
def dry_validation  
      parameters = params[:user]
      @schema = UserSchema.(parameters)
      unless @schema.success?
       render json:{message: @schema.messages}, status: 401
      end
 end
Piotr Solnica
@solnic
May 16 2016 17:27
you always want to memoize schema objects, defining a schema on each request won’t be efficient
Chase Gilliam
@Ch4s3
May 16 2016 17:27
gotcha
Aditya Tiwari
@aditya01933
May 16 2016 17:28
before_action :dry_validation, only: :create
Chase Gilliam
@Ch4s3
May 16 2016 17:29
ok. that makes sense. So this is practical for per endpoint schemas then. That's awesome!
Aditya Tiwari
@aditya01933
May 16 2016 17:29
Yeah!!
Piotr Solnica
@solnic
May 16 2016 17:32
we could provide dry-validation-rails for nice integration with rails
Chase Gilliam
@Ch4s3
May 16 2016 17:37
that would be interesting
Let me try out dry-validation with a few of the endpoints I use for ajax, and I'll see if I can document what works well for the use case
Aditya Tiwari
@aditya01933
May 16 2016 19:03
@solnic I am trying this but not working
key(:username).required(:unique?, :username)

 def unique?(field, value)
      User.where("#{field} = ? ", value).count == 0    
  end
What is right way ?
Fran Worley
@fran-worley
May 16 2016 19:14
@aditya01933 try this:
key(:username).required(unique?:  :username)
Aditya Tiwari
@aditya01933
May 16 2016 19:17
@fran-worley syntax error, unexpected ':', expecting ')'
key(:username).required(:unique? :username)
Fran Worley
@fran-worley
May 16 2016 19:18
Yeah, your colon is in the wrong place
it should read the way I wrote it: key(:username).required(unique?: :username) not key(:username).required(:unique? :username)
Aditya Tiwari
@aditya01933
May 16 2016 19:19
ahhh .. what a mistake!!
Fran Worley
@fran-worley
May 16 2016 19:21
@aditya01933 is it working now?
Aditya Tiwari
@aditya01933
May 16 2016 19:22
yes perfectly !!
Thanks :)
Fran Worley
@fran-worley
May 16 2016 19:22
great :)
Aditya Tiwari
@aditya01933
May 16 2016 19:25
thanks
James Hamilton
@wjdhamilton
May 16 2016 20:16
Hi @solnic! in your talk last year you mentioned a gem called Autocurry. Is it available yet?
Piotr Solnica
@solnic
May 16 2016 20:50
@wjdhamilton no, sorry, Barcelona was too beautiful to sit in my hotel room and work on another gem and when I went back home I got distracted by so many things that I kind-of forgot about it…I’m planning to create a new dry gem with various fp-features, not sure if it makes sense to have a separate gem just for auto-curry behavior, we’ll see