These are chat archives for dry-rb/chat

13th
Mar 2016
Piotr Solnica
@solnic
Mar 13 2016 10:50
hey y’all, we’ve been working on the official website for dryrb org, and it’s getting close to be ready-enough to be launched. I ported all dry-v docs there and I could really use some help with updating “AR Comparison” section here. Please lemme know if anybody is interested in helping with this :) /cc @fran-worley
Fran Worley
@fran-worley
Mar 13 2016 10:55
@solnic I'd love to help. I'm back from a little trip to Scotland on Tuesday and can take a look then.
At the updates pushed to ruby gems or are we still working from master?
Piotr Solnica
@solnic
Mar 13 2016 10:56
@fran-worley oh fantastic :) I’d like to release new dry-v in a couple of days, for now - you gotta use master (with dry-types from master, too)
I’m only fixing bugs these days, although that’s a lie, I added a new feature yesterday :joy:
but yeah, it’s going finally out in a couple of days, I’m certain 100000%
I’ll be revamping docs a bit, adding more info about core ideas and how it works, more info about predicate composition and high-level rules etc
Shaun Hannah
@hooptie45
Mar 13 2016 19:42
Anyone ever thought about integrating this with a testing library? Rspec’s composable matchers are really great for testing, but very hard to debug when they fail.
I’m thinking we could integrate dry-validations and use it as for better assertions, and much better failure messages.
Piotr Solnica
@solnic
Mar 13 2016 19:44
@hooptie45 that’s an intriguing idea :)
Shaun Hannah
@hooptie45
Mar 13 2016 19:44
rspec/rspec-expectations#712
Lol, I’m thinking i’ll give it a shot.
Shaun Hannah
@hooptie45
Mar 13 2016 19:55

I’ve been spelunking through the dryrb code for a little while. It’s facinating, and some really good work. I’d like to try it out on a side project; I figure this might be a good opportunity.

I’d love to help out with this project.

Piotr Solnica
@solnic
Mar 13 2016 19:58
@hooptie45 ah thank you Shaun :) there’s always a ton of work to do, help is very much appreciated
which gems are you considering to use?
Piotr Solnica
@solnic
Mar 13 2016 20:07
@AMHOL would you have some time to add pages for a couple of projects to dryrb website? just literally copy/paste from README’s for a good start would be awesome
Andy Holland
@AMHOL
Mar 13 2016 20:12
@solnic yeah, should be able to tomorrow night I think
Shaun Hannah
@hooptie45
Mar 13 2016 20:18

The thing I’m trying to build would use the Dry types and validations.

It’s a common problem I think. In any app you have models. If you use Rails, your models are all nicely typed because they derive the type info from the DB. I’m picturing a library that could give you the strong typing, and other niceties, but wouldn’t need to be tied to rails, or a DB.

There is also the problem of transforming your models from one shape to another. Picture a SOA. You might get the “same domain object" for each different service, but each service will implement them in different ways. What I want is a way to declare a domain models once, and then have a declarative API for transforming them into into the right format for the various services I’ll be communicating with.

This is actually a real problem where I work. We have a library that does it, but its painfully slow. I think I could do it better and much faster using these gems.

Piotr Solnica
@solnic
Mar 13 2016 20:30
performance is one of the priorities
Shaun Hannah
@hooptie45
Mar 13 2016 20:31

I feel like if you’ve already declared the validations for a model, then the typing should really just work. If I declared in my validations that an attrubute should be a certain type, with certain charactoristics; then I think its safe to assume the underlying model would also have those types.

Maybe not for all cases, but it’s a good start.

I’ve noticed! I really like that Guard api you recently added. It can eliminate whole code paths very early on.

Piotr Solnica
@solnic
Mar 13 2016 20:32
oh you really did look into the code :)
Shaun Hannah
@hooptie45
Mar 13 2016 20:38
An example:

      describe 'deep mapping' do
        let(:attributes) do
          {
            "Deeply" => {
              "Nested" => {
                "Foo" => "123"
              }
            }
          }
        end

        before do
          klass.class_eval do
            attribute :foo, 'Deeply/Nested/Foo'
          end
        end

        it 'should map the nested attributes' do
          instance.attributes = attributes
          expect(instance.foo).to eq 123
        end

        it 'should used map back to then service format' do
          instance.attributes = attributes
          expect(instance.to_legacy_service).to eq {
            "Deeply" => {
              "Nested" => {
                "Foo" => "123"
              }
            }
          }

        end
class DryModel
  attribute :foo, :type => Money

  with_mapping(:legacy_service)
    attribute :foo, “Foo”, :type => Double
   end

  with_mapping(:xml_service)
    attribute :foo, “XML/FOO”, :type => Float
   end

end