Class: Talkie::Permission
- Inherits:
-
Object
- Object
- Talkie::Permission
- Defined in:
- lib/talkie/permission.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #allow?(action, comment = Talkie::Comment.new) ⇒ Boolean
- #comment_form_displayable? ⇒ Boolean
-
#initialize(user) ⇒ Permission
constructor
A new instance of Permission.
Constructor Details
#initialize(user) ⇒ Permission
Returns a new instance of Permission.
7 8 9 |
# File 'lib/talkie/permission.rb', line 7 def initialize(user) @user = user end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/talkie/permission.rb', line 5 def user @user end |
Instance Method Details
#allow?(action, comment = Talkie::Comment.new) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/talkie/permission.rb', line 15 def allow?(action, comment = Talkie::Comment.new) action = action.to_s if user return true if action.in? %w[create index] return true if action.in?(%w[destroy]) && user.owns_comment?(comment) end false end |
#comment_form_displayable? ⇒ Boolean
11 12 13 |
# File 'lib/talkie/permission.rb', line 11 def comment_form_displayable? user.present? end |