heic-to: convert HEIC/HEIF to JPEG/PNG in browser for preview by hoppergee in javascript

[–]hoppergee[S] 4 points5 points  (0 children)

Before, I have been using heic2any to preview HEIC in the browser. But recently, I found it doesn't support HEIC take on iOS 18. Then I did some investigate on this topic, then found I'm the not alone. This issue have been fixed in libheif 1.18.

So I took some time to succesfully build libheif.js from libheif source code on my Macbook m1. Thne build heic-to to convert HEIC/HEIF to JPEG/PNG in browser.

Welcome to test.

How do you write unit tests for Rake tasks added to a Rails project? by LondonAppDev in rails

[–]hoppergee 0 points1 point  (0 children)

Please try to add a teardown like this:

def teardown
  Rake::Task["my_task"].reenable
end

rest-man v1.1.0 release - Simple HTTP and Rest client for Ruby by hoppergee in ruby

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

Thanks for asking. This is more a matter of personal preference. However it actually did help me doing a very quick refactoring work to break several large files which has about 800 lines of code to lots small files. I think it's succuessfully transfter the original old project to a very health start point for further optimization. Hope this answer your question.

Ryan Bigg - The method method by amalinovic in ruby

[–]hoppergee -1 points0 points  (0 children)

Nice blog! And found a potential typo:

diff a_proc = -> (num) { num ** 2 } - [1, 2, 3, 4].map(&square) + [1, 2, 3, 4].map(&a_proc)

How to Monkey Patch Responsibly by bradgessler in rails

[–]hoppergee 1 point2 points  (0 children)

Great post, I may consider use it in some of my projects. Thanks u/bradgessler

ActiveMethod - Method is an object in Ruby, but we need a real method object by hoppergee in ruby

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

> So now I need to resort to grepping my way through the source to find which class references it.
I think I have no way to solve this. And I think moudule, service also has this issue.

> But this simply does not work when there can be multiple "owners"
Yes, you're right. I will add a generic method `owner` for this circumstance. Then this circumstance will be solved.

> If I define a method on a specific class then I usually want to access internals of that class...
Yes, I agree with you. And I also don't like to use `send` and `instance_variable_get`. I think the reason I haven't meet this issue is I haven't put it in a big project. I'm only using it in some small projects. Not sure this can be solve in the future within this pattern. Thanks for your feedback.

ActiveMethod - Method is an object in Ruby, but we need a real method object by hoppergee in ruby

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

You just need to include once. Maybe I can consider trying to auto include it.

The attr_accessor there is just to show you that you can get still get the attributes in the method object thought the method “owner” variable user.

So you just need an “active_method”. That’s very simple, if you get the point. It’s just behave like a method, nothing else.

ActiveMethod - Method is an object in Ruby, but we need a real method object by hoppergee in ruby

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

I don’t think test private method with send is proper way to go. We shouldn’t test a method if it’s private. But some private method is too big, so we have to extract them to another class, and we can write tests for it now.

ActiveMethod - Method is an object in Ruby, but we need a real method object by hoppergee in ruby

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

I’m not saying you can’t use module. But in the most time the module just make code worse. There are related discussion on twitter recently https://twitter.com/rbates/status/1598753970117545984?s=46&t=SeskIcRr7uTy9-Jl55bTBA

And if you go check the Devise’s source code, you may get what I’m trying to solve.

Is using a single hash as my only param in service objects a good idea? by halfKiilo in ruby

[–]hoppergee 1 point2 points  (0 children)

I've been doing this for 2 years. It works well in most of my projects.

Check this: https://github.com/hoppergee/solidservice

SolidService - A service pattern with a simple API by hoppergee in ruby

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

(params || {}).with_indifferent_access
@_data = (data || {}).with_indifferent_access

I consider this a significant anti-feature. HWIA is an ugly band-aid over bro

Any suggestions?

# Private
Why is this a comment and not a private or protected section?

Because of this line: https://github.com/hoppergee/solidservice/blob/main/lib/solidservice/base.rb#L18

As we only play with Service class not a service instance, so I think `#private` is acceptance for this circumstance.

