Sha256: f967ca64ac0a0d850c3c21aea497ecd5a23335eea5f909a0b4c636c841d14fae

Contents?: true

Size: 946 Bytes

Versions: 3

Compression:

Stored size: 946 Bytes

Contents

class Power
  include Consul::Power

  def initialize(user = nil)
    @user = user
  end

  power :clients do
    Client.active unless guest?
  end

  power :client_notes do |client|
    client.notes
  end

  power :notes do
    Note.scoped(:joins => :client)
  end

  power :always_true do
    true
  end

  power :always_false do
    false
  end

  power :always_nil do
    nil
  end

  power :cakes do
    :cakes
  end

  power :updatable_cakes do
    :updatable_cakes
  end

  power :creatable_cakes do
    :creatable_cakes
  end

  power :destroyable_cakes do
    :destroyable_cakes
  end

  def assignable_user_roles
    %w[guest admin]
  end

  power :key_figures do
    %w[amount working_costs] unless guest?
  end

  power :api_key do
    'secret-api-key' unless guest?
  end

  private

  attr_accessor :user

  def role
    user.role
  end

  def admin?
    user.role == 'admin'
  end

  def guest?
    user.role == 'guest'
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
consul-0.4.2 spec/shared/app_root/app/models/power.rb
consul-0.4.1 spec/shared/app_root/app/models/power.rb
consul-0.4.0 spec/rails-2.3/app_root/app/models/power.rb