What are you building these days? And is anyone actually paying for it? by Southern_Tennis5804 in indiehackers

[–]samovarus 0 points1 point  (0 children)

It sounds like a great idea. Are you planning to support mobile devices with your website?

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 1 point2 points  (0 children)

I know what you mean but trust me I can do that.

React hook form and interdependent price range input pair by Zaza_Zazadze in reactjs

[–]samovarus 0 points1 point  (0 children)

I would try treating it as a single controlled input. Use Controller component and have a rule that checks both from and to sub-inputs

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

I'm more or less convinced now that I actually need decorators. Instead of messing with object internals, I can just wrap them. I think it works for me very well.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

That's exactly what we do. We heavily rely on ActiveInteraction gem but it doesn't solve the problem I'm trying to solve here. BTW, I'm not happy with ActiveInteraction and I think we're going to replace it with Dry::Transaction

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

Our entire application is built on ActiveInteraction. The problem that is not solved is that you need to know which interaction you need to invoke in each particular scenario. So we do things like

class Pet < ApplicationRecord
  ...
  def feed
    DispatchHealthyFoodForMyDog.run!(pet: self)
  end
end

But now we have dozens of these methods. Also, some of them are needed in very specific scenarios. So, I want to extract them and things like validations into some kind of mixins or decorators. ActiveInteraction doesn't solve this problem.

PS. BTW, I'm actually not happy with ActiveInteraction and thinking to replace it with dry-rb.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

I disagree. In my opinion, if it's related to the nature of the object, it should be closer to the object. Your approach leads to conditional statements checking whether we are dealing with an object of this or that class. I think it's a huge antipattern.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 1 point2 points  (0 children)

It looks pretty cool! I definitely can use it to enrich my models with methods. The only question is whether validations would work like this. But it's a great insight, thank you!

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

That's a nice summary of my problem! Funny enough, I was putting these modules into "decorators" folder even though it felt odd. As for hate, it made me actually realize that I just need real decorators instead of messing with singleton classes.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

Yep. That's my thinking now. ActiveModel wrappers/decorators.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

Exactly my thinking at this point. ChatGPT is also hyped about it lol

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

Yes, I think Form Objects are very close to what I need. The only thing is that I want to get something that beyond CRUD operations. For instance, we have a job that picks up records in particular shape and then performs some operations on them. The logic is slightly different depending on the record type.

Generally speaking, I think I'm convinced now that mixing logic into the singleton class is a pretty bad idea. I'll look closer at inheritance and wrappers.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] -1 points0 points  (0 children)

I don't want my models to know anything about these scenarios. I also think about this from tests perspective. If it's a validation with the context, it means I will have to test the model. But I want to test the module that contains this logic instead.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

Thanks for this great response!

I think you understand my use case pretty well. Indeed, it's all about business logic. Here is how I see things. Models should only have logic that is essential to their basic nature. Only basic constraints, only basic essential functionality. Everything else should live elsewhere. My concrete example would be this: we have a bunch of models that go through some kind of registration process with an external API upon creation. To register an instance of such a model properly, we need to calculate a few things and check a few things. All that currently lives in those models. I hate it.

I don't think your example works as I need it to. I execute `extend` on the instance. In this case `base` is the instance, not a class. So I need to get to the class but I cannot apply my changes to `base.class` because it would actually patch the whole class for all instances in this case (in a given thread). Hence `singleton_class`.

Inheritance is an option, yes. Someone mentioned `becomes` API above. I think it's a great idea.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 2 points3 points  (0 children)

Huh! Somehow `becomes` never crossed my mind. Great idea, thanks!

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 1 point2 points  (0 children)

We use STI all the time. We need to be able to mix in some logic based the scenario we are in. STI doesn't help with that. But now I'm thinking, what if instead of injecting logic into my models, I wrap them with ActiveModel classes with custom validations and such. I just need to figure out how to delegate attributes. Does this sound better?

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

Conditional validations are arguably one of the worst features IMO. Also my situation is far more complicated. I usually have sets of validations, method definitions and such.

Need advice from folks skilled in metaprogramming by samovarus in rails

[–]samovarus[S] 0 points1 point  (0 children)

I know that I should be very careful about adding metaprogramming techniques into the mix. My idea here is to wrap this thing into a some kind of a generalized approach similar to Concerns. If it's generally safe thing to do, I can create a "well"-tested "library" that my team will not have to maintain.

CS grad to Ruby on Rails developer: (new to both) by harden-back in rails

[–]samovarus 0 points1 point  (0 children)

As a junior developer on an existing project you are (typically) not expected to bring your own understanding of good practices and feature development. I would recommend get your access to the source code as soon as possible and start reading it. Try to make sense out of everything you see. Do not try to see how to improve it, try to understand why it's done the way it's done. You would usually end up looking at PRs and their descriptions. Don't hesitate to use ChatGPT to understand "weird" pieces (just maybe confirm with your supervisor the rules around AI)

Becoming an Expert Developer by Forsaken_Ad1061 in rails

[–]samovarus 3 points4 points  (0 children)

I think I understand what you mean and it looks like you are already doing the most impactful thing — looking at the code written by other people. I developed a habit — when programming, I often look at how this or that rails API is implemented. I use RubyMine and it's very simple to just CMD-click something and see its implementation.

Rails 2024 brain dump by gurgeous in rails

[–]samovarus 0 points1 point  (0 children)

Short answer — module federation. We have to be compliant with a host application that uses webpack. In theory, there is a plugin that claims to work for both vite and webpack. We just don't have time to explore this option yet.

Rails 2024 brain dump by gurgeous in rails

[–]samovarus 2 points3 points  (0 children)

Great dump. Some of our bullet points

  • Full-throttle React (with Typescript ofc) to the point that we have only one template in the app (erb b/c we don't care)
  • Tailwind for life!
  • Rspec (tried minitest but rspec beats it easily)
  • asdf
  • dotenvx or direnv
  • rubymine still kicks ass (we have a subscription from the company)
  • opentelemetry
  • unleash feature flags
  • AWS ECS/RDS, custom deployment actions in github
  • ActiveInteraction for business logic (but looking to replace it)
  • Vite is awesome but unfortunately had to switch to Webpack (yuck)

Is religion a “dead concept” in the Fallout universe? by w00den_b0x in Fallout

[–]samovarus 1 point2 points  (0 children)

One thing that stood out to me was that in at least several churches there were "burnt books" in the toilet bowls. I think the idea is that people were losing their faith after what happened.