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

Attribute values > to_phlex_attribute_value, to_str, to_s #629

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

joelmoss
Copy link
Contributor

Fixes #569

Attribute values can be any object that responds to to_phlex_attribute_value or to_str, falling back to to_s if neither is defined.

…ttribute_value` or `to_str`,

falling back to `to_s` if neither is defined
@joelmoss joelmoss mentioned this pull request Jan 29, 2024
@joeldrapper
Copy link
Collaborator

This looks good to me. I’m happy with to_str coming first.

@joelmoss joelmoss marked this pull request as ready for review January 30, 2024 09:11
v.to_s
end

buffer << " " << name << '="' << ERB::Escape.html_escape(value) << '"'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will need to be updated because of a change I made.

Suggested change
buffer << " " << name << '="' << ERB::Escape.html_escape(value) << '"'
buffer << " " << name << '="' << Phlex::Escape.html_escape(value) << '"'

Copy link
Collaborator

@joeldrapper joeldrapper left a comment

Choose a reason for hiding this comment

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

Looks good @joelmoss. Unless anyone else has any comments, I’m happy to go with this.

Copy link
Contributor

@willcosgrove willcosgrove left a comment

Choose a reason for hiding this comment

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

This looks good! Thanks for doing this! I left one note on the tests to ensure that they're testing for precedence

Comment on lines +5 to +15
class ToPhlexAttributeValueable
def to_phlex_attribute_value
"to_phlex_attribute_value"
end
end

class ToSable
def to_s
"to_s"
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

So that we can test for method precedence as well, what do you think about making these test classes build on each other like this:

Suggested change
class ToPhlexAttributeValueable
def to_phlex_attribute_value
"to_phlex_attribute_value"
end
end
class ToSable
def to_s
"to_s"
end
end
class ToPhlexAttributeValueable < ToSable
def to_phlex_attribute_value
"to_phlex_attribute_value"
end
end
class ToSable < ToStrable
def to_s
"to_s"
end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but not sure it's necessary. The code is hugely simple, so I think testing much more than the existence of the methods has very little benefit.

Happy to add if that's the consensus.

@joeldrapper joeldrapper merged commit a910442 into phlex-ruby:main Jan 30, 2024
17 checks passed
@joeldrapper
Copy link
Collaborator

Oh, good point re tests. I’ll open an issue for that since I merged this already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

to_str vs to_s
3 participants