module Strongbolt::Bolted::ClassMethods
Public Instance Methods
bolted?()
click to toggle source
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
# File lib/strongbolt/bolted.rb, line 14 def bolted? !unbolted? end
owned?()
click to toggle source
Returns true if the model is owned, ie if it has a belongs_to relationship with the user class
# File lib/strongbolt/bolted.rb, line 31 def owned? @owned ||= self <= Configuration.user_class.constantize || owner_association.present? end
owner_attribute()
click to toggle source
Returns the name of the attribute containing the owner id
# 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?()
click to toggle source
Not secure if Grant is disabled, there's no current user or if we're using Rails console
# File lib/strongbolt/bolted.rb, line 22 def unbolted? Grant::Status.grant_disabled? || (defined?(Rails) && defined?(Rails.console)) || Strongbolt.current_user.nil? end
Private Instance Methods
owner_association()
click to toggle source
Returns the association to the user, if present
# File lib/strongbolt/bolted.rb, line 67 def owner_association @owner_association ||= reflect_on_all_associations(:belongs_to).select do |assoc| if assoc.options.key? :polymorphic false else assoc.klass <= Configuration.user_class.constantize end end.try(:first) end