-
Notifications
You must be signed in to change notification settings - Fork 11
Basic logger implementation #7
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
Basic logger implementation #7
Conversation
84e52b3
to
39a5951
Compare
lib/kan/abilities.rb
Outdated
@@ -8,6 +10,8 @@ module ClassMethods | |||
DEFAULT_ROLE_NAME = :base | |||
DEFAULT_ROLE_BLOCK = proc { true } | |||
|
|||
attr_accessor :logger |
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.
Why getter in class methods? 🤔
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.
We have to use instance variable for this instead class methods
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.
In this case logger use class scope and methods
class Post::Abilities
include Kan::Abilities
register 'read' do |user, _|
logger # => logger instance
logger.info 'Something happened'
true
end
end
Need to think how to pass logger from ability instance to action.
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.
just use #instance_exec
:)
class Abilities
def initialize(rules)
@rules = rules
end
def ability
rule = @rules[:post]
proc { |payload| instance_exec(payload, &rule) }
end
def logger
'I am logger'
end
end
rule = proc { |params| puts "logger: #{logger}; hello; #{params}" }
a = Abilities.new(post: rule)
p a.ability
a.ability.call(test: :test)
# => #<Proc:0x007f85c3a2eef0@proc.rb:7>
# => logger: I am logger; hello; {:test=>:test}
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.
So, let’s set instanse for logger, and after that merge.
About “global” logger: I have a idea how to change default values for each abilities and I want to play with it today :)
Thanks for your activity I really appreciate it 💯
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.
Thanks for you work, it's great.
Could you rebase your branch from master? I want to check specs (I added CI) ❤️
2664c20
to
4006e5f
Compare
Awesome work, thanks for quick response 🔥 |
This is initial version of logger.
TODO: refactor default logger initialization.