roleful 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roleful.rb +6 -11
- data/lib/roleful/core_ext/object.rb +24 -0
- data/lib/roleful/inclusion.rb +3 -3
- metadata +42 -12
- data/lib/core_ext/array.rb +0 -5
- data/lib/core_ext/object.rb +0 -21
data/lib/roleful.rb
CHANGED
@@ -1,19 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Roleful
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
end
|
3
4
|
|
4
5
|
# Core extensions
|
5
|
-
require 'object'
|
6
|
-
require 'array' unless [].respond_to?(:extract_options!)
|
6
|
+
require 'roleful/core_ext/object'
|
7
7
|
|
8
8
|
# Project files
|
9
|
-
require 'role'
|
10
|
-
require 'inclusion'
|
9
|
+
require 'roleful/role'
|
10
|
+
require 'roleful/inclusion'
|
11
11
|
|
12
12
|
# Other libraries
|
13
|
-
require 'rubygems'
|
14
13
|
require 'metaid'
|
15
14
|
require 'set'
|
16
|
-
|
17
|
-
module Roleful
|
18
|
-
VERSION = '0.0.3'
|
19
|
-
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
unless respond_to?(:instance_exec)
|
2
|
+
# http://eigenclass.org/hiki/bounded+space+instance_exec
|
3
|
+
class Object
|
4
|
+
module InstanceExecHelper; end
|
5
|
+
include InstanceExecHelper
|
6
|
+
def instance_exec(*args, &block)
|
7
|
+
begin
|
8
|
+
old_critical, Thread.critical = Thread.critical, true
|
9
|
+
n = 0
|
10
|
+
n += 1 while respond_to?(mname="__instance_exec#{n}")
|
11
|
+
InstanceExecHelper.module_eval{ define_method(mname, &block) }
|
12
|
+
ensure
|
13
|
+
Thread.critical = old_critical
|
14
|
+
end
|
15
|
+
begin
|
16
|
+
ret = send(mname, *args)
|
17
|
+
ensure
|
18
|
+
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
19
|
+
end
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/roleful/inclusion.rb
CHANGED
@@ -41,7 +41,7 @@ module Roleful
|
|
41
41
|
|
42
42
|
module ClassMethods
|
43
43
|
def role(*args, &block)
|
44
|
-
options = args.
|
44
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
45
45
|
roles = [:all].eql?(args) ? all_roles : args
|
46
46
|
roles.each { |name| define_role(name.to_sym, options, &block) }
|
47
47
|
end
|
@@ -71,8 +71,8 @@ module Roleful
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def define_role(name, options={}, &block)
|
74
|
-
self::ROLES[name] ||= Role.new(self, name, options)
|
74
|
+
self::ROLES[name] ||= Roleful::Role.new(self, name, options)
|
75
75
|
self::ROLES[name].instance_eval(&block) if block_given?
|
76
76
|
end
|
77
77
|
end
|
78
|
-
end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roleful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Pat Nakajima
|
@@ -9,19 +15,38 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-04-19 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: metaid
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
version: "1.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 7
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
version: "2"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
25
50
|
description:
|
26
51
|
email: patnakajima@gmail.com
|
27
52
|
executables: []
|
@@ -31,8 +56,7 @@ extensions: []
|
|
31
56
|
extra_rdoc_files: []
|
32
57
|
|
33
58
|
files:
|
34
|
-
- lib/core_ext/
|
35
|
-
- lib/core_ext/object.rb
|
59
|
+
- lib/roleful/core_ext/object.rb
|
36
60
|
- lib/roleful/inclusion.rb
|
37
61
|
- lib/roleful/role.rb
|
38
62
|
- lib/roleful.rb
|
@@ -46,21 +70,27 @@ rdoc_options: []
|
|
46
70
|
require_paths:
|
47
71
|
- lib
|
48
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
49
74
|
requirements:
|
50
75
|
- - ">="
|
51
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
52
80
|
version: "0"
|
53
|
-
version:
|
54
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
55
83
|
requirements:
|
56
84
|
- - ">="
|
57
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
58
89
|
version: "0"
|
59
|
-
version:
|
60
90
|
requirements: []
|
61
91
|
|
62
92
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.6.0
|
64
94
|
signing_key:
|
65
95
|
specification_version: 2
|
66
96
|
summary: Generic roles for you and your objects
|
data/lib/core_ext/array.rb
DELETED
data/lib/core_ext/object.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# http://eigenclass.org/hiki/bounded+space+instance_exec
|
2
|
-
class Object
|
3
|
-
module InstanceExecHelper; end
|
4
|
-
include InstanceExecHelper
|
5
|
-
def instance_exec(*args, &block)
|
6
|
-
begin
|
7
|
-
old_critical, Thread.critical = Thread.critical, true
|
8
|
-
n = 0
|
9
|
-
n += 1 while respond_to?(mname="__instance_exec#{n}")
|
10
|
-
InstanceExecHelper.module_eval{ define_method(mname, &block) }
|
11
|
-
ensure
|
12
|
-
Thread.critical = old_critical
|
13
|
-
end
|
14
|
-
begin
|
15
|
-
ret = send(mname, *args)
|
16
|
-
ensure
|
17
|
-
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
18
|
-
end
|
19
|
-
ret
|
20
|
-
end
|
21
|
-
end
|