cantango-config 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/VERSION +1 -1
- data/cantango-config.gemspec +5 -5
- data/lib/cantango/configuration/ability.rb +14 -1
- data/lib/cantango/configuration/accounts.rb +4 -3
- data/lib/cantango/configuration/factory.rb +12 -6
- data/lib/cantango/configuration/users.rb +3 -2
- data/spec/cantango/configuration/ability_spec.rb +31 -0
- data/spec/cantango/configuration/accounts_spec.rb +4 -0
- data/spec/cantango/configuration/factory_spec.rb +48 -2
- data/spec/cantango/configuration/shared/factory_ex.rb +1 -1
- metadata +22 -22
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
arel (2.2.1)
|
33
33
|
builder (3.0.0)
|
34
34
|
cancan (1.6.7)
|
35
|
-
cantango-core (0.1.
|
35
|
+
cantango-core (0.1.9)
|
36
36
|
cancan (>= 1.4)
|
37
37
|
hashie
|
38
38
|
rails (>= 3.0.1)
|
@@ -121,7 +121,7 @@ GEM
|
|
121
121
|
rack (~> 1.0)
|
122
122
|
tilt (~> 1.1, != 1.3.0)
|
123
123
|
sqlite3 (1.3.5)
|
124
|
-
sugar-high (0.6.1)
|
124
|
+
sugar-high (0.6.2.1)
|
125
125
|
activesupport (>= 3.0.1)
|
126
126
|
sweetloader (0.1.6)
|
127
127
|
activesupport (>= 3.0.1)
|
@@ -139,7 +139,7 @@ PLATFORMS
|
|
139
139
|
|
140
140
|
DEPENDENCIES
|
141
141
|
bundler (>= 1.1.rc)
|
142
|
-
cantango-core (~> 0.1.
|
142
|
+
cantango-core (~> 0.1.9)
|
143
143
|
cutter
|
144
144
|
database_cleaner
|
145
145
|
dkastner-moneta (>= 1.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/cantango-config.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cantango-config}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Kristian Mandrup}]
|
12
|
-
s.date = %q{2011-12-
|
12
|
+
s.date = %q{2011-12-08}
|
13
13
|
s.description = %q{Configuration DSL for configuring CanTango}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -122,7 +122,7 @@ Gem::Specification.new do |s|
|
|
122
122
|
s.add_runtime_dependency(%q<sugar-high>, [">= 0.6.1"])
|
123
123
|
s.add_runtime_dependency(%q<sweetloader>, ["~> 0.1.6"])
|
124
124
|
s.add_runtime_dependency(%q<hashie>, ["~> 0.4.0"])
|
125
|
-
s.add_runtime_dependency(%q<cantango-core>, ["~> 0.1.
|
125
|
+
s.add_runtime_dependency(%q<cantango-core>, ["~> 0.1.9"])
|
126
126
|
s.add_development_dependency(%q<bundler>, [">= 1.1.rc"])
|
127
127
|
s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
|
128
128
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
@@ -132,7 +132,7 @@ Gem::Specification.new do |s|
|
|
132
132
|
s.add_dependency(%q<sugar-high>, [">= 0.6.1"])
|
133
133
|
s.add_dependency(%q<sweetloader>, ["~> 0.1.6"])
|
134
134
|
s.add_dependency(%q<hashie>, ["~> 0.4.0"])
|
135
|
-
s.add_dependency(%q<cantango-core>, ["~> 0.1.
|
135
|
+
s.add_dependency(%q<cantango-core>, ["~> 0.1.9"])
|
136
136
|
s.add_dependency(%q<bundler>, [">= 1.1.rc"])
|
137
137
|
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
|
138
138
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -143,7 +143,7 @@ Gem::Specification.new do |s|
|
|
143
143
|
s.add_dependency(%q<sugar-high>, [">= 0.6.1"])
|
144
144
|
s.add_dependency(%q<sweetloader>, ["~> 0.1.6"])
|
145
145
|
s.add_dependency(%q<hashie>, ["~> 0.4.0"])
|
146
|
-
s.add_dependency(%q<cantango-core>, ["~> 0.1.
|
146
|
+
s.add_dependency(%q<cantango-core>, ["~> 0.1.9"])
|
147
147
|
s.add_dependency(%q<bundler>, [">= 1.1.rc"])
|
148
148
|
s.add_dependency(%q<jeweler>, [">= 1.6.4"])
|
149
149
|
s.add_dependency(%q<rcov>, [">= 0"])
|
@@ -7,8 +7,21 @@ module CanTango
|
|
7
7
|
include CanTango::Configuration::Factory
|
8
8
|
include CanTango::Configuration::ExecutionModes
|
9
9
|
|
10
|
+
def default_executor_class
|
11
|
+
@default_executor_class ||= CanTango::Ability::Executor::Modal
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_executor_class= clazz
|
15
|
+
raise ArgumentError, "default must be a Class" if !is_class? clazz
|
16
|
+
@default_executor_class = clazz
|
17
|
+
end
|
18
|
+
|
10
19
|
def default_class
|
11
|
-
@default_class ||= CanTango::Ability::
|
20
|
+
@default_class ||= CanTango::Ability::Base
|
21
|
+
end
|
22
|
+
|
23
|
+
def factor_class_method
|
24
|
+
:default_executor_class
|
12
25
|
end
|
13
26
|
end
|
14
27
|
end
|
@@ -5,14 +5,15 @@ module CanTango
|
|
5
5
|
|
6
6
|
def register_account clazz
|
7
7
|
register account_name(clazz), clazz
|
8
|
+
self
|
8
9
|
end
|
10
|
+
alias_method :register_class, :register_account
|
9
11
|
|
10
12
|
protected
|
11
13
|
|
12
14
|
def account_name clazz
|
13
|
-
clazz.name.demodulize.gsub(/(.+)Account$/, '\1')
|
14
|
-
end
|
15
|
-
|
15
|
+
clazz.name.demodulize.gsub(/(.+)Account$/, '\1').to_s.underscore
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
module CanTango
|
2
2
|
class Configuration
|
3
3
|
module Factory
|
4
|
-
def
|
4
|
+
def clear_factory!
|
5
5
|
@factory = nil
|
6
6
|
end
|
7
7
|
|
8
|
-
def factory
|
9
|
-
raise ArgumentError, "Factory must be a callable (lambda or Proc), was: #{proc}"
|
10
|
-
@factory =
|
8
|
+
def factory proc = nil
|
9
|
+
raise ArgumentError, "Factory must be a callable (lambda or Proc), was: #{proc}" unless callable? proc
|
10
|
+
@factory = proc
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_factory
|
14
|
+
@factory
|
11
15
|
end
|
12
16
|
|
13
17
|
alias_method :factory=, :factory
|
@@ -22,8 +26,10 @@ module CanTango
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def default_factory obj = nil, opts = {}
|
25
|
-
|
26
|
-
default_class
|
29
|
+
clazz_meth = send(:factory_class_method) if respond_to? :factory_class_method
|
30
|
+
clazz_meth = :default_class unless clazz_meth && respond_to?(clazz_meth)
|
31
|
+
raise "Default factory must be defined via call to ##{clazz_meth}" unless send(clazz_meth)
|
32
|
+
send(clazz_meth).new obj, options.merge(opts)
|
27
33
|
end
|
28
34
|
|
29
35
|
attr_reader :default_class
|
@@ -6,11 +6,12 @@ module CanTango
|
|
6
6
|
def register_user clazz
|
7
7
|
register user_name(clazz), clazz
|
8
8
|
end
|
9
|
-
|
9
|
+
alias_method :register_class, :register_user
|
10
|
+
|
10
11
|
protected
|
11
12
|
|
12
13
|
def user_name clazz
|
13
|
-
clazz.name.demodulize.gsub(/(.+)User$/, '\1')
|
14
|
+
clazz.name.demodulize.gsub(/(.+)User$/, '\1').to_s.underscore
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -2,12 +2,43 @@ require 'spec_helper'
|
|
2
2
|
require 'cantango/configuration/shared/factory_ex'
|
3
3
|
require 'cantango/configuration/shared/execution_modes_ex'
|
4
4
|
|
5
|
+
class MyExecutor
|
6
|
+
end
|
7
|
+
|
5
8
|
describe CanTango::Configuration::Ability do
|
6
9
|
subject { CanTango.config.ability }
|
7
10
|
|
8
11
|
it_should_behave_like 'Factory'
|
9
12
|
|
10
13
|
it_should_behave_like 'Execution Modes'
|
14
|
+
|
15
|
+
describe 'default_executor_class' do
|
16
|
+
specify { subject.default_executor_class.should == CanTango::Ability::Executor::Modal }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'default_executor_class' do
|
20
|
+
specify { subject.default_executor_class.should == CanTango::Ability::Executor::Modal }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'default_executor_class=' do
|
24
|
+
specify do
|
25
|
+
lambda { subject.default_executor_class = 's' }.should raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
specify do
|
29
|
+
subject.default_executor_class = MyExecutor
|
30
|
+
subject.default_executor_class.should == MyExecutor
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'default_class' do
|
35
|
+
specify { subject.default_class.should == CanTango::Ability::Base }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'factor_class_method' do
|
39
|
+
specify { subject.factor_class_method.should == :default_executor_class }
|
40
|
+
end
|
41
|
+
|
11
42
|
end
|
12
43
|
|
13
44
|
|
@@ -1,17 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'cantango/configuration/shared/factory_ex'
|
3
3
|
|
4
|
+
AliasedCustomFactory = CustomFactory
|
5
|
+
|
4
6
|
class MyFactory
|
5
7
|
include CanTango::Configuration::Factory
|
6
8
|
include Singleton
|
9
|
+
|
10
|
+
def default_class
|
11
|
+
AliasedCustomFactory
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_executor_class
|
15
|
+
CustomFactory
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_writer :factory_class_method
|
19
|
+
|
20
|
+
def factory_class_method
|
21
|
+
@factory_class_method ||= :default_executor_class
|
22
|
+
end
|
7
23
|
end
|
8
24
|
|
9
25
|
describe CanTango::Configuration::Factory do
|
10
26
|
subject { MyFactory.instance }
|
11
27
|
|
12
|
-
|
28
|
+
it_should_behave_like 'Factory'
|
29
|
+
|
30
|
+
describe 'using factor_class_method to point to default_class' do
|
31
|
+
before :each do
|
32
|
+
subject.clear_factory!
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set it' do
|
36
|
+
subject.factory_build('hello', :works => true).name.should == 'hello'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'using default_class as fallback' do
|
41
|
+
before do
|
42
|
+
subject.clear_factory!
|
43
|
+
subject.factory_class_method = ''
|
44
|
+
end
|
45
|
+
|
46
|
+
specify { subject.factory_class_method.should be_blank }
|
13
47
|
|
14
|
-
|
48
|
+
it 'should set it' do
|
49
|
+
subject.factory_build('hello', :works => true).name.should == 'hello'
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'no factory defined' do
|
53
|
+
before do
|
54
|
+
AliasedCustomFactory = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
specify do
|
58
|
+
lambda { subject.factory_build('hello', :works => true) }.should raise_error
|
59
|
+
end
|
60
|
+
end
|
15
61
|
end
|
16
62
|
end
|
17
63
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cantango-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70260051165800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70260051165800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sugar-high
|
27
|
-
requirement: &
|
27
|
+
requirement: &70260051161180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.6.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70260051161180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sweetloader
|
38
|
-
requirement: &
|
38
|
+
requirement: &70260051155060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.1.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70260051155060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: hashie
|
49
|
-
requirement: &
|
49
|
+
requirement: &70260051153740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,21 +54,21 @@ dependencies:
|
|
54
54
|
version: 0.4.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70260051153740
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: cantango-core
|
60
|
-
requirement: &
|
60
|
+
requirement: &70260051151740 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.1.
|
65
|
+
version: 0.1.9
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70260051151740
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70260051147580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.1.rc
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70260051147580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: jeweler
|
82
|
-
requirement: &
|
82
|
+
requirement: &70260051135740 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.6.4
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70260051135740
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rcov
|
93
|
-
requirement: &
|
93
|
+
requirement: &70260051132200 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70260051132200
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rspec
|
104
|
-
requirement: &
|
104
|
+
requirement: &70260051129140 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: 2.6.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70260051129140
|
113
113
|
description: Configuration DSL for configuring CanTango
|
114
114
|
email: kmandrup@gmail.com
|
115
115
|
executables: []
|
@@ -223,7 +223,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
223
223
|
version: '0'
|
224
224
|
segments:
|
225
225
|
- 0
|
226
|
-
hash:
|
226
|
+
hash: 4402605893604119598
|
227
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
228
|
none: false
|
229
229
|
requirements:
|