CanCanCanSee 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b8f8d1d948b2f9e478567e0dd3d5232b780bad1
4
- data.tar.gz: facb4a6ec257267d28861a77215b8a9309510e06
3
+ metadata.gz: ff25ff4f47b4bb97aecfdad5e7630b42a6e5c14e
4
+ data.tar.gz: 6a48bcad44cdc045c96836aa7dad388f84b77c1a
5
5
  SHA512:
6
- metadata.gz: 72e91981291c0983e05c0583d758646490401194a4e6bebbafedac0dd3b159ea282636828f4917213a08250a08052d7fb74dc4c1b93ef461fa88251fdab6fc5e
7
- data.tar.gz: 95d69df88461a1aadf7a68c37331a6c7534d200e8a574bc53b12792530ff19a1bf89d2b96de5fa335cb0685ca4cb15ab392d64297a7c0bf6236fa06829006dc7
6
+ metadata.gz: 0465dfd4c70ebbaeb003a805d2b12cff35990121e23f1a48cce8755ab9b32fe35b295be21debb204b4f1ab179eab9d927302dd41ef9285e6e63760d72aaefb24
7
+ data.tar.gz: f6cc19753227e2357ec73ae449d784cc7a263872bf51499da5e1fc8438e353db2b8e01f1dfcdd80aee4b3e737513fa592608e1c097e3449bbea1ee83f7a4a82f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CanCanCanSee
2
2
 
3
- #THIS GEM IS IN DEVELOPMENT AND NOT RUNNING YET
3
+ Read-only access to roles and abilities with CanCancan. Note: Since this relies on regex-magic at the moment, it requires a particular formatting that will be further articulated upon in future docs.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,13 +20,40 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- N/A
23
+ Your `Ability.rb` file should use a `case/when` statement for different roles and abilities for this to work.
24
+
25
+ Create a `config/initializers/cancancansee.rb` file, and if you have a normal Ability.rb file include:
26
+
27
+ `abilities_type = single`
28
+
29
+ And if you have a custom multiple Ability.rb setup include:
30
+
31
+ `abilities_type = multiple`
32
+
33
+ Then, anywhere in your code or CLI, you have access to this command:
34
+
35
+ ```ruby
36
+ CanCanCanSee.all_abilities
37
+
38
+ #=> {"RoleOne"=>{"can"=>["manage Object"], "cannot"=>["delete Note", "edit Thing"},
39
+ #=> "RoleTwo"=>{"can"=>["edit User"], "cannot"=>["manage Telephone"]}}
40
+
41
+ #and if you only want to see abilities for a particular slug under multiple....
42
+ CanCanCanSee.all_abilities[my_slug]
43
+
44
+ #=> {"my_slug"=>{"RoleOne"=>{"can"=>["manage Object"], "cannot"=>["delete Note", "edit Thing"},
45
+ #=> "RoleTwo"=>{"can"=>["edit User"], "cannot"=>["manage Telephone"]}},
46
+ #=> "my_other_slug"=>{"RoleOne"=>{"can"=>["manage Object"], "cannot"=>["delete Note", "edit Thing"},
47
+ #=> "RoleTwo"=>{"can"=>["edit User"], "cannot"=>["manage Telephone"]}}
48
+ ```
24
49
 
25
50
  ## Development
26
51
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+ ## TODO Before 1.0
28
53
 
29
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+ * Confirm support for single and multiple Ability.rb files
55
+ * Create docs to show style guidelines to have gem work
56
+ * Create post to show layout for slug-based auth
30
57
 
31
58
  ## Contributing
32
59
 
data/lib/CanCanCanSee.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "CanCanCanSee/version"
2
+ require 'pry'
2
3
 
3
4
  module CanCanCanSee
4
5
 
@@ -6,22 +7,15 @@ module CanCanCanSee
6
7
 
7
8
  def self.initiate_gem
8
9
 
9
- user_answer = "none"
10
-
11
- while user_answer.downcase != "single" && user_answer.downcase != "multiple"
12
- # puts "Single or multiple ability file?"
13
- user_answer = "multiple"
14
- end
15
-
16
- type = user_answer
10
+ configuration_file = File.read('config/initializers/cancancansee.rb')
17
11
 
18
12
 
19
- if type == "single"
13
+ if configuration_file.include?("abilities_type = single")
20
14
 
21
15
  my_file = File.read('app/models/ability.rb') # for single
22
16
  read_file(my_file)
23
17
 
24
- elsif type == "multiple"
18
+ elsif configuration_file.include?("abilities_type = multiple")
25
19
 
26
20
  my_arr = []
27
21
 
@@ -63,7 +57,7 @@ module CanCanCanSee
63
57
  counter = 0
64
58
  roles = @current_file.scan(/when(.*)($|[ do])/)
65
59
  roles.map! { |item| item.to_s.gsub(/[^0-9a-z ]/i, '') }
66
- roles.map! { |item| item[1..-1]}
60
+ roles.map! { |item| item[1..-2]}
67
61
 
68
62
  role_count = roles.length
69
63
  chunk_start = /when/ =~ @current_file
@@ -94,7 +88,7 @@ module CanCanCanSee
94
88
  array_of_can = []
95
89
 
96
90
  #establish can
97
- can_abilities = all_text[roles[new_counter]].scan(/can (.*)($|[ do])/)
91
+ can_abilities = all_text[roles[new_counter]].scan(/can (.*)\n/)
98
92
 
99
93
  can_abilities.each do |can_ability|
100
94
  can_ability = can_ability[0]
@@ -105,7 +99,7 @@ module CanCanCanSee
105
99
  array_of_cannot = []
106
100
 
107
101
  #establish cannot
108
- cannot_abilities = all_text[roles[new_counter]].scan(/cannot(.*)($|[ do])/)
102
+ cannot_abilities = all_text[roles[new_counter]].scan(/cannot(.*)\n/)
109
103
 
110
104
  cannot_abilities.each do |cannot_ability|
111
105
  cannot_ability = cannot_ability[0]
@@ -133,6 +127,9 @@ module CanCanCanSee
133
127
 
134
128
  can_abilities.each do |can_ability|
135
129
  can_ability = can_ability[0]
130
+ if can_ability.include?("do")
131
+ can_ability = "#{/(.*) do/.match(can_ability)[1]} WITH BLOCK"
132
+ end
136
133
  array_of_can << can_ability.gsub(/[^0-9a-z ]/i, '')
137
134
  end
138
135
 
@@ -144,6 +141,9 @@ module CanCanCanSee
144
141
 
145
142
  cannot_abilities.each do |cannot_ability|
146
143
  cannot_ability = cannot_ability[0]
144
+ if cannot_ability.include?("do")
145
+ cannot_ability = "#{/(.*) do/.match(cannot_ability)[1]} WITH BLOCK"
146
+ end
147
147
  array_of_cannot << cannot_ability.gsub(/[^0-9a-z ]/i, '')
148
148
  end
149
149
 
@@ -158,9 +158,9 @@ module CanCanCanSee
158
158
 
159
159
  #public methods
160
160
 
161
- def self.all_roles
161
+ def self.all_roles(desired_slug=nil)
162
162
  initiate_gem
163
- return MY_GLOBAL_HOLDER_OF_ABILITY.keys
163
+ return MY_GLOBAL_HOLDER_OF_ABILITY[desired_slug].keys
164
164
 
165
165
  end
166
166
 
@@ -1,3 +1,3 @@
1
1
  module CanCanCanSee
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CanCanCanSee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Schwaderer