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

Zdrve/config #188

Closed
wants to merge 9 commits into from
Closed

Zdrve/config #188

wants to merge 9 commits into from

Conversation

zdrve
Copy link
Collaborator

@zdrve zdrve commented Sep 16, 2022

No description provided.

Comment on lines +49 to +50
def initialize(config_from = Kennel::Config.from_env, &block)
@config = Kennel::Config.new(config_from, &block)
Copy link
Owner

Choose a reason for hiding this comment

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

passing a config instance to config.new seems strange, can we pass in a config instead ?

Suggested change
def initialize(config_from = Kennel::Config.from_env, &block)
@config = Kennel::Config.new(config_from, &block)
def initialize(config = Kennel::Config.from_env)
@config = config

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can pass in anything which responds to to_h.

Copy link
Owner

Choose a reason for hiding this comment

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

if someone needs to configure the config they can do it outside, and we can remove the block interface for initialize
can even make config a keyword-arg to leave room for future additions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yielding a mutable config object during build is a very common style that I'd like to keep.

Copy link
Owner

Choose a reason for hiding this comment

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

The most common for I see is keyword-args (also easy to build/debug etc), if things get more complicated then yielding+config object might make sense though.
Kennel is for users that don't necessarily know a lot of ruby, so keeping things simple ("pass in a hash" vs "yield this config object") is nice.

Comment on lines +24 to +31
# A block can be passed to `.new` or `.from_env`. If a block is given,
# then after any settings have been copied from `from` (if given),
# a mutable config object will be yielded to the block, so that
# the config can be set up:
#
# config = Kennel::Config.new do |c|
# c.strict_imports = false
# end
Copy link
Owner

Choose a reason for hiding this comment

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

if someone wants to modify the config they can create their own object and pass it in ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup.

Copy link
Owner

Choose a reason for hiding this comment

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

I meant: we can remove the block interface and do Config.new strict_imports: false to have less api surface makes the input easier to test since we can have a "base" hash that gets modified each test instead of having to deal with a block

# c.strict_imports = false
# end
#
# Once built, a config object is immutable.
Copy link
Owner

Choose a reason for hiding this comment

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

not a fan of that, makes testing/experimenting harder 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have the exact opposite viewpoint. Mutability makes testing harder. Don't like the config? Make a new one.

Copy link
Owner

Choose a reason for hiding this comment

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

if it's a global object then yeah, if it's per-instance then I don't really see the benefit since there would be a new one per test anyways
(no big deal either way)

].freeze
private_constant :ATTRS

attr_reader(*ATTRS)
Copy link
Owner

Choose a reason for hiding this comment

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

just use an attr_accessor ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No thanks. No validation.

@@ -114,7 +120,7 @@ def write_file_if_necessary(path, content)
end

def syncer
@syncer ||= Syncer.new(api, generated, project_filter: project_filter, tracking_id_filter: tracking_id_filter)
@syncer ||= Syncer.new(config, api, generated, project_filter: project_filter, tracking_id_filter: tracking_id_filter)
Copy link
Owner

Choose a reason for hiding this comment

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

I like the config as first argument, ideally tracking_id_filter + project_filter would also live in there, but that can come later

@@ -4,8 +4,11 @@ module Kennel
module Compatibility
def self.included(into)
class << into
%I[out out= err err= strict_imports strict_imports= generate plan update].each do |sym|
define_method(sym) { |*args| instance.public_send(sym, *args) }
%I[generate plan update].each do |sym|
Copy link
Owner

Choose a reason for hiding this comment

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

FYI actually prefer the simpler:

Suggested change
%I[generate plan update].each do |sym|
[:generate, :plan, :update].each do |sym|

Comment on lines +38 to +40
config = Kennel::Config.from_env do |c|
c.strict_imports = false
end
Copy link
Owner

Choose a reason for hiding this comment

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

another neat api could be:

Suggested change
config = Kennel::Config.from_env do |c|
c.strict_imports = false
end
config = Kennel::Config.from_env.merge(strict_imports: false)

@zdrve zdrve closed this Nov 4, 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
Development

Successfully merging this pull request may close these issues.

2 participants