These are chat archives for dry-rb/chat

26th
Jul 2016
Tim Riley
@timriley
Jul 26 2016 11:01
Going to make -auto_inject and -component releases tonight, and bump dry-web-roda to make sure it uses the changed dry-component injector method in the new project generator.
Piotr Solnica
@solnic
Jul 26 2016 11:02
@timriley awesome news :)
timriley @timriley wonders what version bump to give to dry-web-roda though...
Tim Riley
@timriley
Jul 26 2016 11:03
0.current.bump or 0.bump.0
Piotr Solnica
@solnic
Jul 26 2016 11:04
I think 0.bump.0
mostly because you run it on production, mature enough to be beta :laughing:
Tim Riley
@timriley
Jul 26 2016 11:05
oh yeah, it’s already on 0.something.x
Just wondering whether a change in a project generator constitutes a bugfix or a breaking change...
Russell Edens
@rx
Jul 26 2016 11:10
@timriley hoping dry-rb/dry-component#21 makes the dry-component release. @solnica there is a proposed change to auto_register! In the issue that needs an opinion.
Tim Riley
@timriley
Jul 26 2016 11:11
@rx It won’t make tonight’s release, no. I’d like to make sure we have time to properly consider things. However, I’m happy to release often :)
Russell Edens
@rx
Jul 26 2016 11:21
@timriley cool, thx
Tim Riley
@timriley
Jul 26 2016 12:21
Travis ಠ_ಠ
Gem::InstallError: dry-auto_inject requires Ruby version >= 2.1.0.
An error occurred while installing dry-auto_inject (0.4.0), and Bundler cannot
continue.
Make sure that `gem install dry-auto_inject -v '0.4.0'` succeeds before
bundling.
oh
I need to change the minimum ruby there
sigh
I’ll fix this now.
Tim Riley
@timriley
Jul 26 2016 12:32
OK, that’s sorted in 0.4.1 :disappointed_relieved:
Fran Worley
@fran-worley
Jul 26 2016 12:33
@timriley are any others likely to be affected by that?
Tim Riley
@timriley
Jul 26 2016 12:34
If they update both -auto_inject as well as -component, yes. Reckon I should yank 0.4.0?
I will.
Done. Now no one will get stranded on that version.
timriley @timriley has learnt his lesson about coordinating multiple gem releases :disappointed:
Fran Worley
@fran-worley
Jul 26 2016 12:36
Now now, let's not cry over spilt milk :wink:
Tim Riley
@timriley
Jul 26 2016 12:37
:)
Piotr Solnica
@solnic
Jul 26 2016 12:38
yeah it’s hard :D
I handled a couple of DataMapper releases…10+ gems at once
scary stuff
Tim Riley
@timriley
Jul 26 2016 12:39
jeepers
Fran Worley
@fran-worley
Jul 26 2016 12:40
Think I'll stick with dabbling in dry-logic for now!!
Tim Riley
@timriley
Jul 26 2016 13:01
I realise there’s a second side to this default namespace stuff in dry-component: having it work properly for lazy loading of components
when the file is foo/bar.rb but the injector is just being asked for “bar”
(because “foo” is the default namespace)
sigh
actually, it’s not just in lazy loading
it’s when you’re finalizing a container
auto-registrtion runs alphabetically on files, so if foo/bar.rb auto-injects “baz” (expecting the default namespace to turn it into foo/baz.rb), it’ll crash
OK, this needs more work
What a pain that I didn’t realise this in testing
Tim Riley
@timriley
Jul 26 2016 13:10
OK, so I can make a small fix to get this working:
in Component::Container.load_component
          begin
            require_component(component) { |klass| register(key) { klass.new } }
          rescue ArgumentError => e
            if config.default_namespace
              load_component("#{config.default_namespace}#{config.namespace_separator}#{component.identifier}")
            else
              raise e
            end
          end
Catch failures to load the component based on its identifier name, and then try again with the default namespace added to the front.
We could obviously tighten that up a bit but it’d get this release fully working.
We could then take the time to consider alternative approaches
if e.g. we wanted a different identifier structure to indicate that something should have the default namespace appended
e.g. include MyApp::Import[“.foo”]
^ a leading separator character could signify this component should have the default namespace prepended
this is like how Swift handles its shorthand for enum items
Tim Riley
@timriley
Jul 26 2016 13:34
OK, 0.4.2 is out for -component and we’re golden
what a night
After going through all of this, I’m thinking a better way to do default namespacing would be for a custom container resolver.
I’ll file an issue
I’m going to stop releasing things now and go to sleep :grin:
Juanma Cervera
@jmcervera
Jul 26 2016 13:57
Hi everyone,
I have already seen the great introduction to ROM by Tim Riley.
Now, I want to learn how to use it, writing a script to work with a postgres database.
I would like to setup a project for that, and use rspec for testing, but I'm having problems with all this DI thing.
I really appreciate if somebody could point me to an example/tutorial where I can see how ROM objects are used in testing,
and some recommendation for the structure of that project.
Juanma Cervera
@jmcervera
Jul 26 2016 14:10
Sorry, I made a mistake and this is not the correct group. Forget about it and I'll make the question in the correct ont
Kevin Ross
@rosskevin
Jul 26 2016 19:16
in dry-validation, not seeing examples on string length. Can any of the built-in predicates be used for string length 6..20?
Piotr Solnica
@solnic
Jul 26 2016 19:25
@rosskevin you want size?: 6..20
Kevin Ross
@rosskevin
Jul 26 2016 19:26
great, thank you. Might want to update http://dry-rb.org/gems/dry-validation/basics/built-in-predicates/ Checks that an array’s size is equal to the given value.
btw - thanks for your work on this @solnic, it's great to use
Piotr Solnica
@solnic
Jul 26 2016 19:43
@rosskevin cool! :) we’ll be updating docs with 0.10.0 release + PRs for doc updates are always welcome
Kevin Ross
@rosskevin
Jul 26 2016 19:46
can a validation rule set a custom message? it's interpolated with values
sample with old message
          rule(:sender_matches_plan?, [:plan_id, :sender_id]) do |plan_id, sender_id|
            plan = AfCore::Plan.find(plan_id)
            if sender_id.to_i != plan.catalog.possessor.books.id
              #errors.add :sender_id, "Sender #{sender_id} should be the same as plan's owner #{plan.catalog.possessor.books.id}"
              false
            end
            true
          end
