Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Jan Stevens
@JanStevens
And how do I create a constrained Form::Int type? I’m using StatusUpdateInterval = Form::Int.default(90).constrained(int: true) it seems to work allright
Piotr Solnica
@solnic
Like that :)
Jan Stevens
@JanStevens
awesome
Igor
@svilenkov
Is it possible to easily duplicate a Dry::Initialize object
i want to replaced an initializer object in an array with a new one with some values changes
it would be possible with attr_writer on those params, and to mutate the existing object
but if I wanted to do it in an immutable way, is there an easy way to do with initializer?
Jan Stevens
@JanStevens
I’m trying to do a nested Dry::Struct, the only problem is that the attribute can be of different possible Dry::Struct types
Example
class Cow < Dry::Struct
  attribute :sound, Types::Strict::String.default("MEEEU")
end

class Chicken < Dry::Struct
  attribute :food, Types::Strict::String.default("corn")
end

class Cage < Dry::Struct
  attribute :animal, Cow | Chicken
end
I cannot set Cage to have a chicken :D
Jan Stevens
@JanStevens
One would expect that Cage.new(animal: Chicken.new) would work but animal is always Cow
Piotr Solnica
@solnic
@JanStevens animals don’t like cages ¯_(⊙ʖ⊙)
Jan Stevens
@JanStevens
LOL
Piotr Solnica
@solnic
@JanStevens srsly though, pls report an issue, maybe it’s a bug
Jan Stevens
@JanStevens
Ha dry-rb/dry-struct#24
My example post here does work, but my code not :/
Haaa with constructor_type :schema it doesn’t work :D
Chris Richards
@cmrichards
Berg::Form looks strange...
Chris Richards
@cmrichards
Shouldn't this validation be two different validations? EditValidation and NewValidation (or whatever)? There are required fields marked as optional.
https://github.com/icelab/berg/blob/master/apps/admin/lib/admin/posts/validation/form.rb
Piotr Solnica
@solnic
@cmrichards it’s a simple bridge between formalist and dry-v IIRC
@cmrichards they could be separated
Jan Stevens
@JanStevens
Is it possible to combine multiple Dry::Struct’s? Basically I’m going to define a couple of them and then I want to inhert multiple in a different dry struct.
I was thinking on merging the underlying schema (as it seem to contain the most important parts)
or can I easily extend `include Dry::Structs :D
Piotr Solnica
@solnic
@JanStevens inheritance works but you can’t override attributes
Jan Stevens
@JanStevens
I need to inherent from multiple classes 😀
Piotr Solnica
@solnic
really?
Jan Stevens
@JanStevens
Hmm yea my usecase is rather messed up. I basically need a kind of template attribute set that can be applied to multiple classes and can be combined depending on the provided params
Piotr Solnica
@solnic
so just use a module and class_eval attributes in included hook
Jan Stevens
@JanStevens
For example Animal -> Bird -> Eagle and Food -> Rats -> Eagle
Hmm that might work
And then I initialse eagle with a type 'bold' and it should have Food: mise
Jan Stevens
@JanStevens
Basically I need the good old virtus where you can define a module and then later on include it in your instance when needed. Is the same possible in DRY world? :D
Piotr Solnica
@solnic
@JanStevens yes, as I mentioned, just define a module with included hook and class-eval
Jan Stevens
@JanStevens
@solnic small tiny example? :D
Tim Riley
@timriley
module MyThing
  def self.included(base)
    base.class_eval do
      attribute :foo, Types::Strict::String
    end
  end
end
Piotr Solnica
@solnic
module MyAttrs
  def self.included(klass)
    klass.class_eval do
        # aaand Tim was faster
  end
end
Tim Riley
@timriley
haha
Jan Stevens
@JanStevens
Haaaa I see
Oke really thanks alot :)
Tim Riley
@timriley
fairly common ruby pattern
@solnic sorry :kissing_heart:
Piotr Solnica
@solnic
@timriley :D
Tim Riley
@timriley
@solnic btw, I’m gonna work on dry-rb/dry-view#15 tonight, but it’ll be easiest done based on top of my work in dry-rb/dry-view#25, so if you have any reservations, let me know and I can hold off.
Piotr Solnica
@solnic
@timriley I don’t, if it works better for you then go for it
Tim Riley
@timriley
Thanks @solnic :)
dry-view 0.2.0 is going to be a big release
Piotr Solnica
@solnic
I don’t like conditionals in templates but enforcing that seems to be an overkill, esp in the early days of a project, so I’m not surprised it didn’t work well for you
Tim Riley
@timriley
yeah, I know what you mean. I think if you did want to avoid them, it is something that you can build extra tooling around on top of a less opinionated base
i.e. dry-view with #25 applied would hoefully not stop people from being stricter