cantango-api 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +36 -0
- data/Gemfile.lock +152 -0
- data/LICENSE.txt +20 -0
- data/README.mdown +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/cantango-api.gemspec +117 -0
- data/lib/cantango/api/ability/account.rb +46 -0
- data/lib/cantango/api/ability/user.rb +45 -0
- data/lib/cantango/api/ability.rb +5 -0
- data/lib/cantango/api/account.rb +20 -0
- data/lib/cantango/api/attributes.rb +15 -0
- data/lib/cantango/api/can/account.rb +32 -0
- data/lib/cantango/api/can/user.rb +26 -0
- data/lib/cantango/api/can.rb +5 -0
- data/lib/cantango/api/common.rb +14 -0
- data/lib/cantango/api/model/account.rb +39 -0
- data/lib/cantango/api/model/user.rb +39 -0
- data/lib/cantango/api/model.rb +5 -0
- data/lib/cantango/api/options.rb +19 -0
- data/lib/cantango/api/scope/account.rb +26 -0
- data/lib/cantango/api/scope/user.rb +26 -0
- data/lib/cantango/api/scope.rb +5 -0
- data/lib/cantango/api/session/account.rb +38 -0
- data/lib/cantango/api/session/user.rb +38 -0
- data/lib/cantango/api/session.rb +5 -0
- data/lib/cantango/api/user.rb +19 -0
- data/lib/cantango/api.rb +26 -0
- data/spec/cantango/api/ability/account_spec.rb +34 -0
- data/spec/cantango/api/ability/user_spec.rb +57 -0
- data/spec/cantango/api/account_spec.rb +0 -0
- data/spec/cantango/api/attributes_spec.rb +25 -0
- data/spec/cantango/api/can/account_spec.rb +85 -0
- data/spec/cantango/api/can/user_spec.rb +113 -0
- data/spec/cantango/api/options_spec.rb +0 -0
- data/spec/cantango/api/scope/account_spec.rb +0 -0
- data/spec/cantango/api/scope/user_spec.rb +73 -0
- data/spec/cantango/api/user_spec.rb +0 -0
- data/spec/cantango/api_spec.rb +11 -0
- data/spec/cantango_api_spec.rb +8 -0
- data/spec/fixtures/models/admin.rb +2 -0
- data/spec/fixtures/models/admin_account.rb +22 -0
- data/spec/fixtures/models/items.rb +8 -0
- data/spec/fixtures/models/permission.rb +12 -0
- data/spec/fixtures/models/project.rb +2 -0
- data/spec/fixtures/models/simple_roles.rb +49 -0
- data/spec/fixtures/models/user.rb +52 -0
- data/spec/fixtures/models/user_account.rb +21 -0
- data/spec/fixtures/models.rb +2 -0
- data/spec/helpers/current_user_accounts.rb +20 -0
- data/spec/helpers/current_users.rb +10 -0
- data/spec/spec_helper.rb +14 -0
- metadata +203 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
group :default do
|
4
|
+
gem 'rails', '>= 3.1'
|
5
|
+
gem 'sugar-high', '>= 0.6.0'
|
6
|
+
gem 'sweetloader', '~> 0.1.0'
|
7
|
+
gem 'hashie'
|
8
|
+
|
9
|
+
gem 'cantango-config', :git => 'git://github.com/kristianmandrup/cantango-config.git'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem "bundler", ">= 1.1.rc"
|
14
|
+
gem "jeweler", ">= 1.6.4"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
17
|
+
|
18
|
+
group :test do
|
19
|
+
gem 'require_all', '~> 1.2.0'
|
20
|
+
|
21
|
+
gem 'forgery'
|
22
|
+
gem 'sqlite3'
|
23
|
+
# Data
|
24
|
+
gem 'database_cleaner'
|
25
|
+
gem 'factory_girl'
|
26
|
+
|
27
|
+
# Specs
|
28
|
+
gem 'spork'
|
29
|
+
|
30
|
+
# Debug and performance tests
|
31
|
+
gem 'cutter'
|
32
|
+
end
|
33
|
+
|
34
|
+
group :test, :development do
|
35
|
+
gem "rspec", ">= 2.6.0"
|
36
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/kristianmandrup/cantango-config.git
|
3
|
+
revision: 852141acab7fec0eb61930bdda07c16461140a7e
|
4
|
+
specs:
|
5
|
+
cantango-config (0.1.0)
|
6
|
+
cantango-core
|
7
|
+
hashie
|
8
|
+
rails (>= 3.1)
|
9
|
+
sugar-high (>= 0.6.0)
|
10
|
+
sweetloader (~> 0.1.0)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
actionmailer (3.1.3)
|
16
|
+
actionpack (= 3.1.3)
|
17
|
+
mail (~> 2.3.0)
|
18
|
+
actionpack (3.1.3)
|
19
|
+
activemodel (= 3.1.3)
|
20
|
+
activesupport (= 3.1.3)
|
21
|
+
builder (~> 3.0.0)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
i18n (~> 0.6)
|
24
|
+
rack (~> 1.3.5)
|
25
|
+
rack-cache (~> 1.1)
|
26
|
+
rack-mount (~> 0.8.2)
|
27
|
+
rack-test (~> 0.6.1)
|
28
|
+
sprockets (~> 2.0.3)
|
29
|
+
activemodel (3.1.3)
|
30
|
+
activesupport (= 3.1.3)
|
31
|
+
builder (~> 3.0.0)
|
32
|
+
i18n (~> 0.6)
|
33
|
+
activerecord (3.1.3)
|
34
|
+
activemodel (= 3.1.3)
|
35
|
+
activesupport (= 3.1.3)
|
36
|
+
arel (~> 2.2.1)
|
37
|
+
tzinfo (~> 0.3.29)
|
38
|
+
activeresource (3.1.3)
|
39
|
+
activemodel (= 3.1.3)
|
40
|
+
activesupport (= 3.1.3)
|
41
|
+
activesupport (3.1.3)
|
42
|
+
multi_json (~> 1.0)
|
43
|
+
arel (2.2.1)
|
44
|
+
builder (3.0.0)
|
45
|
+
cancan (1.6.7)
|
46
|
+
cantango-core (0.1.0)
|
47
|
+
cancan (>= 1.4)
|
48
|
+
hashie
|
49
|
+
rails (>= 3.0.1)
|
50
|
+
sugar-high (>= 0.6.0)
|
51
|
+
sweetloader (~> 0.1.0)
|
52
|
+
colorize (0.5.8)
|
53
|
+
cutter (0.8.2)
|
54
|
+
activesupport (>= 2.3.5)
|
55
|
+
colorize (>= 0.5)
|
56
|
+
database_cleaner (0.7.0)
|
57
|
+
diff-lcs (1.1.3)
|
58
|
+
erubis (2.7.0)
|
59
|
+
factory_girl (2.3.1)
|
60
|
+
activesupport
|
61
|
+
forgery (0.5.0)
|
62
|
+
git (1.2.5)
|
63
|
+
hashie (1.2.0)
|
64
|
+
hike (1.2.1)
|
65
|
+
i18n (0.6.0)
|
66
|
+
jeweler (1.6.4)
|
67
|
+
bundler (~> 1.0)
|
68
|
+
git (>= 1.2.5)
|
69
|
+
rake
|
70
|
+
json (1.6.1)
|
71
|
+
mail (2.3.0)
|
72
|
+
i18n (>= 0.4.0)
|
73
|
+
mime-types (~> 1.16)
|
74
|
+
treetop (~> 1.4.8)
|
75
|
+
mime-types (1.17.2)
|
76
|
+
multi_json (1.0.3)
|
77
|
+
polyglot (0.3.3)
|
78
|
+
rack (1.3.5)
|
79
|
+
rack-cache (1.1)
|
80
|
+
rack (>= 0.4)
|
81
|
+
rack-mount (0.8.3)
|
82
|
+
rack (>= 1.0.0)
|
83
|
+
rack-ssl (1.3.2)
|
84
|
+
rack
|
85
|
+
rack-test (0.6.1)
|
86
|
+
rack (>= 1.0)
|
87
|
+
rails (3.1.3)
|
88
|
+
actionmailer (= 3.1.3)
|
89
|
+
actionpack (= 3.1.3)
|
90
|
+
activerecord (= 3.1.3)
|
91
|
+
activeresource (= 3.1.3)
|
92
|
+
activesupport (= 3.1.3)
|
93
|
+
bundler (~> 1.0)
|
94
|
+
railties (= 3.1.3)
|
95
|
+
railties (3.1.3)
|
96
|
+
actionpack (= 3.1.3)
|
97
|
+
activesupport (= 3.1.3)
|
98
|
+
rack-ssl (~> 1.3.2)
|
99
|
+
rake (>= 0.8.7)
|
100
|
+
rdoc (~> 3.4)
|
101
|
+
thor (~> 0.14.6)
|
102
|
+
rake (0.9.2.2)
|
103
|
+
rcov (0.9.11)
|
104
|
+
rdoc (3.11)
|
105
|
+
json (~> 1.4)
|
106
|
+
require_all (1.2.0)
|
107
|
+
rspec (2.7.0)
|
108
|
+
rspec-core (~> 2.7.0)
|
109
|
+
rspec-expectations (~> 2.7.0)
|
110
|
+
rspec-mocks (~> 2.7.0)
|
111
|
+
rspec-core (2.7.1)
|
112
|
+
rspec-expectations (2.7.0)
|
113
|
+
diff-lcs (~> 1.1.2)
|
114
|
+
rspec-mocks (2.7.0)
|
115
|
+
spork (0.8.5)
|
116
|
+
sprockets (2.0.3)
|
117
|
+
hike (~> 1.2)
|
118
|
+
rack (~> 1.0)
|
119
|
+
tilt (~> 1.1, != 1.3.0)
|
120
|
+
sqlite3 (1.3.4)
|
121
|
+
sugar-high (0.6.0)
|
122
|
+
activesupport (>= 3.0.1)
|
123
|
+
sweetloader (0.1.1)
|
124
|
+
activesupport (>= 3.0.1)
|
125
|
+
i18n
|
126
|
+
thor (0.14.6)
|
127
|
+
tilt (1.3.3)
|
128
|
+
treetop (1.4.10)
|
129
|
+
polyglot
|
130
|
+
polyglot (>= 0.3.1)
|
131
|
+
tzinfo (0.3.31)
|
132
|
+
|
133
|
+
PLATFORMS
|
134
|
+
ruby
|
135
|
+
|
136
|
+
DEPENDENCIES
|
137
|
+
bundler (>= 1.1.rc)
|
138
|
+
cantango-config!
|
139
|
+
cutter
|
140
|
+
database_cleaner
|
141
|
+
factory_girl
|
142
|
+
forgery
|
143
|
+
hashie
|
144
|
+
jeweler (>= 1.6.4)
|
145
|
+
rails (>= 3.1)
|
146
|
+
rcov
|
147
|
+
require_all (~> 1.2.0)
|
148
|
+
rspec (>= 2.6.0)
|
149
|
+
spork
|
150
|
+
sqlite3
|
151
|
+
sugar-high (>= 0.6.0)
|
152
|
+
sweetloader (~> 0.1.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Kristian Mandrup
|
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.mdown
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# CanTango Api
|
2
|
+
|
3
|
+
The main API for [CanTango](https://github.com/kristianmandrup/cantango)
|
4
|
+
|
5
|
+
## Contributing to cantango-api
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
## Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "cantango-api"
|
18
|
+
gem.homepage = "http://github.com/kristianmandrup/cantango-api"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{The main API for CanTango}
|
21
|
+
gem.description = %Q{Ability, Can, Scope, Session, User, Account and more APIs for CanTango}
|
22
|
+
gem.email = "kristian@unity3d.com"
|
23
|
+
gem.authors = ["Kristian Mandrup"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "cantango-api #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "cantango-api"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = "2011-11-25"
|
13
|
+
s.description = "Ability, Can, Scope, Session, User, Account and more APIs for CanTango"
|
14
|
+
s.email = "kristian@unity3d.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.mdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.mdown",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"cantango-api.gemspec",
|
29
|
+
"lib/cantango/api.rb",
|
30
|
+
"lib/cantango/api/ability.rb",
|
31
|
+
"lib/cantango/api/ability/account.rb",
|
32
|
+
"lib/cantango/api/ability/user.rb",
|
33
|
+
"lib/cantango/api/account.rb",
|
34
|
+
"lib/cantango/api/attributes.rb",
|
35
|
+
"lib/cantango/api/can.rb",
|
36
|
+
"lib/cantango/api/can/account.rb",
|
37
|
+
"lib/cantango/api/can/user.rb",
|
38
|
+
"lib/cantango/api/common.rb",
|
39
|
+
"lib/cantango/api/model.rb",
|
40
|
+
"lib/cantango/api/model/account.rb",
|
41
|
+
"lib/cantango/api/model/user.rb",
|
42
|
+
"lib/cantango/api/options.rb",
|
43
|
+
"lib/cantango/api/scope.rb",
|
44
|
+
"lib/cantango/api/scope/account.rb",
|
45
|
+
"lib/cantango/api/scope/user.rb",
|
46
|
+
"lib/cantango/api/session.rb",
|
47
|
+
"lib/cantango/api/session/account.rb",
|
48
|
+
"lib/cantango/api/session/user.rb",
|
49
|
+
"lib/cantango/api/user.rb",
|
50
|
+
"spec/cantango/api/ability/account_spec.rb",
|
51
|
+
"spec/cantango/api/ability/user_spec.rb",
|
52
|
+
"spec/cantango/api/account_spec.rb",
|
53
|
+
"spec/cantango/api/attributes_spec.rb",
|
54
|
+
"spec/cantango/api/can/account_spec.rb",
|
55
|
+
"spec/cantango/api/can/user_spec.rb",
|
56
|
+
"spec/cantango/api/options_spec.rb",
|
57
|
+
"spec/cantango/api/scope/account_spec.rb",
|
58
|
+
"spec/cantango/api/scope/user_spec.rb",
|
59
|
+
"spec/cantango/api/user_spec.rb",
|
60
|
+
"spec/cantango/api_spec.rb",
|
61
|
+
"spec/cantango_api_spec.rb",
|
62
|
+
"spec/fixtures/models.rb",
|
63
|
+
"spec/fixtures/models/admin.rb",
|
64
|
+
"spec/fixtures/models/admin_account.rb",
|
65
|
+
"spec/fixtures/models/items.rb",
|
66
|
+
"spec/fixtures/models/permission.rb",
|
67
|
+
"spec/fixtures/models/project.rb",
|
68
|
+
"spec/fixtures/models/simple_roles.rb",
|
69
|
+
"spec/fixtures/models/user.rb",
|
70
|
+
"spec/fixtures/models/user_account.rb",
|
71
|
+
"spec/helpers/current_user_accounts.rb",
|
72
|
+
"spec/helpers/current_users.rb",
|
73
|
+
"spec/spec_helper.rb"
|
74
|
+
]
|
75
|
+
s.homepage = "http://github.com/kristianmandrup/cantango-api"
|
76
|
+
s.licenses = ["MIT"]
|
77
|
+
s.require_paths = ["lib"]
|
78
|
+
s.rubygems_version = "1.8.10"
|
79
|
+
s.summary = "The main API for CanTango"
|
80
|
+
|
81
|
+
if s.respond_to? :specification_version then
|
82
|
+
s.specification_version = 3
|
83
|
+
|
84
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
85
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.1"])
|
86
|
+
s.add_runtime_dependency(%q<sugar-high>, [">= 0.6.0"])
|
87
|
+
s.add_runtime_dependency(%q<sweetloader>, ["~> 0.1.0"])
|
88
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
89
|
+
s.add_runtime_dependency(%q<cantango-config>, [">= 0"])
|
90
|
+
s.add_development_dependency(%q<bundler>, [">= 1.1.rc"])
|
91
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
|
92
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
93
|
+
s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
|
94
|
+
else
|
95
|
+
s.add_dependency(%q<rails>, [">= 3.1"])
|
96
|
+
s.add_dependency(%q<sugar-high>, [">= 0.6.0"])
|
97
|
+
s.add_dependency(%q<sweetloader>, ["~> 0.1.0"])
|
98
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
99
|
+
s.add_dependency(%q<cantango-config>, [">= 0"])
|
100
|
+
s.add_dependency(%q<bundler>, [">= 1.1.rc"])
|
101
|
+
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
|
102
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
103
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
104
|
+
end
|
105
|
+
else
|
106
|
+
s.add_dependency(%q<rails>, [">= 3.1"])
|
107
|
+
s.add_dependency(%q<sugar-high>, [">= 0.6.0"])
|
108
|
+
s.add_dependency(%q<sweetloader>, ["~> 0.1.0"])
|
109
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
110
|
+
s.add_dependency(%q<cantango-config>, [">= 0"])
|
111
|
+
s.add_dependency(%q<bundler>, [">= 1.1.rc"])
|
112
|
+
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
|
113
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
114
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Ability
|
3
|
+
module Account
|
4
|
+
def user_account_ability user_account, options = {}
|
5
|
+
@account_ability ||= create_ability(user_account, ability_options.merge(options))
|
6
|
+
end
|
7
|
+
alias_method :account_ability, :user_account_ability
|
8
|
+
|
9
|
+
def current_account_ability user_type = :user
|
10
|
+
user_account_ability get_ability_user_account
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
include CanTango::Api::Common
|
16
|
+
include CanTango::Api::Options
|
17
|
+
|
18
|
+
def get_ability_user_account user_type = :user
|
19
|
+
account_meth = :"current_#{user_type}_account"
|
20
|
+
return AbilityAccount.guest if !respond_to?(account_meth)
|
21
|
+
AbilityAccount.resolve_account(send account_meth)
|
22
|
+
end
|
23
|
+
|
24
|
+
module AbilityAccount
|
25
|
+
# test if current_xxx actually returns an account and not a user instance!
|
26
|
+
# if so call the #account method on the user
|
27
|
+
def self.resolve_account obj
|
28
|
+
return obj if AbilityAccount.is_account?(obj)
|
29
|
+
return resolve_account(obj.send(:account)) if obj.respond_to?(:account)
|
30
|
+
guest
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.is_account? account
|
34
|
+
::CanTango.config.user_accounts.registered_class? account.class
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.guest
|
38
|
+
account = CanTango.config.guest.account
|
39
|
+
|
40
|
+
raise "You must set the guest_account to a Proc or lambda in CanTango.config" if !account
|
41
|
+
account.respond_to?(:call) ? account.call : account
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Ability
|
3
|
+
module User
|
4
|
+
def user_ability user, options = {}
|
5
|
+
create_ability(user, ability_options.merge(options))
|
6
|
+
end
|
7
|
+
|
8
|
+
def current_user_ability user_type = :user
|
9
|
+
user_ability get_ability_user(user_type)
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
include CanTango::Api::Common
|
15
|
+
include CanTango::Api::Options
|
16
|
+
|
17
|
+
def get_ability_user user_type
|
18
|
+
user_meth = :"current_#{user_type}"
|
19
|
+
return AbilityUser.guest if !respond_to?(user_meth)
|
20
|
+
AbilityUser.resolve_user(send user_meth)
|
21
|
+
end
|
22
|
+
|
23
|
+
module AbilityUser
|
24
|
+
# test if current_xxx actually returns an account and not a user instance!
|
25
|
+
# if so call the #user method on the account
|
26
|
+
def self.resolve_user obj
|
27
|
+
return obj if is_user?(obj)
|
28
|
+
return resolve_user(obj.send(:user)) if obj.respond_to? :user
|
29
|
+
guest
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.is_user? user
|
33
|
+
::CanTango.config.users.registered_class? user.class
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.guest
|
37
|
+
user = CanTango.config.guest.user
|
38
|
+
|
39
|
+
raise "You must set the guest_user to a Proc or lambda in CanTango.config" if !user
|
40
|
+
user.respond_to?(:call) ? user.call : user
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Account
|
3
|
+
module All
|
4
|
+
def self.included base
|
5
|
+
apis.each do |api|
|
6
|
+
base.send :include, clazz(api)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.apis
|
11
|
+
[:ability, :can, :scope, :session]
|
12
|
+
end
|
13
|
+
|
14
|
+
def clazz api
|
15
|
+
"CanTango::Api::#{api.to_s.camelize}::UserAccount".constantize
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Attributes
|
3
|
+
[:read, :edit].each do |action|
|
4
|
+
define_method :"#{action}_attribute" do |name|
|
5
|
+
:"#{action}_attr_\#{name}"
|
6
|
+
end
|
7
|
+
|
8
|
+
define_method :"#{action}_attributes" do |*names|
|
9
|
+
names.select_symbols.map { |name| send("#{action}_attribute", name) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Can
|
3
|
+
module Account
|
4
|
+
include Ability
|
5
|
+
# Example: generated from types of accounts! (see below)
|
6
|
+
# def admin_account_can?(*args)
|
7
|
+
# current_account_ability(:admin).can?(*args)
|
8
|
+
# end
|
9
|
+
def self.included(base)
|
10
|
+
::CanTango.config.user_accounts.registered.each do |account|
|
11
|
+
|
12
|
+
# by default alias call to current_xxx_account to current_xxx (devise user method) unless already defined!
|
13
|
+
unless base.methods.include? :"current_#{account}_account"
|
14
|
+
define_method :"current_#{account}_account" do
|
15
|
+
send :"current_#{account}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
base.class_eval %{
|
20
|
+
def #{account}_account_can? *args
|
21
|
+
current_account_ability(:#{account}).can?(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def #{account}_account_cannot? *args
|
25
|
+
current_account_ability(:#{account}).cannot?(*args)
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Api
|
3
|
+
module Can
|
4
|
+
module User
|
5
|
+
include Ability
|
6
|
+
# Example: generated from types of accounts! (see below)
|
7
|
+
# def admin_can?(*args)
|
8
|
+
# current_user_ability(:admin).can?(*args)
|
9
|
+
# end
|
10
|
+
def self.included(base)
|
11
|
+
::CanTango.config.users.registered.each do |user|
|
12
|
+
base.class_eval %{
|
13
|
+
def #{user}_can? *args
|
14
|
+
current_user_ability(:#{user}).can?(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def #{user}_cannot? *args
|
18
|
+
current_user_ability(:#{user}).cannot?(*args)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Common
|
3
|
+
include CanTango::Api::Attributes
|
4
|
+
|
5
|
+
def create_ability candidate, opts = {}
|
6
|
+
CanTango.config.ability.factory_build candidate, opts
|
7
|
+
end
|
8
|
+
|
9
|
+
def category label
|
10
|
+
config.models.by_category label
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CanTango::Api
|
2
|
+
module Model
|
3
|
+
module Account
|
4
|
+
attr_writer :active_user, :active_account, :ability_class
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
CanTango.config.users.register base
|
8
|
+
end
|
9
|
+
|
10
|
+
def active_user
|
11
|
+
return @active_user if @active_user
|
12
|
+
return send(:user) if respond_to? :user
|
13
|
+
raise "No user could be found for account: #{self}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def active_account
|
17
|
+
@active_account || self
|
18
|
+
end
|
19
|
+
|
20
|
+
def can? *args
|
21
|
+
ability.can?(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def cannot? *args
|
25
|
+
ability.cannot?(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def ability
|
31
|
+
ability_class.new(active_account)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ability_class
|
35
|
+
CanTango::Ability::Executor::Modes
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|