Sha256: 303b3b2394d5fcfcfb33260175a690eec98cf3d5c7208bf55d7e92625d98b131

Contents?: true

Size: 626 Bytes

Versions: 2

Compression:

Stored size: 626 Bytes

Contents

GOVERNOR_AUTHOR = Proc.new do |actor|
  if actor.respond_to?(:current_user)
    actor.current_user
  else
    raise "Set up GOVERNOR_AUTHOR in #{File.expand_path(__FILE__)}"
  end
end

Governor.authorize_if do |actor, action, article|
  case action.to_sym
  when :new, :create
    # if respond_to?(:user_signed_in?)
      actor.user_signed_in?
    # else
    #   raise "Set up Governor.authorize_if in #{File.expand_path(__FILE__)}"
    # end
  when :edit, :update, :destroy
    article.author == GOVERNOR_AUTHOR.call(actor)
  else
    raise ArgumentError.new('action must be new, create, edit, update, or destroy')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
governor-0.1.1 lib/generators/governor/templates/governor.rb
governor-0.1.0 lib/generators/governor/templates/governor.rb