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

Use the generic type map object for mysql field lookups #15200

Merged
merged 1 commit into from
May 20, 2014

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented May 20, 2014

No description provided.

@sgrif
Copy link
Contributor Author

sgrif commented May 20, 2014

/cc @senny

module Type
class HashLookupTypeMap < TypeMap # :nodoc:
def lookup(type)
@mapping[type].try(:call, type) || default_value
Copy link
Member

Choose a reason for hiding this comment

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

Could we not use try? 🙏

@sgrif
Copy link
Contributor Author

sgrif commented May 20, 2014

@rafaelfranca Updated.

@rafaelfranca
Copy link
Member

Waiting the build run.

@@ -317,23 +317,17 @@ def cast_value(value)
end
end

TYPES = {}
class << self
TYPES = ConnectionAdapters::Type::HashLookupTypeMap.new
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a difference between putting a constant inside or outside the class << self block?

Copy link
Member

Choose a reason for hiding this comment

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

Not that I know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

delegate :register_type, to: :TYPES will fail if it's outside of the class << self block.

Copy link
Contributor

Choose a reason for hiding this comment

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

is TYPES part of public api? if not, perhaps this should be class instance var instead (or cattr_reader)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not consider it part of the public API, but I'm also not opposed to that change.

Copy link
Member

Choose a reason for hiding this comment

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

It is not. I'll make it with nodoc

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I thought I already merged this. @sgrif could you add nodoc comment?

@sgrif
Copy link
Contributor Author

sgrif commented May 20, 2014

@rafaelfranca Nodoc added.

rafaelfranca added a commit that referenced this pull request May 20, 2014
Use the generic type map object for mysql field lookups
@rafaelfranca rafaelfranca merged commit 5300844 into rails:master May 20, 2014
@sgrif sgrif deleted the sg-type-map-mysql branch March 14, 2018 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants