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

Feature/add variable type registry #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

imdrasil
Copy link

@imdrasil imdrasil commented Oct 8, 2018

  • allow registering custom types
  • add ENVied.[] which avoids #method_missing invocation; it raises ArgumentError if given variable is not defined

@imdrasil imdrasil requested a review from locochris October 8, 2018 08:04
@imdrasil imdrasil added the enhancement New feature or request label Oct 8, 2018
#
# @return [Hash] of type names and their definitions.
def supported_type?(type)
name = type.to_sym.downcase

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 👍

Copy link

@johncarney johncarney left a 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

@imdrasil
Copy link
Author

@johncarney nice idea. But I still have to use separate containers for the default types and custom. The reason is that default types use ENVied::Coercer::ENViedString methods and custom ones - ENVied::Coercer

@imdrasil imdrasil force-pushed the feature/add_variable_type_registry branch from e75c7e6 to 9d5d84e Compare October 17, 2018 07:47
@johncarney
Copy link

Ok. I'll take your word for it :)

@dxg dxg force-pushed the feature/add_variable_type_registry branch from 9d5d84e to da6a2d7 Compare July 2, 2021 03:43
Copy link

@dangalipo dangalipo left a 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

@dxg dxg closed this in e9a61da Jul 2, 2021
@dxg dxg reopened this Jul 2, 2021
@dxg dxg force-pushed the feature/add_variable_type_registry branch from b08fea1 to 9c007cc Compare July 2, 2021 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants