permissify 0.0.13 → 0.0.14

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.
data/Gemfile CHANGED
@@ -40,13 +40,15 @@
40
40
  #
41
41
  # gem 'authlogic', '>= 3.1.0'
42
42
 
43
- source "http://rubygems.org"
43
+ source :rubygems
44
44
 
45
45
  # gem "sqlite3"
46
46
  # TODO : any activerecord version dependency?
47
47
  # gem "activerecord", '~> 3.0.9', :require => "active_record"
48
- gem "activerecord", :require => "active_record"
48
+ # gem "activerecord", :require => "active_record"
49
49
  # gem "with_model", "~> 0.2.5"
50
50
  # gem "meta_where"
51
51
 
52
52
  gemspec
53
+
54
+ gem 'rspec'
@@ -1,39 +1,42 @@
1
- # TODO : talk about how this could be an active record, but just needs to support a set of interfaces (all, all_for, others?)
1
+ # TODO : this could be an active record
2
+ # - needs to support a set of interfaces (all, all_for, others?)
2
3
  class Ability
4
+
3
5
  class << self
6
+ include Permissify::Abilities
4
7
  include SystemFixtures::Abilities
5
- @@abilities = []
6
-
7
- def all; seed if @@abilities.empty?; @@abilities; end
8
-
9
- def all_for(applicability_types)
10
- applicability_types = [applicability_types] if applicability_types.kind_of?(String)
11
- all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
12
- end
13
-
14
- def add_category(category, section, applicability=['Role'], actions=%w(View Create Update Delete), category_allows = :multiple)
15
- actions = [actions] unless actions.kind_of?(Array)
16
- actions.collect do |action|
17
- add("#{key_token(category)}_#{key_token(action)}", category, section, action, applicability, 1, actions.index(action)+1, [false], '', category_allows)
18
- end
19
- end
20
-
21
- def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
22
- @@permissions = {}
23
- all_for(applicability_types).each{|permission| @@permissions[permission[:key]] = {'0' => '1'}}
24
- view_only_categories.each{|category| view_only(category)}
25
- remove_categories.each{|category| remove(category)}
26
- @@permissions
27
- end
28
-
29
- private
30
- def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
31
- def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
32
- def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
33
- def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
34
- @@abilities << { :key => key, :category => category, :section => section, :action => action,
35
- :applicability => applicability, :number_of_values => number_of_values, :position => position,
36
- :default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows}
37
- end
8
+ # @@abilities = []
9
+ #
10
+ # def all; seed if @@abilities.empty?; @@abilities; end
11
+ #
12
+ # def all_for(applicability_types)
13
+ # applicability_types = [applicability_types] if applicability_types.kind_of?(String)
14
+ # all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
15
+ # end
16
+ #
17
+ # def add_category(category, section, applicability=['Role'], actions=%w(View Create Update Delete), category_allows = :multiple)
18
+ # actions = [actions] unless actions.kind_of?(Array)
19
+ # actions.collect do |action|
20
+ # add("#{key_token(category)}_#{key_token(action)}", category, section, action, applicability, 1, actions.index(action)+1, [false], '', category_allows)
21
+ # end
22
+ # end
23
+ #
24
+ # def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
25
+ # @@permissions = {}
26
+ # all_for(applicability_types).each{|permission| @@permissions[permission[:key]] = {'0' => '1'}}
27
+ # view_only_categories.each{|category| view_only(category)}
28
+ # remove_categories.each{|category| remove(category)}
29
+ # @@permissions
30
+ # end
31
+ #
32
+ # private
33
+ # def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
34
+ # def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
35
+ # def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
36
+ # def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
37
+ # @@abilities << { :key => key, :category => category, :section => section, :action => action,
38
+ # :applicability => applicability, :number_of_values => number_of_values, :position => position,
39
+ # :default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows}
40
+ # end
38
41
  end
39
42
  end
