classy_cancan 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +30 -0
- data/MIT-LICENSE +20 -0
- data/README.md +48 -0
- data/Rakefile +21 -0
- data/classy_cancan.gemspec +22 -0
- data/lib/classy_cancan.rb +4 -0
- data/lib/classy_cancan/base_ability.rb +17 -0
- data/lib/classy_cancan/version.rb +3 -0
- data/spec/lib/classy_cancan/base_ability_spec.rb +31 -0
- data/spec/spec_helper.rb +20 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ffb4ead8e780e0e1d16f40efd92e2235b73d3695
|
4
|
+
data.tar.gz: 9efaf76e48ddb67ccd0e41f154f6de3676b99571
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e64331fe1718035e3ab506539f53a35407b9924b0186336637bf5d04b8a7f89072254e0351df94c726863a5a3fa36c70ce2d856b06ac6d423d42513fa4074ab
|
7
|
+
data.tar.gz: 8599858c0c66ff8bf3d4124a4bd6a51662756834d1e55a119cbc8922781238ccb5ec70b7a0d96e22ebd40a7aec0758114aa3296ee5346e2eaeee194e70afd885
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
classy_cancan
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in classy_cancan.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
classy_cancan (0.0.1)
|
5
|
+
cancancan
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
cancancan (1.9.2)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
rspec (3.1.0)
|
13
|
+
rspec-core (~> 3.1.0)
|
14
|
+
rspec-expectations (~> 3.1.0)
|
15
|
+
rspec-mocks (~> 3.1.0)
|
16
|
+
rspec-core (3.1.5)
|
17
|
+
rspec-support (~> 3.1.0)
|
18
|
+
rspec-expectations (3.1.2)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.1.0)
|
21
|
+
rspec-mocks (3.1.2)
|
22
|
+
rspec-support (~> 3.1.0)
|
23
|
+
rspec-support (3.1.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
classy_cancan!
|
30
|
+
rspec
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# ClassyCancan
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/neckhair/classy_cancan.svg)](https://travis-ci.org/neckhair/classy_cancan)
|
4
|
+
|
5
|
+
When using Cancan/can, a `Ability` class in a larger Ruby on Rails application can grow quite quickly.
|
6
|
+
This gem lets you seperate model specific ability definitions into their own class.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add the following line to your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'classy_cancan'
|
14
|
+
```
|
15
|
+
|
16
|
+
Now run `bundle install`.
|
17
|
+
|
18
|
+
**Note**: This gem is useless without `cancan` or `cancancan`.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
And this is how you use it:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# app/models/ability.rb
|
26
|
+
class Ability
|
27
|
+
include CanCan::Ability
|
28
|
+
|
29
|
+
def initialize(user)
|
30
|
+
ContactAbility.new(self, user).setup
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# app/models/abilities/contact_ability.rb
|
35
|
+
class ContactAbility < ClassyCancan::BaseAbility
|
36
|
+
def setup
|
37
|
+
can :manage, Contact
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
## Todo
|
43
|
+
|
44
|
+
- [ ] Rails generator to create ability classes
|
45
|
+
|
46
|
+
## Licence
|
47
|
+
|
48
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ClassyCancan'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require 'classy_cancan/version'
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'classy_cancan'
|
9
|
+
s.version = ClassyCancan::VERSION
|
10
|
+
s.authors = ['Philippe Hässig']
|
11
|
+
s.email = ['phil@neckhair.ch']
|
12
|
+
s.homepage = 'http://github.com/neckhair/classy_cancan'
|
13
|
+
s.summary = 'Classify your cancancan abilities'
|
14
|
+
s.description = 'Define an ability class for each of your models to separate authorizations.'
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
|
19
|
+
s.add_dependency 'cancancan'
|
20
|
+
|
21
|
+
s.add_development_dependency 'rspec'
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ClassyCancan
|
2
|
+
class BaseAbility
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
attr_reader :ability, :user
|
6
|
+
|
7
|
+
def_delegators :@ability, :can, :cannot
|
8
|
+
|
9
|
+
def initialize(ability, user)
|
10
|
+
@ability = ability
|
11
|
+
@user = user
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ClassyCancan::BaseAbility do
|
4
|
+
class Contact
|
5
|
+
end
|
6
|
+
|
7
|
+
class ContactAbility < ClassyCancan::BaseAbility
|
8
|
+
def setup
|
9
|
+
can :manage, Contact
|
10
|
+
cannot :destroy, Contact
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Ability
|
15
|
+
include CanCan::Ability
|
16
|
+
|
17
|
+
def initialize(user)
|
18
|
+
ContactAbility.new(self, user).setup
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
subject(:ability) { Ability.new(double(:user)) }
|
23
|
+
|
24
|
+
it 'can manage a contact' do
|
25
|
+
expect(ability).to be_able_to :manage, Contact.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'cannot destroy the contact' do
|
29
|
+
expect(ability).to_not be_able_to :destroy, Contact.new
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'classy_cancan'
|
2
|
+
require 'cancancan'
|
3
|
+
require 'cancan/matchers'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.filter_run :focus
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.warnings = true
|
17
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
18
|
+
config.order = :random
|
19
|
+
Kernel.srand config.seed
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classy_cancan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Philippe Hässig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cancancan
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Define an ability class for each of your models to separate authorizations.
|
42
|
+
email:
|
43
|
+
- phil@neckhair.ch
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".ruby-gemset"
|
51
|
+
- ".ruby-version"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- classy_cancan.gemspec
|
58
|
+
- lib/classy_cancan.rb
|
59
|
+
- lib/classy_cancan/base_ability.rb
|
60
|
+
- lib/classy_cancan/version.rb
|
61
|
+
- spec/lib/classy_cancan/base_ability_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
homepage: http://github.com/neckhair/classy_cancan
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Classify your cancancan abilities
|
87
|
+
test_files: []
|