cantango-permits 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +39 -0
  3. data/Gemfile.lock +155 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.mdown +362 -0
  6. data/Rakefile +45 -0
  7. data/VERSION +1 -0
  8. data/lib/cantango/executor.rb +5 -0
  9. data/lib/cantango/executor/base.rb +9 -0
  10. data/lib/cantango/executor/permit.rb +7 -0
  11. data/lib/cantango/executor/permit/abstract.rb +27 -0
  12. data/lib/cantango/executor/permit/base.rb +19 -0
  13. data/lib/cantango/executor/permit/special.rb +9 -0
  14. data/lib/cantango/executor/permit_type.rb +50 -0
  15. data/lib/cantango/license.rb +19 -0
  16. data/lib/cantango/license/rules.rb +17 -0
  17. data/lib/cantango/permit.mdown +4 -0
  18. data/lib/cantango/permit.rb +5 -0
  19. data/lib/cantango/permit/account_type.rb +44 -0
  20. data/lib/cantango/permit/attribute.rb +71 -0
  21. data/lib/cantango/permit/base.rb +94 -0
  22. data/lib/cantango/permit/class_methods.rb +49 -0
  23. data/lib/cantango/permit/helper.rb +11 -0
  24. data/lib/cantango/permit/helper/execution.rb +38 -0
  25. data/lib/cantango/permit/helper/host.rb +13 -0
  26. data/lib/cantango/permit/helper/license.rb +34 -0
  27. data/lib/cantango/permit/helper/naming.rb +38 -0
  28. data/lib/cantango/permit/helper/state.rb +21 -0
  29. data/lib/cantango/permit/special.rb +17 -0
  30. data/lib/cantango/permit/user.rb +36 -0
  31. data/lib/cantango/permit/user_type.rb +34 -0
  32. data/lib/cantango/permits.rb +20 -0
  33. data/lib/cantango/permits_ext.rb +7 -0
  34. data/lib/cantango/permits_ext/ability.rb +7 -0
  35. data/lib/cantango/permits_ext/ability/helper.rb +9 -0
  36. data/lib/cantango/permits_ext/ability/helper/permits.rb +8 -0
  37. data/lib/cantango/permits_ext/builder.rb +7 -0
  38. data/lib/cantango/permits_ext/builder/permit.rb +9 -0
  39. data/lib/cantango/permits_ext/builder/permit/account_type.rb +13 -0
  40. data/lib/cantango/permits_ext/builder/permit/base.rb +94 -0
  41. data/lib/cantango/permits_ext/builder/permit/special.rb +13 -0
  42. data/lib/cantango/permits_ext/builder/permit/user_type.rb +7 -0
  43. data/lib/cantango/permits_ext/class_methods.rb +28 -0
  44. data/lib/cantango/permits_ext/config.rb +11 -0
  45. data/lib/cantango/permits_ext/config/engines.rb +9 -0
  46. data/lib/cantango/permits_ext/config/engines/permit.rb +20 -0
  47. data/lib/cantango/permits_ext/config/permits.rb +43 -0
  48. data/lib/cantango/permits_ext/config/permits/accounts.rb +15 -0
  49. data/lib/cantango/permits_ext/config/permits/disabling.rb +22 -0
  50. data/lib/cantango/permits_ext/config/permits/enabling.rb +14 -0
  51. data/lib/cantango/permits_ext/config/permits/execution.rb +21 -0
  52. data/lib/cantango/permits_ext/config/permits/key.rb +19 -0
  53. data/lib/cantango/permits_ext/config/permits/registration.rb +33 -0
  54. data/lib/cantango/permits_ext/config/permits/tracking.rb +19 -0
  55. data/lib/cantango/permits_ext/config/permits/types.rb +25 -0
  56. data/lib/cantango/permits_ext/engine.rb +7 -0
  57. data/lib/cantango/permits_ext/engine/permits.rb +75 -0
  58. data/lib/cantango/permits_ext/factory.rb +7 -0
  59. data/lib/cantango/permits_ext/factory/permits.rb +40 -0
  60. data/lib/cantango/permits_ext/finder.rb +7 -0
  61. data/lib/cantango/permits_ext/finder/base.rb +35 -0
  62. data/lib/cantango/permits_ext/finder/permit.rb +7 -0
  63. data/lib/cantango/permits_ext/finder/permit/account.rb +47 -0
  64. data/lib/cantango/permits_ext/finder/permit/base.rb +53 -0
  65. data/lib/cantango/permits_ext/loader.rb +7 -0
  66. data/lib/cantango/permits_ext/loader/categories.rb +50 -0
  67. data/lib/cantango/permits_ext/loader/license.rb +19 -0
  68. data/lib/cantango/permits_ext/macros.rb +7 -0
  69. data/lib/cantango/permits_ext/macros/permit.rb +32 -0
  70. data/lib/cantango/permits_ext/parser.rb +7 -0
  71. data/lib/cantango/permits_ext/parser/categories.rb +15 -0
  72. data/lib/cantango/permits_ext/registry.rb +7 -0
  73. data/lib/cantango/permits_ext/registry/permit.rb +45 -0
  74. data/lib/generators/cantango/account_permit/account_permit_generator.rb +37 -0
  75. data/lib/generators/cantango/account_permit/templates/account_permit.erb +23 -0
  76. data/lib/generators/cantango/base.rb +71 -0
  77. data/lib/generators/cantango/basic.rb +41 -0
  78. data/lib/generators/cantango/license/license_generator.rb +29 -0
  79. data/lib/generators/cantango/license/templates/license.erb +10 -0
  80. data/lib/generators/cantango/license_base.rb +15 -0
  81. data/lib/generators/cantango/licenses/licenses_generator.rb +26 -0
  82. data/lib/generators/cantango/permit_generator.rb +58 -0
  83. data/lib/generators/cantango/role_permit/role_permit_generator.rb +39 -0
  84. data/lib/generators/cantango/role_permit/templates/account_permit.erb +4 -0
  85. data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +24 -0
  86. data/lib/generators/cantango/role_permit/templates/role_permit.erb +23 -0
  87. data/lib/generators/cantango/role_permits/role_permits_generator.rb +45 -0
  88. data/lib/generators/cantango/user_permit/templates/account_permit.erb +5 -0
  89. data/lib/generators/cantango/user_permit/templates/user_permit.erb +23 -0
  90. data/lib/generators/cantango/user_permit/user_permit_generator.rb +36 -0
  91. data/lib/tasks/permits_tasks.rake +4 -0
  92. data/spec/cantango/ability/helper/permits_spec.rb +14 -0
  93. data/spec/cantango/builder/permit/account_type_spec.rb +25 -0
  94. data/spec/cantango/builder/permit/base_spec.rb +30 -0
  95. data/spec/cantango/builder/permit/special_spec.rb +25 -0
  96. data/spec/cantango/builder/permit/user_type_spec.rb +27 -0
  97. data/spec/cantango/config/engines/permit_spec.rb +14 -0
  98. data/spec/cantango/config/engines_spec.rb +142 -0
  99. data/spec/cantango/config/permit_registry_ex.rb +9 -0
  100. data/spec/cantango/config/permit_registry_spec.rb +8 -0
  101. data/spec/cantango/config/permits/accounts_spec.rb +23 -0
  102. data/spec/cantango/config/permits/disabling_spec.rb +38 -0
  103. data/spec/cantango/config/permits/enabling_spec.rb +19 -0
  104. data/spec/cantango/config/permits/execution_spec.rb +27 -0
  105. data/spec/cantango/config/permits/registration_spec.rb +15 -0
  106. data/spec/cantango/config/permits/tracking_spec.rb +19 -0
  107. data/spec/cantango/config/permits/types_spec.rb +27 -0
  108. data/spec/cantango/config/permits_spec.rb +76 -0
  109. data/spec/cantango/engine/permit_cached_spec.rb +52 -0
  110. data/spec/cantango/engine/permit_spec.rb +58 -0
  111. data/spec/cantango/engine/permit_static_dynamic_spec.rb +65 -0
  112. data/spec/cantango/executor/custom_permit_spec.rb +65 -0
  113. data/spec/cantango/executor/more_permit_spec.rb +45 -0
  114. data/spec/cantango/executor/permit_base_spec.rb +46 -0
  115. data/spec/cantango/executor/permit_spec.rb +53 -0
  116. data/spec/cantango/executor/special_permit_spec.rb +36 -0
  117. data/spec/cantango/factory/permits_spec.rb +70 -0
  118. data/spec/cantango/finder/account_permit_spec.rb +30 -0
  119. data/spec/cantango/finder/permit_spec.rb +23 -0
  120. data/spec/cantango/license/save_license_spec.rb +24 -0
  121. data/spec/cantango/license_spec.rb +0 -0
  122. data/spec/cantango/loader/categories_spec.rb +47 -0
  123. data/spec/cantango/loader/license_spec.rb +7 -0
  124. data/spec/cantango/macros/permit_spec.rb +38 -0
  125. data/spec/cantango/parser/categories_spec.rb +19 -0
  126. data/spec/cantango/permit/account_type_spec.rb +34 -0
  127. data/spec/cantango/permit/attribute_permit_spec.rb +65 -0
  128. data/spec/cantango/permit/base_spec.rb +106 -0
  129. data/spec/cantango/permit/class_methods_spec.rb +34 -0
  130. data/spec/cantango/permit/helper/execution_spec.rb +54 -0
  131. data/spec/cantango/permit/helper/host_spec.rb +29 -0
  132. data/spec/cantango/permit/helper/license_spec.rb +37 -0
  133. data/spec/cantango/permit/helper/naming_spec.rb +56 -0
  134. data/spec/cantango/permit/helper/state_spec.rb +24 -0
  135. data/spec/cantango/permit/special_default_spec.rb +2 -0
  136. data/spec/cantango/permit/special_first_spec.rb +2 -0
  137. data/spec/cantango/permit/user_type_spec.rb +78 -0
  138. data/spec/cantango/registry/permit_spec.rb +67 -0
  139. data/spec/fixtures/config/cantango_permissions.yml +49 -0
  140. data/spec/fixtures/config/categories.yml +6 -0
  141. data/spec/fixtures/config/evaluator_fixtures.yml +18 -0
  142. data/spec/fixtures/config/licenses.yml +4 -0
  143. data/spec/fixtures/config/permissions.yml +60 -0
  144. data/spec/fixtures/config/role_group.yml +4 -0
  145. data/spec/fixtures/config/roles.yml +4 -0
  146. data/spec/fixtures/config/test_permissions.yml +55 -0
  147. data/spec/fixtures/config/user_permissions.yml +8 -0
  148. data/spec/fixtures/models.rb +15 -0
  149. data/spec/fixtures/models/admin.rb +2 -0
  150. data/spec/fixtures/models/admin_account.rb +22 -0
  151. data/spec/fixtures/models/items.rb +11 -0
  152. data/spec/fixtures/models/permission.rb +12 -0
  153. data/spec/fixtures/models/simple_roles.rb +49 -0
  154. data/spec/fixtures/models/user.rb +52 -0
  155. data/spec/fixtures/models/user_account.rb +21 -0
  156. data/spec/fixtures/tango_fixtures.rb +29 -0
  157. data/spec/generators/cantango/account_role_permit_generator_spec.rb +35 -0
  158. data/spec/generators/cantango/account_role_permits_generator_spec.rb +59 -0
  159. data/spec/generators/cantango/license_generator_spec.rb +33 -0
  160. data/spec/generators/cantango/licenses_generator_spec.rb +58 -0
  161. data/spec/generators/cantango/role_permit_generator_spec.rb +35 -0
  162. data/spec/generators/cantango/role_permits_generator_spec.rb +58 -0
  163. data/spec/helpers/current_user_accounts.rb +20 -0
  164. data/spec/helpers/current_users.rb +10 -0
  165. data/spec/spec_helper.rb +24 -0
  166. metadata +325 -0
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Finder
3
+ sweet_scope :ns => {:CanTango => 'cantango/permits_ext'} do
4
+ sweetload :Base, :Permit
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ module CanTango
2
+ module Finder
3
+ class Base
4
+ include CanTango::Helpers::Debug
5
+
6
+ attr_reader :type, :name
7
+
8
+ def initialize name, options
9
+ @name = name.to_s.underscore.to_sym
10
+ @type = options[:type]
11
+ raise ArgumentError, "Missing name of permit to find" if !name
12
+ raise ArgumentError, "Missing type of permit to find" if !type
13
+ end
14
+
15
+ def permit
16
+ debug permit_msg(found_permit)
17
+ found_permit
18
+ end
19
+
20
+ protected
21
+
22
+ def permit_msg
23
+ found_permit.nil? ? "no #{type} permits found named #{name}" : "#{type} permit found named: #{name} -> #{found_permit}"
24
+ end
25
+
26
+ def permits
27
+ registered_permits.registered_for(type)
28
+ end
29
+
30
+ def registered_permits
31
+ CanTango.config.permits
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango::Finder
2
+ module Permit
3
+ sweet_scope :ns => {:CanTango => 'cantango/permits_ext'} do
4
+ sweetload :Base, :Account
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ module CanTango
2
+ module Finder
3
+ module Permit
4
+ class Account < Base
5
+ attr_reader :user_account
6
+
7
+ def initialize name, options = {}
8
+ super
9
+ @account = options[:account]
10
+ end
11
+
12
+ def find_permit
13
+ retrieve_permit
14
+ end
15
+
16
+ def permits
17
+ account_registry.registered_for(type)
18
+ end
19
+
20
+ def account_registry
21
+ CanTango.config.permits.accounts.registry_for(account)
22
+ end
23
+
24
+ protected
25
+
26
+ def found_permit
27
+ @found_permit ||= permits.registered[name]
28
+ end
29
+
30
+ def permits_to_try
31
+ [permit]
32
+ end
33
+
34
+ # this is used to namespace role permits for a specific type of user account
35
+ # this allows role permits to be defined differently for each user account (and hence sub application) if need be
36
+ # otherwise it will fall back to the generic role permit (the one which is not wrapped in a user account namespace)
37
+ def permit_class
38
+ [permit_ns , permit_class].join('::')
39
+ end
40
+
41
+ def permit_ns
42
+ "#{account}Permits"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,53 @@
1
+ module CanTango
2
+ module Finder
3
+ module Permit
4
+ class Base < CanTango::Finder::Base
5
+ include CanTango::Helpers::Debug
6
+
7
+ # This class is used to find the right permit, possible scoped for a specific user account
8
+ attr_reader :account
9
+
10
+ def initialize name, options = {}
11
+ super
12
+ @account = options[:account]
13
+ end
14
+
15
+ def find_permit
16
+ raise find_error if !retrieve_permit
17
+ retrieve_permit
18
+ end
19
+
20
+ def account_finder name
21
+ @account_finder ||= CanTango::Finder::Permit::Account.new name, :type => type, :account => account
22
+ end
23
+
24
+ protected
25
+
26
+ def permit_msg found
27
+ found.nil? ? "no permits found for #{name}" : "permits registered for name: #{name} -> #{found}"
28
+ end
29
+
30
+ def found_permit
31
+ @found_permit ||= permits.registered.send(name)
32
+ end
33
+ alias_method :registered?, :found_permit
34
+
35
+ def account_permit
36
+ account_finder(name).find_permit
37
+ end
38
+
39
+ def find_error
40
+ "The #{type} Permit for #{name} could not be loaded. You need to define a coresponding Permit class"
41
+ end
42
+
43
+ def retrieve_permit
44
+ @found_permit ||= permits_to_try.first
45
+ end
46
+
47
+ def permits_to_try
48
+ @permits_to_try ||= [account_permit, permit].compact
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Loader
3
+ sweet_scope :ns => {:CanTango => 'cantango/permits_ext'} do
4
+ sweetload :Categories, :License
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ module CanTango
2
+ module Loader
3
+ class Categories < Yaml
4
+ attr_reader :file_name, :categories
5
+
6
+ def initialize file = nil
7
+ begin
8
+ @file_name = file || categories_config_file
9
+ yml_content.each do |key, value|
10
+ parser.parse(categories, key, value)
11
+ end
12
+
13
+ rescue RuntimeError => e
14
+ raise "CanTango::Categories::Loader Error: The categories for the file #{file_name} could not be loaded - cause was #{e}"
15
+ end
16
+ end
17
+
18
+ def category name
19
+ categories.category(name).subjects
20
+ rescue
21
+ []
22
+ end
23
+
24
+ def categories
25
+ @categories ||= CanTango.config.categories
26
+ end
27
+
28
+ def parser
29
+ @parser ||= CanTango::Parser::Categories.new
30
+ end
31
+
32
+ def load_categories name = nil
33
+ name ||= categories_config_file
34
+ CanTango::Loader::Categories.new name
35
+ end
36
+
37
+ def categories_config_file
38
+ get_config_file 'categories'
39
+ end
40
+
41
+ def get_config_file name
42
+ File.join(config_path, "#{name}.yml")
43
+ end
44
+
45
+ def config_path
46
+ CanTango.config.engine(:permit).config_path
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ module CanTango
2
+ module Loader
3
+ class License
4
+ def load_rules name = nil
5
+ return if !licenses || licenses.permissions.empty?
6
+ name ||= self.class.to_s.gsub(/License$/, "").underscore
7
+
8
+ return if licenses.permissions[name].nil?
9
+
10
+ licenses.permissions[name].can_eval do |permission_statement|
11
+ instance_eval permission_statement
12
+ end
13
+ licenses.permissions[name].cannot_eval do |permission_statement|
14
+ instance_eval permission_statement
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Macros
3
+ sweet_scope :ns => {:CanTango => 'cantango/permits_ext'} do
4
+ sweetload :Permit
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module CanTango
2
+ module Permit
3
+ class MissingTypeError < StandardError; end
4
+ class MissingNameError < StandardError; end
5
+ end
6
+
7
+ module Macros
8
+ module Permit
9
+ def tango_permit options = {}
10
+ name = options[:name] || CanTango::Macros::Permit.permit_name(self)
11
+ account = options[:account] || CanTango::Macros::Permit.account_name(self)
12
+ super_class = self.superclass
13
+ class_type = unless super_class == Object
14
+ super_class.respond_to?(:type) ? super_class.type : nil
15
+ end
16
+ type = options[:type] || class_type
17
+
18
+ raise CanTango::Permit::MissingNameError, "Name of permit could not be determined, try specifying a :name option" if name.nil?
19
+ raise CanTango::Permit::MissingTypeError, "Type of permit could not be determined, try specifying a :type option" if type.nil?
20
+
21
+ reg_options = {:name => name, :type => type, :account => account}
22
+ CanTango.config.permits.register self, reg_options
23
+ reg_options
24
+ end
25
+ extend CanTango::Permit::Helper::Naming
26
+ end
27
+ end
28
+ end
29
+
30
+ class Class
31
+ include CanTango::Macros::Permit
32
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Parser
3
+ sweet_scope :ns => {:CanTango => 'cantango/permits_ext'} do
4
+ sweetload :Categories
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module CanTango
2
+ module Parser
3
+ class Categories
4
+ def parse categories, key, obj, &blk
5
+ case obj
6
+ when Array
7
+ categories[key] = obj
8
+ else
9
+ raise "Each key must have a YAML hash that defines which models make up the category (related kinds of items)"
10
+ end
11
+ yield categories if blk
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Registry
3
+ sweet_scope :ns => {:CanTango => 'cantango/permits_ext'} do
4
+ sweetload :Permit
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ module CanTango
2
+ module Registry
3
+ module Permit
4
+ def registry_for type
5
+ raise ArgumentError, "Not an available permit type, was: #{type} - available: #{available_types}" unless available_type? type
6
+ inst_var_name = "@#{type}"
7
+ instance_variable_set(inst_var_name, CanTango::Registry::Hash.new) if !instance_variable_get(inst_var_name)
8
+ instance_variable_get(inst_var_name)
9
+ end
10
+
11
+ def registered_for type, name = nil
12
+ name ? registry_for(type)[name.to_s] : registry_for(type)
13
+ end
14
+
15
+ def all
16
+ (available_types - [:special]).map{|type| registry_for(type) }
17
+ end
18
+
19
+ def show_all
20
+ (available_types - [:special]).map{|type| "#{type} -> #{show_hash_reg(registry_for(type))}" }.join("\n")
21
+ end
22
+
23
+ protected
24
+
25
+ def show_hash_reg reg
26
+ reg.registered.map {|key, value| "#{key} (#{value})" }.join(',')
27
+ end
28
+
29
+ def available_type? type
30
+ available_types.include? type
31
+ end
32
+
33
+ def available_types
34
+ CanTango.config.permits.types.available
35
+ end
36
+
37
+ class Base
38
+ include CanTango::Registry::Permit
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+
@@ -0,0 +1,37 @@
1
+ require 'generators/cantango/base'
2
+ require 'generators/cantango/license_base'
3
+ require 'generators/cantango/permit_generator'
4
+
5
+ module Cantango
6
+ module Generators
7
+ class AccountPermitGenerator < Cantango::Generators::Base
8
+ desc "Creates a Permit for an account in 'app/permits' with specific permissions and/or licenses"
9
+
10
+ argument :account, :type => :string, :desc => "Account class to create permit for"
11
+
12
+ class_option :licenses, :type => :array, :default => [], :desc => "Licenses to use in Permit"
13
+
14
+ class_option :account, :type => :string,
15
+ :desc => "Generate permits for a specific user account"
16
+
17
+ class_option :group, :type => :boolean, :default => false, :desc => "Generate permit for a role group"
18
+
19
+ source_root File.dirname(__FILE__) + '/templates'
20
+
21
+ def main_flow
22
+ template_permit account
23
+ end
24
+
25
+ protected
26
+
27
+ def is_account?
28
+ true
29
+ end
30
+
31
+ include Cantango::Generators::LicenseBase
32
+ include Cantango::Generators::PermitGenerator
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -0,0 +1,23 @@
1
+ class <%= account.to_s.camelize %>AccountPermit < CanTango::AccountPermit
2
+ def initialize ability
3
+ super
4
+ end
5
+
6
+ protected
7
+
8
+ def permit_rules
9
+ # insert your can, cannot and any other rule statements here
10
+ <%= permit_logic.strip %>
11
+ <%= license_logic %>
12
+ end
13
+
14
+ module Cached
15
+ def permit_rules
16
+ end
17
+ end
18
+
19
+ module NonCached
20
+ def permit_rules
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,71 @@
1
+ require 'generators/cantango/basic'
2
+
3
+ module Cantango
4
+ module Generators
5
+ class Base < ::Rails::Generators::Base
6
+
7
+ include Cantango::Generators::Basic
8
+
9
+ CAN_ACTIONS = [:create, :update, :manage, :read, :access]
10
+
11
+ CAN_ACTIONS.each do |action|
12
+ class_eval %{
13
+ class_option :#{action}, :type => :array, :default => [], :desc => "Models allowed to #{action}"
14
+ class_option :not_#{action}, :type => :array, :default => [], :desc => "Models not allowed to #{action}"
15
+ }
16
+ end
17
+
18
+ protected
19
+
20
+ [:user, :account].each do |name|
21
+ define_method :"#{name}?" do
22
+ false
23
+ end
24
+ end
25
+
26
+ CAN_ACTIONS.each do |action|
27
+ class_eval %{
28
+ def #{action}
29
+ options[:#{action}]
30
+ end
31
+ }
32
+ end
33
+
34
+ CAN_ACTIONS.each do |action|
35
+ class_eval %{
36
+ def not_#{action}
37
+ options[:not_#{action}]
38
+ end
39
+ }
40
+ end
41
+
42
+ def rules_logic
43
+ can_logic
44
+ cannot_logic
45
+ end
46
+
47
+ def can_logic
48
+ CAN_ACTIONS.map do |action|
49
+ send(action).map do |c|
50
+ "can(:#{action}, #{act_model(c)})"
51
+ end.join("\n ")
52
+ end.join("\n")
53
+ end
54
+
55
+ def cannot_logic
56
+ CAN_ACTIONS.map do |action|
57
+ send(action).map do |c|
58
+ "can(:#{action}, #{act_model(c)})"
59
+ end.join("\n ")
60
+ end.join("\n")
61
+ end
62
+
63
+ def act_model name
64
+ return ':all' if name == 'all'
65
+ name.camelize
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+