Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autogenerate *? methods for outputs. #59

Merged
merged 17 commits into from
Apr 27, 2022
Merged

Autogenerate *? methods for outputs. #59

merged 17 commits into from
Apr 27, 2022

Conversation

rockwellll
Copy link
Contributor

@rockwellll rockwellll commented Apr 24, 2022

This is a continuation of #58. Closes #58

Since these methods are not often used and there is no guarantee the developer would want one. They are only generated when a call is made for an output value that has been defined.

This way, these methods(ending with ?) will never be generated if not called.

This uses the standard way OpenStruct defines methods, in listening to method_missing and checking if there is an attribute defined on the object.

    def method_missing(symbol, *args)
      attribute = symbol.to_s.chomp("?")

      if symbol.end_with?("?") && respond_to?(attribute)

Then, we define the method on the fly and call it immediatly to return the result to the caller.

        define_singleton_method symbol do
          attribute_value = send(attribute.to_sym)

          # ActiveSupport ships with native #present?
          # Delegate to ActiveSupport's Object#present? if ActiveSupport is present
          attribute_value.respond_to?(:present?) ? attribute_value.present? : !blank?(attribute_value)
        end

Copy link
Owner

@sunny sunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 😍

Can you also add a line in the README, under the unreleased section? 🙏🏻

README.md Outdated Show resolved Hide resolved
lib/service_actor/result.rb Show resolved Hide resolved
lib/service_actor/result.rb Outdated Show resolved Hide resolved
spec/result_spec.rb Outdated Show resolved Hide resolved
spec/result_spec.rb Outdated Show resolved Hide resolved
rockwellll and others added 4 commits April 24, 2022 16:43
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
@rockwellll
Copy link
Contributor Author

Awesome 😍

Can you also add a line in the README, under the unreleased section? 🙏🏻

I'm sorry. do you mean the CHANGELOG.md file?

@sunny
Copy link
Owner

sunny commented Apr 24, 2022

Woops, my bad. Yes, the CHANGELOG 😅

lib/service_actor/result.rb Outdated Show resolved Hide resolved
@rockwellll
Copy link
Contributor Author

@sunny. I've updated the codebase. Let me know if there are any other issues!.

CHANGELOG.md Outdated Show resolved Hide resolved
lib/service_actor/result.rb Outdated Show resolved Hide resolved
expect(result.respond_to?(:name?)).to eq true
end

context "String" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To follow the RSpec/ContextWording RuboCop convention, contexts should start with when, with or without.

Suggested change
context "String" do
context "when input is a String" do

@sunny
Copy link
Owner

sunny commented Apr 25, 2022

There are a few code-style suggestions that deserved to change so I changed the RuboCop configuration a bit to prefer double-quoted strings for example.

Can you fetch the latest version:

  • git fetch origin
  • git merge origin/main
  • bundle install

Make sure RuboCop & RSpec run smoothly:

  • bin/rubocop
  • bin/rspec

🙏🏻

rockwellll and others added 3 commits April 25, 2022 15:34
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
@rockwellll
Copy link
Contributor Author

rockwellll commented Apr 25, 2022

  • bin/rubocop

Thanks for these guides. I've only left with two RuboCop offences

Screenshot 2022-04-25 at 15 46 26

Should this be neglected?

@sunny
Copy link
Owner

sunny commented Apr 25, 2022

Yes, let’s turn this one off. Can you add the following to the .rubocop conf?

Style/DoubleNegation:
  Enabled: false

Also tests seem to fail on Ruby lower than 3. I think that’s because hash is actually Ruby method that return each object’s internal id. So in the spec we should probably use a different name for the result value, like options :)

@rockwellll
Copy link
Contributor Author

Hopefully. It won't give any more errors 💀

@rockwellll
Copy link
Contributor Author

@sunny any updates on this PR?.

@sunny
Copy link
Owner

sunny commented Apr 27, 2022

Looks good! That's a great addition to Actor, thank you \o/ 🎉

@sunny sunny merged commit ff769b7 into sunny:main Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants