cantango-config 0.1.9.2 → 0.2.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/README.mdown +16 -0
- data/VERSION +1 -1
- data/cantango-config.gemspec +68 -62
- data/lib/cantango/category.rb +18 -0
- data/lib/cantango/class_methods.rb +10 -0
- data/lib/cantango/config.rb +43 -2
- data/lib/cantango/{configuration → config}/ability.rb +8 -3
- data/lib/cantango/config/ability/engine.rb +45 -0
- data/lib/cantango/config/ability/modes.rb +16 -0
- data/lib/cantango/config/ability/modes/execution.rb +19 -0
- data/lib/cantango/{configuration → config}/account.rb +1 -1
- data/lib/cantango/{configuration → config}/accounts.rb +2 -3
- data/lib/cantango/{configuration → config}/adapters.rb +4 -4
- data/lib/cantango/{configuration → config}/autoload.rb +1 -1
- data/lib/cantango/{configuration → config}/categories.rb +3 -4
- data/lib/cantango/config/class_methods.rb +27 -0
- data/lib/cantango/{configuration → config}/debug.rb +1 -1
- data/lib/cantango/config/engines.rb +47 -0
- data/lib/cantango/config/engines/available.rb +19 -0
- data/lib/cantango/config/engines/order.rb +48 -0
- data/lib/cantango/{configuration → config}/factory.rb +1 -1
- data/lib/cantango/{configuration → config}/guest.rb +5 -6
- data/lib/cantango/config/helpers.rb +17 -0
- data/lib/cantango/{configuration → config}/hooks.rb +3 -3
- data/lib/cantango/{configuration → config}/localhosts.rb +4 -5
- data/lib/cantango/{configuration → config}/models.rb +16 -7
- data/lib/cantango/{configuration → config}/models/actions.rb +0 -0
- data/lib/cantango/{configuration → config}/models/active_record.rb +0 -0
- data/lib/cantango/{configuration → config}/models/data_mapper.rb +0 -0
- data/lib/cantango/{configuration → config}/models/generic.rb +0 -0
- data/lib/cantango/{configuration → config}/models/mongo.rb +0 -0
- data/lib/cantango/{configuration → config}/models/mongo_mapper.rb +0 -0
- data/lib/cantango/{configuration → config}/models/mongoid.rb +0 -0
- data/lib/cantango/{configuration → config}/orms.rb +2 -2
- data/lib/cantango/{configuration → config}/user.rb +1 -1
- data/lib/cantango/{configuration → config}/users.rb +2 -2
- data/lib/cantango/registry.rb +5 -0
- data/lib/cantango/{configuration/registry → registry}/base.rb +18 -4
- data/lib/cantango/registry/clazz.rb +92 -0
- data/lib/cantango/{configuration/registry → registry}/hash.rb +8 -10
- data/spec/cantango/category_spec.rb +21 -0
- data/spec/cantango/config/ability/modes/execution_spec.rb +33 -0
- data/spec/cantango/{configuration → config/ability}/modes_spec.rb +3 -3
- data/spec/cantango/{configuration → config}/ability_spec.rb +3 -3
- data/spec/cantango/{configuration → config}/account_spec.rb +1 -1
- data/spec/cantango/{configuration → config}/accounts_spec.rb +3 -3
- data/spec/cantango/{configuration → config}/adapters_spec.rb +1 -1
- data/spec/cantango/{configuration → config}/autoload_spec.rb +1 -2
- data/spec/cantango/{configuration → config}/categories_spec.rb +2 -10
- data/spec/cantango/config/class_methods_spec.rb +12 -0
- data/spec/cantango/{configuration → config}/debug_spec.rb +2 -7
- data/spec/cantango/config/engines/available_spec.rb +29 -0
- data/spec/cantango/{configuration → config}/engines/engine_shared.rb +0 -0
- data/spec/cantango/{configuration/engines_spec.rb → config/engines/order_spec.rb} +9 -54
- data/spec/cantango/config/engines_spec.rb +59 -0
- data/spec/cantango/{configuration → config}/factory_spec.rb +3 -3
- data/spec/cantango/{configuration → config}/guest/find_guest_default_way_spec.rb +1 -1
- data/spec/cantango/{configuration → config}/guest_spec.rb +2 -2
- data/spec/cantango/config/helpers_spec.rb +15 -0
- data/spec/cantango/config/localhosts_spec.rb +8 -0
- data/spec/cantango/{configuration → config}/models_spec.rb +10 -3
- data/spec/cantango/{configuration → config}/orms_spec.rb +2 -2
- data/spec/cantango/{configuration → config}/shared/factory_ex.rb +0 -0
- data/spec/cantango/{configuration → config}/user_spec.rb +2 -2
- data/spec/cantango/{configuration → config}/users_spec.rb +4 -4
- data/spec/cantango/config_spec.rb +86 -5
- data/spec/cantango/{configuration/registry → registry}/base_spec.rb +2 -2
- data/spec/cantango/{configuration/registry/candidate_spec.rb → registry/clazz_spec.rb} +2 -2
- data/spec/cantango/{configuration/registry → registry}/hash_spec.rb +2 -2
- data/spec/cantango/{configuration/shared/registry → registry/shared}/base_ex.rb +0 -0
- data/spec/cantango/{configuration/shared/registry → registry/shared}/clazz_ex.rb +0 -0
- data/spec/cantango/{configuration/shared/registry → registry/shared}/hash_ex.rb +0 -0
- metadata +87 -81
- data/lib/cantango/configuration.rb +0 -110
- data/lib/cantango/configuration/category.rb +0 -20
- data/lib/cantango/configuration/engine.rb +0 -33
- data/lib/cantango/configuration/engines.rb +0 -95
- data/lib/cantango/configuration/execution_modes.rb +0 -21
- data/lib/cantango/configuration/modes.rb +0 -8
- data/lib/cantango/configuration/registry.rb +0 -7
- data/lib/cantango/configuration/registry/clazz.rb +0 -94
- data/spec/cantango/configuration/execution_modes_spec.rb +0 -15
- data/spec/cantango/configuration/localhosts_spec.rb +0 -9
- data/spec/cantango/configuration/shared/execution_modes_ex.rb +0 -14
- data/spec/cantango/configuration_spec.rb +0 -112
@@ -0,0 +1,27 @@
|
|
1
|
+
module CanTango
|
2
|
+
class Config
|
3
|
+
module ClassMethods
|
4
|
+
def self.extended base
|
5
|
+
base.class_eval do
|
6
|
+
components.each do |conf_module|
|
7
|
+
class_eval %{
|
8
|
+
def #{conf_module} &block
|
9
|
+
conf = conf::#{conf_module.to_s.camelize}.instance
|
10
|
+
yield conf if block
|
11
|
+
conf
|
12
|
+
end
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def components
|
19
|
+
[
|
20
|
+
:guest, :autoload, :user, :account, :models, :modes, :roles, :role_groups,
|
21
|
+
:engines, :users, :accounts, :categories, :adapters, :debug,
|
22
|
+
:localhosts, :orms, :hooks, :helpers
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CanTango
|
2
|
+
class Config
|
3
|
+
class Engines
|
4
|
+
sweetload :Order, :Available
|
5
|
+
|
6
|
+
include Singleton
|
7
|
+
include Enumerable
|
8
|
+
include Order
|
9
|
+
include Available
|
10
|
+
include CanTango::Registry::Hash::InstanceMethods
|
11
|
+
|
12
|
+
# engine registry is a simple hash
|
13
|
+
def register hash
|
14
|
+
hash.each_pair do |name, engine_class|
|
15
|
+
raise "Class must implement the CanTango::Engine API." unless self.class.valid_engine?(engine_class)
|
16
|
+
raise "Name of engine must be a String or Symbol" if !name.kind_of_label?
|
17
|
+
registered[name.to_s] = engine_class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear!
|
22
|
+
each {|engine| engine.reset! }
|
23
|
+
@registered = nil
|
24
|
+
clear_order!
|
25
|
+
end
|
26
|
+
|
27
|
+
def each
|
28
|
+
available.each {|engine| yield send(engine) if respond_to?(engine) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def active? name
|
32
|
+
active.include? name.to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
def active_list
|
36
|
+
available.select {|engine| send(engine).on? if respond_to?(engine) }
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
# does it implement the basic Engine API?
|
42
|
+
def self.valid_engine? engine_class
|
43
|
+
[:execute!, :ability].all? {|meth| engine_class.instance_methods.include? meth }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CanTango::Config::Engines
|
2
|
+
module Available
|
3
|
+
def available
|
4
|
+
registered_names
|
5
|
+
end
|
6
|
+
|
7
|
+
def available? name
|
8
|
+
available.include? name.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def all state
|
12
|
+
available.each {|engine| send(engine).set state }
|
13
|
+
end
|
14
|
+
|
15
|
+
def any? state
|
16
|
+
available.any? {|engine| send(engine).send(:"#{state}?") if respond_to?(engine) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module CanTango
|
2
|
+
class Config
|
3
|
+
class Engines
|
4
|
+
module Order
|
5
|
+
def clear_order!
|
6
|
+
@execution_order = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
# defines the order of execution of engine in ability
|
10
|
+
def set_execution_order *names
|
11
|
+
@execution_order = names.flatten.uniq.map(&:to_s).select {|name| available? name }
|
12
|
+
end
|
13
|
+
|
14
|
+
def dont_execute name
|
15
|
+
execution_order.delete(name.to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute_first name
|
19
|
+
dont_execute name
|
20
|
+
execution_order.insert(0, name.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute_last name
|
24
|
+
dont_execute name
|
25
|
+
execution_order.insert(-1, name.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_before existing, name
|
29
|
+
dont_execute name
|
30
|
+
index = execution_order.index(existing.to_s) || 0
|
31
|
+
execution_order.insert(index, name.to_s)
|
32
|
+
execution_order.compact!
|
33
|
+
end
|
34
|
+
|
35
|
+
def execute_after existing, name
|
36
|
+
dont_execute name
|
37
|
+
index = execution_order.index(existing.to_s)
|
38
|
+
index ? execution_order.insert(index +1, name.to_s) : execute_last(name)
|
39
|
+
execution_order.compact!
|
40
|
+
end
|
41
|
+
|
42
|
+
def execution_order
|
43
|
+
@execution_order ||= (available - [:cache])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module CanTango
|
2
|
-
class
|
2
|
+
class Config
|
3
3
|
class Guest
|
4
4
|
include Singleton
|
5
5
|
|
@@ -15,11 +15,10 @@ module CanTango
|
|
15
15
|
|
16
16
|
alias_method :user=, :user
|
17
17
|
|
18
|
-
def account
|
19
|
-
return (@account ||
|
20
|
-
@account =
|
18
|
+
def account acc = nil, &block
|
19
|
+
return (@account || acc) if !acc && !block
|
20
|
+
@account = acc || yield
|
21
21
|
end
|
22
|
-
alias_method :user_account, :account
|
23
22
|
alias_method :account=, :account
|
24
23
|
|
25
24
|
def default_user?
|
@@ -49,7 +48,7 @@ module CanTango
|
|
49
48
|
end
|
50
49
|
|
51
50
|
def base_account_class
|
52
|
-
CanTango.config.
|
51
|
+
CanTango.config.account.base_class
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CanTango
|
2
|
+
class Config
|
3
|
+
class Helpers
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def enable *names
|
7
|
+
names = names.to_symbols
|
8
|
+
enable_rest if names.include? :rest
|
9
|
+
end
|
10
|
+
|
11
|
+
def enable_rest
|
12
|
+
raise 'ApplicationController not defined' if !defined?(::ApplicationController)
|
13
|
+
::ApplicationController.send :include, CanTango::Rails::Helpers::RestHelper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module CanTango
|
2
|
-
class
|
3
|
-
class Localhosts < Registry::Base
|
2
|
+
class Config
|
3
|
+
class Localhosts < CanTango::Registry::Base
|
4
4
|
include Singleton
|
5
|
-
|
5
|
+
|
6
6
|
def default
|
7
7
|
@default ||= ['localhost', '0.0.0.0', '127.0.0.1']
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
-
end
|
12
|
-
|
11
|
+
end
|
@@ -1,15 +1,24 @@
|
|
1
1
|
module CanTango
|
2
|
-
class
|
2
|
+
class Config
|
3
3
|
class Models
|
4
|
-
|
5
|
-
|
4
|
+
sweetload :Generic, :ActiveRecord, :DataMapper, :Mongo, :MongoMapper, :Mongoid
|
5
|
+
sweetload :Actions
|
6
6
|
|
7
7
|
include CanTango::Helpers::Debug
|
8
8
|
include Singleton
|
9
9
|
include ClassExt
|
10
10
|
|
11
|
+
def use *names
|
12
|
+
names = names.select_symbols
|
13
|
+
if names.include? :guest_user
|
14
|
+
require 'cantango/model/user/guest'
|
15
|
+
end
|
16
|
+
rescue LoadError => e
|
17
|
+
debug e.message
|
18
|
+
end
|
19
|
+
|
11
20
|
def actions
|
12
|
-
@actions ||= Registry::Hash.new
|
21
|
+
@actions ||= CanTango::Registry::Hash.new
|
13
22
|
end
|
14
23
|
|
15
24
|
def by_reg_exp reg_exp
|
@@ -34,13 +43,13 @@ module CanTango
|
|
34
43
|
@excluded ||= []
|
35
44
|
end
|
36
45
|
|
37
|
-
def
|
38
|
-
|
46
|
+
def available
|
47
|
+
all - excluded.map {|m| m.to_s.camelize}
|
39
48
|
end
|
40
49
|
|
41
50
|
protected
|
42
51
|
|
43
|
-
def
|
52
|
+
def all
|
44
53
|
CanTango.config.orms.registered.compact.inject([]) do |result, orm|
|
45
54
|
adapter = adapter_for(orm)
|
46
55
|
result << (adapter.models.map(&:name) if adapter)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -2,10 +2,10 @@ require 'singleton'
|
|
2
2
|
require 'sugar-high/kind_of'
|
3
3
|
|
4
4
|
module CanTango
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
attr_writer :default
|
5
|
+
module Registry
|
6
|
+
class Base
|
7
|
+
module InstanceMethods
|
8
|
+
attr_writer :default, :available
|
9
9
|
attr_accessor :registered
|
10
10
|
|
11
11
|
def types= *types
|
@@ -21,6 +21,10 @@ module CanTango
|
|
21
21
|
@registered = []
|
22
22
|
end
|
23
23
|
|
24
|
+
def reset!
|
25
|
+
@registered = default
|
26
|
+
end
|
27
|
+
|
24
28
|
alias_method :clear!, :clean!
|
25
29
|
|
26
30
|
def default!
|
@@ -49,7 +53,17 @@ module CanTango
|
|
49
53
|
def default
|
50
54
|
@default ||= []
|
51
55
|
end
|
56
|
+
|
57
|
+
def valid? label
|
58
|
+
return available.include?(label) if respond_to?(:available) && !available.empty?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def available
|
63
|
+
[]
|
64
|
+
end
|
52
65
|
end
|
66
|
+
include InstanceMethods
|
53
67
|
end
|
54
68
|
end
|
55
69
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'sugar-high/kind_of'
|
3
|
+
|
4
|
+
module CanTango::Registry
|
5
|
+
class Clazz
|
6
|
+
module InstanceMethods
|
7
|
+
def register label, value
|
8
|
+
raise "first arg must be a label, was: #{label}" if !label.kind_of_label?
|
9
|
+
raise "second arg must be a valid Class, was: #{value}" if !valid? value
|
10
|
+
name_registry.register label.to_sym
|
11
|
+
class_registry.register value
|
12
|
+
end
|
13
|
+
alias_method :[]=, :register
|
14
|
+
|
15
|
+
def << hash
|
16
|
+
raise "Must be a hash" if !hash.is_a?(::Hash)
|
17
|
+
hash.each_pair do |key, value|
|
18
|
+
register key, value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def registered
|
23
|
+
name_registry.registered
|
24
|
+
end
|
25
|
+
alias_method :registered_names, :registered
|
26
|
+
|
27
|
+
def clean!
|
28
|
+
name_registry.clean!
|
29
|
+
class_registry.clean!
|
30
|
+
end
|
31
|
+
alias_method :clear!, :clean!
|
32
|
+
|
33
|
+
def registered_classes
|
34
|
+
class_registry.registered
|
35
|
+
end
|
36
|
+
|
37
|
+
def registered? name
|
38
|
+
name_registry.registered? name
|
39
|
+
end
|
40
|
+
|
41
|
+
def registered_class? name
|
42
|
+
class_registry.registered? name
|
43
|
+
end
|
44
|
+
|
45
|
+
def name_registry
|
46
|
+
@name_registry ||=NameRegistry.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def class_registry
|
50
|
+
@class_registry ||= ClassRegistry.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def value_methods
|
54
|
+
class_registry.value_methods
|
55
|
+
end
|
56
|
+
|
57
|
+
def value_types
|
58
|
+
class_registry.types
|
59
|
+
end
|
60
|
+
|
61
|
+
class NameRegistry < CanTango::Registry::Base
|
62
|
+
end
|
63
|
+
|
64
|
+
class ClassRegistry < CanTango::Registry::Base
|
65
|
+
def types
|
66
|
+
[Class]
|
67
|
+
end
|
68
|
+
|
69
|
+
def value_methods
|
70
|
+
[]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def valid? value
|
77
|
+
valid_by_type?(value) && valid_by_methods?(value)
|
78
|
+
end
|
79
|
+
|
80
|
+
def valid_by_type? value
|
81
|
+
return true if value_types.blank?
|
82
|
+
value.any_kind_of?(*value_types)
|
83
|
+
end
|
84
|
+
|
85
|
+
def valid_by_methods? value
|
86
|
+
return true if value_methods.blank?
|
87
|
+
value_methods.all?{|m| value.respond_to(m)}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
include InstanceMethods
|
91
|
+
end
|
92
|
+
end
|