Class: RsUserPolicy::Policy::JsonPolicy
- Inherits:
-
Object
- Object
- RsUserPolicy::Policy::JsonPolicy
- Includes:
- Policy
- Defined in:
- lib/rs_user_policy/policy/json_policy.rb
Instance Method Summary collapse
-
#get_permissions(roles, account_href) ⇒ Array<String>
Returns an array of permissions for a particular role in a particular RightScale account.
-
#initialize(options = {}) ⇒ JsonPolicy
constructor
Initializes a new Policy.
Constructor Details
#initialize(options = {}) ⇒ JsonPolicy
Initializes a new Policy
If more than one source is passed into options, the order of preference will be
- :json, :json_str, :filename
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rs_user_policy/policy/json_policy.rb', line 43 def initialize(={}) if ([:filename, :json, :json_str] & .keys()).empty? raise ArgumentError, "You must supply either a filename, JSON string, or a JSON object" end if .has_key?(:json) @policy = [:json] elsif .has_key?(:json_str) @policy = JSON.parse([:json_str]) else @policy = JSON.parse(File.read([:filename])) end validate() end |
Instance Method Details
#get_permissions(roles, account_href) ⇒ Array<String>
Returns an array of permissions for a particular role in a particular RightScale account
65 66 67 68 69 70 71 72 73 |
# File 'lib/rs_user_policy/policy/json_policy.rb', line 65 def (roles, account_href) = [] roles.each do |role| if @policy.has_key?(role) = + (@policy[role][account_href] || @policy[role]['default'] || []) end end .uniq end |