-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/add variable type registry #1
base: master
Are you sure you want to change the base?
Conversation
lib/envied/coercer.rb
Outdated
# | ||
# @return [Hash] of type names and their definitions. | ||
def supported_type?(type) | ||
name = type.to_sym.downcase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interresting. I didn't know you could downcase
a symbol 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a much simpler way to achieve custom types. Leave ENVied::Coercer
as-is and add this to ENVied::Configuration
:
def type(name, &block)
coercer.supported_types.push(name.to_sym).uniq!.sort!
coercer.define_singleton_method("to_#{name}", &block)
end
Or, if coercer
is not persistent, you can define the method on the class.
def type(name, &block)
coercer.supported_types.push(name.to_sym).uniq!.sort!
coercer.class.define_method("to_#{name}", &block)
end
@johncarney nice idea. But I still have to use separate containers for the default types and custom. The reason is that default types use |
e75c7e6
to
9d5d84e
Compare
Ok. I'll take your word for it :) |
9d5d84e
to
da6a2d7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10/10 GREATEST COMMIT EVER
b08fea1
to
9c007cc
Compare
ENVied.[]
which avoids#method_missing
invocation; it raisesArgumentError
if given variable is not defined