Sha256: 9ecd76f2ba3d7d945fba8485d03d67e8decc4b54308d8a5fe663a348526aeda7

Contents?: true

Size: 719 Bytes

Versions: 10

Compression:

Stored size: 719 Bytes

Contents

require 'active_record'
require 'active_support/core_ext'

Eucalypt.glob('app', '{policies}', '*.rb') do |file|
  policy_name        = File.basename file, '.rb'
  policy_constant    = policy_name.camelize.constantize
  resource_name      = policy_name.gsub '_policy', ''
  roles_name         = "#{resource_name}_roles"
  role_constant_name = roles_name.singularize.camelize
  role_constant      = role_constant_name.constantize

  if ActiveRecord::Base.connection.table_exists? roles_name
    role_constant.pluck(:permission).each do |permission|
      policy_constant.define_method "#{permission}?" do
        role_constant.find_by(permission: permission).send(user.role.send resource_name)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eucalypt-0.7.2 lib/eucalypt/security/permissions.rb
eucalypt-0.7.1 lib/eucalypt/security/permissions.rb
eucalypt-0.7.0 lib/eucalypt/security/permissions.rb
eucalypt-0.6.2 lib/eucalypt/security/permissions.rb
eucalypt-0.6.1 lib/eucalypt/security/permissions.rb
eucalypt-0.6.0 lib/eucalypt/security/permissions.rb
eucalypt-0.5.4 lib/eucalypt/security/permissions.rb
eucalypt-0.5.3 lib/eucalypt/security/permissions.rb
eucalypt-0.5.2 lib/eucalypt/security/permissions.rb
eucalypt-0.5.1 lib/eucalypt/security/permissions.rb