dar_da_da 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGES.md +8 -2
- data/dar_da_da.gemspec +3 -5
- data/lib/dar_da_da/active_record_extension.rb +16 -14
- data/lib/dar_da_da/version.rb +1 -1
- data/spec/dar_da_da/active_record_extension_spec.rb +9 -9
- metadata +20 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3508fbde233fce90f037ff62c15721426891bef
|
4
|
+
data.tar.gz: a6b5e04b1a88b2ad6d1752c0f21da50b327e6a42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aec035d497a9378ec819d01305ec3cbf0f03dea9db724500d5659c18993325ae6c11ef65158235660f13ff263e9ee89f3964d7e5ecbf14f955c93a26deeceff
|
7
|
+
data.tar.gz: 595661f990878b8847aa363c16955e1f50cdc25b01737555151e4fef142975528ad3481eb34fb39dfe0132f994c5851c7b51e65099b6ae075ed91634bd5d553c
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](http://github.com/yolk/valvat/compare/v0.0.
|
3
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.0.5...master)
|
4
|
+
|
5
|
+
### 0.0.5 / 2014-04-09
|
6
|
+
|
7
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.0.5...v0.0.3)
|
8
|
+
|
9
|
+
* Compatiblity with Rails 4.0
|
4
10
|
|
5
11
|
### 0.0.3 / 2012-02-06
|
6
12
|
|
7
|
-
[full changelog](http://github.com/yolk/valvat/compare/v0.0
|
13
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.0.2...v0.0.3)
|
8
14
|
|
9
15
|
* Compatiblity with Rails 3.2
|
data/dar_da_da.gemspec
CHANGED
@@ -22,10 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency 'activerecord', '>= 3.0'
|
23
23
|
|
24
24
|
# Actionpack is optional!
|
25
|
-
s.add_development_dependency 'actionpack', '
|
26
|
-
s.add_development_dependency 'rspec'
|
27
|
-
s.add_development_dependency 'guard-rspec'
|
28
|
-
s.add_development_dependency 'growl', '>=1.0.3'
|
29
|
-
s.add_development_dependency 'rb-fsevent', '>=0.3.9'
|
25
|
+
s.add_development_dependency 'actionpack', '>= 3.0'
|
26
|
+
s.add_development_dependency 'rspec'
|
27
|
+
s.add_development_dependency 'guard-rspec'
|
30
28
|
s.add_development_dependency 'sqlite3-ruby'
|
31
29
|
end
|
@@ -6,17 +6,19 @@ module DarDaDa
|
|
6
6
|
base.class_attribute(:dar_dar_da, :instance_reader => false, :instance_writer => false)
|
7
7
|
base.extend(ClassMethods)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def self.decorate(base, config)
|
11
11
|
base.send :include, DarDaDa::ActiveRecordExtension::InstanceMethods
|
12
|
-
|
12
|
+
|
13
13
|
config.each do |name, role|
|
14
14
|
base.class_eval("
|
15
15
|
def #{name}?
|
16
16
|
role_symbol == :#{name}
|
17
17
|
end
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
def self.#{name.to_s.pluralize}
|
20
|
+
where(\"#{base.table_name}.#{config.options[:role_attribute]} = '#{name}'\")
|
21
|
+
end
|
20
22
|
")
|
21
23
|
end
|
22
24
|
config.all_rights.each do |right|
|
@@ -27,7 +29,7 @@ module DarDaDa
|
|
27
29
|
")
|
28
30
|
end
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
module ClassMethods
|
32
34
|
def define_roles(options={}, &block)
|
33
35
|
(self.dar_dar_da ||= DarDaDa::Config.new(options)).tap do |config|
|
@@ -36,41 +38,41 @@ module DarDaDa
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
module InstanceMethods
|
41
43
|
def self.included(base)
|
42
44
|
base.send :before_save, :set_role_to_default_value
|
43
45
|
end
|
44
|
-
|
46
|
+
|
45
47
|
def role
|
46
48
|
role_symbol.to_s
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
def role=(new_role)
|
50
52
|
write_role_attribute(new_role) if self.class.dar_dar_da[new_role]
|
51
53
|
end
|
52
|
-
|
54
|
+
|
53
55
|
def allowed_to?(name)
|
54
56
|
rights = self.class.dar_dar_da[role]
|
55
57
|
!!rights && !name.blank? && rights.include?(name.to_sym)
|
56
58
|
end
|
57
|
-
|
59
|
+
|
58
60
|
private
|
59
|
-
|
61
|
+
|
60
62
|
def role_symbol
|
61
63
|
role_attribute = read_role_attribute
|
62
64
|
return self.class.dar_dar_da.options[:default_role] if role_attribute.blank?
|
63
65
|
role_attribute.to_sym
|
64
66
|
end
|
65
|
-
|
67
|
+
|
66
68
|
def read_role_attribute
|
67
69
|
read_attribute(self.class.dar_dar_da.options[:role_attribute])
|
68
70
|
end
|
69
|
-
|
71
|
+
|
70
72
|
def write_role_attribute(new_role)
|
71
73
|
write_attribute(self.class.dar_dar_da.options[:role_attribute], new_role.to_s)
|
72
74
|
end
|
73
|
-
|
75
|
+
|
74
76
|
def set_role_to_default_value
|
75
77
|
unless self.class.dar_dar_da[read_role_attribute]
|
76
78
|
write_role_attribute(self.class.dar_dar_da.options[:default_role])
|
data/lib/dar_da_da/version.rb
CHANGED
@@ -2,12 +2,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
4
4
|
before { @user = User.create! }
|
5
|
-
|
5
|
+
|
6
6
|
it "should set role to default_role" do
|
7
7
|
@user.role.should eql("user")
|
8
8
|
User.new.role.should eql("user")
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should add role accessor to map role_attribute" do
|
12
12
|
@user.role = :author
|
13
13
|
@user.role.should eql("author")
|
@@ -18,11 +18,11 @@ describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
|
18
18
|
@user.update_attributes!(:role => 'user')
|
19
19
|
@user.role.should eql("user")
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "should set default_role to user" do
|
23
23
|
User.dar_dar_da.options[:default_role].should == (:"user")
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should prevent saving role_attribute with nil or empty" do
|
27
27
|
@user.role_name = ""
|
28
28
|
@user.send(:read_role_attribute).should be_blank
|
@@ -32,7 +32,7 @@ describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
|
32
32
|
@user.role_name.should eql("user")
|
33
33
|
@user.role.should eql("user")
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should prevent saving role_attribute with not exisiting role" do
|
37
37
|
@user.role_name = "unknown"
|
38
38
|
@user.send(:read_role_attribute).should eql("unknown")
|
@@ -42,7 +42,7 @@ describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
|
42
42
|
@user.role_name.should eql("user")
|
43
43
|
@user.role.should eql("user")
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should add {role}? methods" do
|
47
47
|
@user.should be_user
|
48
48
|
@user.role = :author
|
@@ -50,7 +50,7 @@ describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
|
50
50
|
@user.role = :admin
|
51
51
|
@user.should be_admin
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "should add allowed_to? method" do
|
55
55
|
@user.allowed_to?(:read_acticles).should be_true
|
56
56
|
@user.allowed_to?("read_acticles").should be_true
|
@@ -60,7 +60,7 @@ describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
|
60
60
|
@user.allowed_to?("").should be_false
|
61
61
|
@user.allowed_to?(nil).should be_false
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it "should add allowed_to_{right}? methods" do
|
65
65
|
@user.should be_allowed_to_read_acticles
|
66
66
|
@user.should_not be_allowed_to_write_acticles
|
@@ -74,7 +74,7 @@ describe DarDaDa::ActiveRecordExtension, "extended Model" do
|
|
74
74
|
@user.should be_allowed_to_write_acticles
|
75
75
|
@user.should be_allowed_to_cancel_account
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
it "should add named_scope for every role" do
|
79
79
|
User.destroy_all
|
80
80
|
User.create!(:role => "admin")
|
metadata
CHANGED
@@ -1,111 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dar_da_da
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.9
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.9
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: growl
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.0.3
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rb-fsevent
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.3.9
|
61
|
+
version: '0'
|
90
62
|
type: :development
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
|
-
- -
|
66
|
+
- - ">="
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0
|
68
|
+
version: '0'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
70
|
name: sqlite3-ruby
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
|
-
- -
|
73
|
+
- - ">="
|
102
74
|
- !ruby/object:Gem::Version
|
103
75
|
version: '0'
|
104
76
|
type: :development
|
105
77
|
prerelease: false
|
106
78
|
version_requirements: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
108
|
-
- -
|
80
|
+
- - ">="
|
109
81
|
- !ruby/object:Gem::Version
|
110
82
|
version: '0'
|
111
83
|
description: Roles easy like sunday morning.
|
@@ -115,7 +87,7 @@ executables: []
|
|
115
87
|
extensions: []
|
116
88
|
extra_rdoc_files: []
|
117
89
|
files:
|
118
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
119
91
|
- CHANGES.md
|
120
92
|
- Gemfile
|
121
93
|
- Guardfile
|
@@ -144,17 +116,17 @@ require_paths:
|
|
144
116
|
- lib
|
145
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
118
|
requirements:
|
147
|
-
- -
|
119
|
+
- - ">="
|
148
120
|
- !ruby/object:Gem::Version
|
149
121
|
version: '0'
|
150
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
123
|
requirements:
|
152
|
-
- -
|
124
|
+
- - ">="
|
153
125
|
- !ruby/object:Gem::Version
|
154
126
|
version: '0'
|
155
127
|
requirements: []
|
156
128
|
rubyforge_project: dar_da_da
|
157
|
-
rubygems_version: 2.0
|
129
|
+
rubygems_version: 2.2.0
|
158
130
|
signing_key:
|
159
131
|
specification_version: 4
|
160
132
|
summary: Roles easy like sunday morning.
|