@@ -0,0 +1,46 @@
1
+ # TODO : this could be an active record
2
+ # - needs to support a set of interfaces (all, all_for, others?)
3
+ # - very specific hash structure
4
+ # - does this need to be a module?
5
+ module Permissify
6
+ module Ability
7
+
8
+ # class << self
9
+ # include SystemFixtures::Abilities
10
+ @@abilities = []
11
+
12
+ def clear; @@abilities = []; end
13
+ def all; seed if @@abilities.empty?; @@abilities; end
14
+
15
+ def all_for(applicability_types)
16
+ applicability_types = [applicability_types] if applicability_types.kind_of?(String)
17
+ all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
18
+ end
19
+
20
+ def add_category(category, section, applicability=['Role'], actions=%w(View Create Update Delete), category_allows = :multiple)
21
+ actions = [actions] unless actions.kind_of?(Array)
22
+ actions.collect do |action|
23
+ add("#{key_token(category)}_#{key_token(action)}", category, section, action, applicability, 1, actions.index(action)+1, [false], '', category_allows)
24
+ end
25
+ end
26
+
27
+ def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
28
+ @@permissions = {}
29
+ all_for(applicability_types).each{|permission| @@permissions[permission[:key]] = {'0' => '1'}}
30
+ view_only_categories.each{|category| view_only(category)}
31
+ remove_categories.each{|category| remove(category)}
32
+ @@permissions
33
+ end
34
+
35
+ private
36
+ def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
37
+ def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
38
+ def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
39
+ def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
40
+ @@abilities << { :key => key, :category => category, :section => section, :action => action,
41
+ :applicability => applicability, :number_of_values => number_of_values, :position => position,
42
+ :default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows}
43
+ end
44
+ # end
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ability do
4
+ describe "all" do
5
+ it "should return the correct number of abilities" do
6
+ Ability.all.size.should == 189
7
+ end
8
+ end
9
+
10
+ # describe "all_for" do
11
+ # it "should return the correct number of abilities when invoked with 'Product' applicability type" do
12
+ # Ability.all_for('Product').size.should == 50
13
+ # end
14
+ #
15
+ # it "should return the correct number of abilities when invoked with 'Role' applicability type" do
16
+ # Ability.all_for('Role').size.should == 179
17
+ # end
18
+ #
19
+ # it "should return the correct number of abilities when invoked with both 'Product' and 'Role' applicability types" do
20
+ # Ability.all_for(%w(Product Role)).size.should == 40
21
+ # end
22
+ #
23
+ # it "should do the right set logic" do
24
+ # (Ability.all_for('Product') & Ability.all_for('Role')).should == Ability.all_for(%w(Product Role))
25
+ # end
26
+ # end
27
+ #
28
+ # describe "create_permissions_hash" do
29
+ # it "should return the correct number of entries when full access to all Role permissions" do
30
+ # Ability.create_permissions_hash([], [], 'Role').keys.size.should == 179
31
+ # end
32
+ # it "should return the correct number of entries when full access to all Role permissions except view only to a single category" do
33
+ # Ability.create_permissions_hash(['loyalty_id'], [], 'Role').keys.size.should == 176
34
+ # end
35
+ # it "should return the correct number of entries when full access to all Role permissions except view only to a single category" do
36
+ # Ability.create_permissions_hash([], ['loyalty_id'], 'Role').keys.size.should == 175
37
+ # end
38
+ # it "should yield the expected difference" do
39
+ # (Ability.create_permissions_hash(['loyalty_id'], [], 'Role') - Ability.create_permissions_hash([], ['loyalty_id'], 'Role')).should == {"loyalty_id_view"=>{"0"=>"1"}}
40
+ # end
41
+ # end
42
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
@@ -0,0 +1,16 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rubygems'
8
+ require 'bundler/setup'
9
+
10
+ require 'permissify'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permissify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 13
10
- version: 0.0.13
9
+ - 14
10
+ version: 0.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Frederick Fix
@@ -101,12 +101,16 @@ files:
101
101
  - lib/generators/permissify/views/template/roles_helper.rb
102
102
  - lib/generators/permissify/views/USAGE
103
103
  - lib/generators/permissify/views/views_generator.rb
104
+ - lib/permissify/ability.rb
104
105
  - lib/permissify/aggregate.rb
105
106
  - lib/permissify/controller.rb
106
107
  - lib/permissify/model.rb
107
108
  - lib/permissify/model_class.rb
108
109
  - lib/permissify/roles.rb
109
110
  - lib/permissify.rb
111
+ - spec/permissify/ability_spec.rb
112
+ - spec/spec.opts
113
+ - spec/spec_helper.rb
110
114
  - CHANGELOG.rdoc
111
115
  - Gemfile
112
116
  - LICENSE