draper-cancan 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ vendor/ruby
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in draper-cancan.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,76 @@
1
+ = Draper-CanCan
2
+
3
+ Draper-CanCan adds a few simple methods to your decorators to make it easier to work with cancan
4
+
5
+ == Install
6
+
7
+ Add to your gemfile:
8
+ gem 'draper-cancan'
9
+
10
+ == Usage
11
+
12
+ Inside your ApplicationDecorator.rb (or a specific decorator) just add
13
+
14
+ class ApplicationDecorator < Draper::Base
15
+ include Draper::CanCan
16
+ end
17
+
18
+ And now you'll have access to a few helpful methods like
19
+
20
+ user_decorator.able_to? :read #=> calls can? :read, user_decorator.model
21
+ user_decorator.unable_to? :destroy #=> calls cannot? :destory, user_decorator.model
22
+
23
+ also you get some quick methods like
24
+ user_decorator.creatable?
25
+ user_decorator.editable?
26
+ user_decorator.updatable?
27
+ user_decorator.readable?
28
+ user_decorator.managable?
29
+ user_decorator.deletable? #or user_decorator.destroyable?
30
+
31
+
32
+ == Spacial Thanks
33
+ This would be pointless without the awesome work done by:
34
+ - Jeff Casimir on {Draper}[https://github.com/jcasimir/draper]
35
+ - Ryan Bates on {CanCan}[https://github.com/ryanb/cancan]
36
+
37
+ == Development
38
+
39
+ === Requirements
40
+
41
+ You just need bundler >= 1.0
42
+
43
+ bundle install
44
+ bundle exec ruby spec/draper/cancan_spec.rb
45
+
46
+ == About
47
+
48
+ This gem was made by Andrew Kalek from Anlek Consulting
49
+
50
+ Reach me at:
51
+ * Twitter: {@anlek}[http://www.twitter.com/anlek]
52
+ * Email: andrew.kalek@anlek[dot]com
53
+
54
+
55
+ == License
56
+
57
+ Copyright (c) 2011 Andrew Kalek, Anlek Consulting
58
+
59
+ Permission is hereby granted, free of charge, to any person obtaining
60
+ a copy of this software and associated documentation files (the
61
+ "Software"), to deal in the Software without restriction, including
62
+ without limitation the rights to use, copy, modify, merge, publish,
63
+ distribute, sublicense, and/or sell copies of the Software, and to
64
+ permit persons to whom the Software is furnished to do so, subject to
65
+ the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be
68
+ included in all copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
73
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
74
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
75
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
76
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "draper/cancan/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "draper-cancan"
7
+ s.version = Draper::CanCan::VERSION
8
+ s.authors = ["Andrew Kalek"]
9
+ s.email = ["andrew.kalek@anlek.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Adds some simple methods to your decorators to make it easier to use with rbates CanCan gem}
12
+ s.description = %q{Adds some simple methods to your decorators to make it easier to use with rbates CanCan gem}
13
+
14
+ s.rubyforge_project = "draper-cancan"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'draper'
22
+ s.add_runtime_dependency 'cancan'
23
+ s.add_development_dependency 'minitest'
24
+ s.add_development_dependency 'mocha'
25
+ s.add_development_dependency 'active_support'
26
+ s.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,3 @@
1
+ require 'draper/cancan'
2
+ require "draper/cancan/version"
3
+
@@ -0,0 +1,40 @@
1
+ module Draper
2
+ module CanCan
3
+ module InstanceMethods
4
+ def creatable?
5
+ able_to?(:create)
6
+ end
7
+
8
+ def updatable?
9
+ able_to?(:update)
10
+ end
11
+ def editable?
12
+ able_to?(:edit)
13
+ end
14
+
15
+ def managable?
16
+ able_to?(:manage)
17
+ end
18
+ def readable?
19
+ able_to?(:read)
20
+ end
21
+
22
+ def destroyable?
23
+ able_to?(:destroy)
24
+ end
25
+ alias :deletable? :destroyable?
26
+
27
+ def able_to?(action, *args)
28
+ h.can?(action, model, *args)
29
+ end
30
+ def unable_to?(action, *args)
31
+ h.cannot?(action, model, *args)
32
+ end
33
+
34
+ end
35
+
36
+ def self.included(receiver)
37
+ receiver.send :include, InstanceMethods
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module Draper
2
+ module CanCan
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+ require 'draper/cancan'
3
+
4
+ class TestModel; self; end
5
+
6
+ class TestDecorator < Draper::Base
7
+ decorates :TestModel
8
+ include Draper::CanCan
9
+ end
10
+
11
+ describe Draper::CanCan do
12
+
13
+ subject{ TestDecorator.new(source) }
14
+ let(:source){ TestModel.new }
15
+ before(:each) { subject.stubs(:h).returns({}) }
16
+
17
+ { :creatable => :create,
18
+ :editable => :edit,
19
+ :updatable => :update,
20
+ :destroyable => :destroy,
21
+ :readable => :read,
22
+ :managable => :manage}.each do |cmd, test_value|
23
+ describe "#{cmd}?" do
24
+ it "#{test_value} is doable" do
25
+ subject.h.expects(:can?).with(test_value, source).returns(true)
26
+ subject.send("#{cmd}?").must_equal(true)
27
+ end
28
+ it "#{test_value} is not doable" do
29
+ subject.h.expects(:can?).with(test_value, source).returns(false)
30
+ subject.send("#{cmd}?").must_equal(false)
31
+ end
32
+ end
33
+ end
34
+
35
+ it "is able to edit" do
36
+ subject.h.expects(:can?).with(:edit, source).returns(true)
37
+ subject.able_to?(:edit).must_equal(true)
38
+ end
39
+
40
+ it "is unable to be edited" do
41
+ subject.h.expects(:can?).with(:edit, source).returns(false)
42
+ subject.able_to?(:edit).must_equal(false)
43
+ end
44
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+
4
+ require 'draper'
5
+ require 'draper/base'
6
+ require 'active_support/inflector'
7
+
8
+ require 'mocha'
9
+
10
+ $: << File.expand_path("../../lib/draper/cancan", __FILE__)
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: draper-cancan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Kalek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: draper
16
+ requirement: &70307679426380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70307679426380
25
+ - !ruby/object:Gem::Dependency
26
+ name: cancan
27
+ requirement: &70307679425500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70307679425500
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70307679424600 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70307679424600
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &70307679423700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70307679423700
58
+ - !ruby/object:Gem::Dependency
59
+ name: active_support
60
+ requirement: &70307679422700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70307679422700
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70307679421860 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70307679421860
80
+ description: Adds some simple methods to your decorators to make it easier to use
81
+ with rbates CanCan gem
82
+ email:
83
+ - andrew.kalek@anlek.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - Gemfile
90
+ - README.rdoc
91
+ - Rakefile
92
+ - draper-cancan.gemspec
93
+ - lib/draper-cancan.rb
94
+ - lib/draper/cancan.rb
95
+ - lib/draper/cancan/version.rb
96
+ - spec/draper/cancan_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: ''
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project: draper-cancan
118
+ rubygems_version: 1.8.10
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Adds some simple methods to your decorators to make it easier to use with
122
+ rbates CanCan gem
123
+ test_files:
124
+ - spec/draper/cancan_spec.rb
125
+ - spec/spec_helper.rb