Piotr Solnica
@solnic
Jul 26 2016 19:53
@rosskevin this will be supported in 0.9.4 or 0.10.0
Kevin Ross
@rosskevin
Jul 26 2016 19:54
Great, in this case, it's just a sanity check, nothing i18n that a user would see
Piotr Solnica
@solnic
Jul 26 2016 19:56
I added partial support for dynamic arguments in 0.9.2 but it doesn’t support high-lvl rules yet
Kevin Ross
@rosskevin
Jul 26 2016 22:54
confused about high level rules, can I access the value of params within them? (using reform/trailblazer), for example in the above, need to access the value for plan_id
Tim Riley
@timriley
Jul 26 2016 22:55
value(:plan_id) ?
Kevin Ross
@rosskevin
Jul 26 2016 22:56
I need the numeric value, not adding another predicate. I thought the high level rules allowed me to implement a custom predicate inline
You are saying Plan.find(value(:plan_id))?
Here is a more complete snippet of my attempt:
validation :default, schema_class: Validations::Schema do
  required(:plan_id).value(:id?)
  required(:sender_id).value(:id?)

  rule(sender_matches_plan?: [:plan_id, :sender_id]) do |plan_id, sender_id|
    plan = Plan.find(plan_id)
    if sender_id.to_i != plan.catalog.possessor.books.id
      false
    end
    true
  end
end
where :id? is implemented as a custom predicate in my schema as
      def id?(value)
        !value.nil? && value.class == Integer && value > 0
      end
Tim Riley
@timriley
Jul 26 2016 22:59
I’d move all of that logic into a predicate, I think. plan_matches_sender?(sender_id, plan_id)
then inside your rule you can go plan_id.plan_matches_sender?(value(:sender_id))
Kevin Ross
@rosskevin
Jul 26 2016 23:02
not sure about your second line there, here's what I've got now:
validation :default, schema_class: Validations::Schema do
  required(:plan_id).value(:id?)
  required(:sender_id).value(:id?)

  rule(sender_matches_plan?: [:plan_id, :sender_id]) do |plan_id, sender_id|

  end

  def sender_matches_plan?(plan_id, sender_id)
    plan = Plan.find(plan_id)
    if sender_id.to_i != plan.catalog.possessor.books.id
      false
    end
    true
  end
end
Tim Riley
@timriley
Jul 26 2016 23:03
your predicate def needs to go into a configure do … end block
Kevin Ross
@rosskevin
Jul 26 2016 23:03
yes, that's implicit here, sorry I didn't mention that
Tim Riley
@timriley
Jul 26 2016 23:03
then inside your rule block that’s where you can put plan_id.plan_matches_sender?(value(:sender_id))
ok, sorry, opposite:
sender_id.sender_matches_plan(value(:plan_id))
in fact, you may not even need the high-level rule anymore...
Kevin Ross
@rosskevin
Jul 26 2016 23:04
I depend on both values, only reason I had it
Tim Riley
@timriley
Jul 26 2016 23:04
Actually, yes, you do
yeah
Piotr Solnica
@solnic
Jul 26 2016 23:06
high-lvl needs some love :)
Kevin Ross
@rosskevin
Jul 26 2016 23:06
so confused about the execution inside the rule:
validation :default, schema_class: Validations::Schema do
  required(:plan_id).value(:id?)
  required(:sender_id).value(:id?)

  rule(assert_sender: [:plan_id, :sender_id]) do |plan_id, sender_id|
     sender_id.sender_matches_plan?(value(:plan_id))
  end

  def sender_matches_plan?(plan_id, sender_id)
    plan = Plan.find(plan_id)
    if sender_id.to_i != plan.catalog.possessor.books.id
      false
    end
    true
  end
end
Tim Riley
@timriley
Jul 26 2016 23:07
@rosskevin what happens when you run that?
Kevin Ross
@rosskevin
Jul 26 2016 23:07
inside the rule, both are args are, what do you call it?
Tim Riley
@timriley
Jul 26 2016 23:07
@solnic yeah, it’s an area of slight awkwardness still :)
Piotr Solnica
@solnic
Jul 26 2016 23:07
yeah it’s because it goes back to older dry-v
Kevin Ross
@rosskevin
Jul 26 2016 23:07
I did a mass migration, so I'm not up and running yet, still squashing bad conversion errors
ok, I'll just stick with this and keep pushing until I come out the other end.
only have about 8 or so of these in the app
+sender_matches_plan?+ is not a valid predicate name (ArgumentError) - I'll check to make sure I'm registering custom predicates with reform properly
I do need the configure in reform as well - my misunderstanding
Kevin Ross
@rosskevin
Jul 26 2016 23:18
Ok, another code review please, assuming model is available from my base schema:
validation :default, schema_class: Validations::Schema do
  configure do
    def has_next?
      !model.next.nil?
    end

    def is_downgrade?
      model.plan.is_downgrade?(model.next.plan)
    end

    def next_not_active?
      model.next.uninitialized? || model.next.future_active?
    end
  end

  required(:id).value(:id?, :has_next?, :is_downgrade?, :next_not_active?)
end
look ok?