Method: Mist::Configuration#authorize

Defined in:
lib/mist/configuration.rb

#authorize(*types, &block) ⇒ Object

Register a block to be invoked whenever Mist needs to know if a user is allowed to perform some action, such as :create_post, :edit_post, :view_post, :destroy_post, or :all.

Mist.authorize { |controller| ... }               # invoke for any action not otherwise registered
Mist.authorize(:all) { |controller| ... }         # same as above
Mist.authorize(:create_post) { |controller| ... } # use this block only for :create_post

By default, all authorization requests will return false (denied).

Raises:

  • (ArgumentError)


54
55
56
57
58
# File 'lib/mist/configuration.rb', line 54

def authorize(*types, &block)
  raise ArgumentError, "Expected a block which will be evaluated at runtime" unless block_given?
  types.push :all if types.empty?
  types.each { |type| authorizations[type] = block }
end