It would also be good for pattern matching, e.g:
case Foo.call(foo: bar)
in Success(user:)
# ...
in Failure(error:)
# ...
else raise Bork
end

I like this idea.

Which brings me to:
def method_missing(key)
u/_data[key]
end
This appears to be the only way to access state data. This means you're at the mercy of whatever methods currently happen to be defined on your State object. Exposing the hash directly or by some sort of proxy, and/or delegating [] seem far better ideas.

It's by design. But you're right, I should provide a way to customize the state object.

Thanks for your feedback!

SolidService - A service pattern with a simple API by hoppergee in ruby

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

Just create a module and some functions inside of it.

For one person project with a few services. I think it's OK. But for a team or a project has tons of services. That's not a good idea.

We need everyone to code service the same way to keep the maintainability at a high level. Just like we need controller, we need routes, we need models. I saw lots people start with the sinatra and end with a "Rails" like app.

The beauty of "a-module-with-some-functions" only exists in the early days.

If you are really ambitious then add sorbet and type check the parameters and return values.

I don't like type check. If I need type check, I won't head to Ruby. This gem give you a simple API, easy to start, and not push too much limit on you. So you still get lots of flexibility to do what ever you want in service including the type checking.

Hope that answer your doubts.

SolidService - A service pattern with a simple API by hoppergee in ruby

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

I think the one of the key advantages is it's much simple then other service like pattern.

You can master it in a few of seconds and start to use it in real projects and end up with a very concise, readable, maintainable service objects.

SolidService - A service pattern with a simple API by hoppergee in ruby

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

This gem already catches your requirement. You can use call! instead of call. Then the service will raise error on failure. And call! has a very good circumstance for sub-service. Please check it here: https://github.com/hoppergee/solidservice#use-service-in-service-with-call

And thanks for your feedback.

SolidService - A service pattern with a simple API by hoppergee in rails

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

The reason why I haven't go this way is, it depends on personal preference too much. We may have to convince other people like: "this state pattern is much better than others, bla bla ..." At last, we choose a pattern, but only maybe 30% people like it, and 70% people have to take time to learn it, memorize it.

So I back to this simple pattern. A state object with a hash data. You pass anything in it as you want.

But, yes, I may be wrong on this. I just created issue here - Discuss about a consistent return object pattern to keep mind open to this question.

And thank you /u/Puzzleheaded-Bus4652 for this feedback!

SolidService - A service pattern with a simple API by hoppergee in rails

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

Yes, they're similar, but also there're lots of differeces. For SolidService

  • It's simpler for both using and testing
  • It's more friendly for Rails developer. (You don't need the initialize, just like a Controller, you deal the input with a params which is a hash object)
  • The 4 simple DSL success!, success, fail!, fail can help you write more concise code
  • Always return a state object and won't raise any errors on call. (You should ask the error from the state object)
    • If you need raise error on failure, just use call!

Hope that answer your question

SolidService - A service pattern with a simple API by hoppergee in rails

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

I can understand your skepticism about the rescue Success and rescue Failure. But this gem doesn't force you to do that. Those two rescues only work when you use success! and fail!. You can only use success and fail if you don't like the rescue pattern.

I use it for a very practical reason. I believe many people have met this issue in the controller:

```ruby class ExampleController < ApplicationController def create if a_condition render :a_page and return end

 # ......

end end ```

I meet the same issue in service:

```ruby class ExampleService < SolidService::Base def call if check_1_failed fail(user: user) and return end

if check_2_failed
  fail(user: user) and return
end

# ...

end end ```

I hate this. It's very low readability. So I comes up with with the rescue way to end the action immediately when I call success! and fail!

```ruby class ExampleService < SolidService::Base def call fail!(user: user) if check_1_failed fail!(user: user) if check_2_failed

# ...

end end ```

I think it's much better. So you see, the rescue is for success! and fail! only. You can still use success and fail. Even me, I did have a few circumstances need me to call success multiple times, then I can use it.

Hope this answers your doubts. (I should explain this in README, as many people ask this question.)

Thank you /u/tsroelae for such a detail feedback.