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

Application with default settings #6

Open
davydovanton opened this issue Jan 15, 2018 · 1 comment
Open

Application with default settings #6

davydovanton opened this issue Jan 15, 2018 · 1 comment

Comments

@davydovanton
Copy link
Owner

@davydovanton davydovanton commented Jan 15, 2018

Now we have a simple problem: how to set up default values for each abilities instance in one place?

I sugest to use something like this:

class ProjectAbilityApplication < Kan::Application
  default_options logger: MyLogger.new
end

After that we can initialize:

  • default application class
Kan::Application.new(
  comment: Comments::Abilities.new
) # => will use default Logger
  • custom application class
ProjectAbilityApplication.new(
  comment: Comments::Abilities.new
) # => will use default MyLogger
  • custom application class with other value
ProjectAbilityApplication.new(
  comment: Comments::Abilities.new(logger: MyOtherLogger.new)
) # => will use MyOtherLogger

WDYT?


UPD agter small talk with @apotonick: Maybe we need to use instance variable for settings and #call for generating a builder class 🤔

Kan::Application.new.call(
  comment: Comments::Abilities.new
) # => will use default Logger

Kan::Application.new(logger: MyLogger.new).call(
  comment: Comments::Abilities.new
) # will use MyLogger

Kan::Application.new(logger: MyLogger.new).call(
  comment: Comments::Abilities.new(logger: MyOtherLogger.new)
) # => will use MyOtherLogger
@apotonick
Copy link

@apotonick apotonick commented Jan 18, 2018

Hey, I like the third step where you can override it as an argument, but I don't understand how the ProjectAbilityApplication manages to set a MyLogger on the Comments ability object. Are you using a writer internally for that? Because that I think I wouldn't like.

@davydovanton davydovanton added this to the v0.3 milestone Jan 27, 2018
@davydovanton davydovanton removed this from the v0.3 milestone Feb 28, 2018
@davydovanton davydovanton added this to Inbox in Development Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development
  
Inbox
Development

No branches or pull requests

2 participants