Module: Strongbolt::Bolted::ClassMethods
- Defined in:
- lib/strongbolt/bolted.rb
Instance Method Summary collapse
-
#authorize_as(model_name) ⇒ Object
Authorize as another model.
-
#bolted? ⇒ Boolean
Returns true if grant is currently enable, the user is set and we’re not in the console ie when we need to perform a check.
-
#name_for_authorization ⇒ Object
Returns the model name for authorization.
-
#owned? ⇒ Boolean
Returns true if the model is owned, ie if it has a belongs_to relationship with the user class.
-
#owner_attribute ⇒ Object
Returns the name of the attribute containing the owner id.
-
#unbolted? ⇒ Boolean
Not secure if Grant is disabled, there’s no current user or if we’re using Rails console.
Instance Method Details
#authorize_as(model_name) ⇒ Object
Authorize as another model
51 52 53 |
# File 'lib/strongbolt/bolted.rb', line 51 def (model_name) @name_for_authorization = model_name end |
#bolted? ⇒ Boolean
Returns true if grant is currently enable, the user is set and we’re not in the console ie when we need to perform a check
14 15 16 |
# File 'lib/strongbolt/bolted.rb', line 14 def bolted? !unbolted? end |
#name_for_authorization ⇒ Object
Returns the model name for authorization
58 59 60 |
# File 'lib/strongbolt/bolted.rb', line 58 def @name_for_authorization ||= self.name end |
#owned? ⇒ Boolean
Returns true if the model is owned, ie if it has a belongs_to relationship with the user class
31 32 33 |
# File 'lib/strongbolt/bolted.rb', line 31 def owned? @owned ||= self <= Configuration.user_class.constantize || owner_association.present? end |
#owner_attribute ⇒ Object
Returns the name of the attribute containing the owner id
38 39 40 41 42 43 44 45 46 |
# File 'lib/strongbolt/bolted.rb', line 38 def owner_attribute return unless owned? @owner_attribute ||= if self <= Configuration.user_class.constantize :id else owner_association.foreign_key.to_sym end end |
#unbolted? ⇒ Boolean
Not secure if Grant is disabled, there’s no current user or if we’re using Rails console
22 23 24 25 |
# File 'lib/strongbolt/bolted.rb', line 22 def unbolted? Grant::Status.grant_disabled? || (defined?(Rails) && defined?(Rails.console)) || Strongbolt.current_user.nil? end |