cantango-config 0.1.9.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/README.mdown +16 -0
  2. data/VERSION +1 -1
  3. data/cantango-config.gemspec +68 -62
  4. data/lib/cantango/category.rb +18 -0
  5. data/lib/cantango/class_methods.rb +10 -0
  6. data/lib/cantango/config.rb +43 -2
  7. data/lib/cantango/{configuration → config}/ability.rb +8 -3
  8. data/lib/cantango/config/ability/engine.rb +45 -0
  9. data/lib/cantango/config/ability/modes.rb +16 -0
  10. data/lib/cantango/config/ability/modes/execution.rb +19 -0
  11. data/lib/cantango/{configuration → config}/account.rb +1 -1
  12. data/lib/cantango/{configuration → config}/accounts.rb +2 -3
  13. data/lib/cantango/{configuration → config}/adapters.rb +4 -4
  14. data/lib/cantango/{configuration → config}/autoload.rb +1 -1
  15. data/lib/cantango/{configuration → config}/categories.rb +3 -4
  16. data/lib/cantango/config/class_methods.rb +27 -0
  17. data/lib/cantango/{configuration → config}/debug.rb +1 -1
  18. data/lib/cantango/config/engines.rb +47 -0
  19. data/lib/cantango/config/engines/available.rb +19 -0
  20. data/lib/cantango/config/engines/order.rb +48 -0
  21. data/lib/cantango/{configuration → config}/factory.rb +1 -1
  22. data/lib/cantango/{configuration → config}/guest.rb +5 -6
  23. data/lib/cantango/config/helpers.rb +17 -0
  24. data/lib/cantango/{configuration → config}/hooks.rb +3 -3
  25. data/lib/cantango/{configuration → config}/localhosts.rb +4 -5
  26. data/lib/cantango/{configuration → config}/models.rb +16 -7
  27. data/lib/cantango/{configuration → config}/models/actions.rb +0 -0
  28. data/lib/cantango/{configuration → config}/models/active_record.rb +0 -0
  29. data/lib/cantango/{configuration → config}/models/data_mapper.rb +0 -0
  30. data/lib/cantango/{configuration → config}/models/generic.rb +0 -0
  31. data/lib/cantango/{configuration → config}/models/mongo.rb +0 -0
  32. data/lib/cantango/{configuration → config}/models/mongo_mapper.rb +0 -0
  33. data/lib/cantango/{configuration → config}/models/mongoid.rb +0 -0
  34. data/lib/cantango/{configuration → config}/orms.rb +2 -2
  35. data/lib/cantango/{configuration → config}/user.rb +1 -1
  36. data/lib/cantango/{configuration → config}/users.rb +2 -2
  37. data/lib/cantango/registry.rb +5 -0
  38. data/lib/cantango/{configuration/registry → registry}/base.rb +18 -4
  39. data/lib/cantango/registry/clazz.rb +92 -0
  40. data/lib/cantango/{configuration/registry → registry}/hash.rb +8 -10
  41. data/spec/cantango/category_spec.rb +21 -0
  42. data/spec/cantango/config/ability/modes/execution_spec.rb +33 -0
  43. data/spec/cantango/{configuration → config/ability}/modes_spec.rb +3 -3
  44. data/spec/cantango/{configuration → config}/ability_spec.rb +3 -3
  45. data/spec/cantango/{configuration → config}/account_spec.rb +1 -1
  46. data/spec/cantango/{configuration → config}/accounts_spec.rb +3 -3
  47. data/spec/cantango/{configuration → config}/adapters_spec.rb +1 -1
  48. data/spec/cantango/{configuration → config}/autoload_spec.rb +1 -2
  49. data/spec/cantango/{configuration → config}/categories_spec.rb +2 -10
  50. data/spec/cantango/config/class_methods_spec.rb +12 -0
  51. data/spec/cantango/{configuration → config}/debug_spec.rb +2 -7
  52. data/spec/cantango/config/engines/available_spec.rb +29 -0
  53. data/spec/cantango/{configuration → config}/engines/engine_shared.rb +0 -0
  54. data/spec/cantango/{configuration/engines_spec.rb → config/engines/order_spec.rb} +9 -54
  55. data/spec/cantango/config/engines_spec.rb +59 -0
  56. data/spec/cantango/{configuration → config}/factory_spec.rb +3 -3
  57. data/spec/cantango/{configuration → config}/guest/find_guest_default_way_spec.rb +1 -1
  58. data/spec/cantango/{configuration → config}/guest_spec.rb +2 -2
  59. data/spec/cantango/config/helpers_spec.rb +15 -0
  60. data/spec/cantango/config/localhosts_spec.rb +8 -0
  61. data/spec/cantango/{configuration → config}/models_spec.rb +10 -3
  62. data/spec/cantango/{configuration → config}/orms_spec.rb +2 -2
  63. data/spec/cantango/{configuration → config}/shared/factory_ex.rb +0 -0
  64. data/spec/cantango/{configuration → config}/user_spec.rb +2 -2
  65. data/spec/cantango/{configuration → config}/users_spec.rb +4 -4
  66. data/spec/cantango/config_spec.rb +86 -5
  67. data/spec/cantango/{configuration/registry → registry}/base_spec.rb +2 -2
  68. data/spec/cantango/{configuration/registry/candidate_spec.rb → registry/clazz_spec.rb} +2 -2
  69. data/spec/cantango/{configuration/registry → registry}/hash_spec.rb +2 -2
  70. data/spec/cantango/{configuration/shared/registry → registry/shared}/base_ex.rb +0 -0
  71. data/spec/cantango/{configuration/shared/registry → registry/shared}/clazz_ex.rb +0 -0
  72. data/spec/cantango/{configuration/shared/registry → registry/shared}/hash_ex.rb +0 -0
  73. metadata +87 -81
  74. data/lib/cantango/configuration.rb +0 -110
  75. data/lib/cantango/configuration/category.rb +0 -20
  76. data/lib/cantango/configuration/engine.rb +0 -33
  77. data/lib/cantango/configuration/engines.rb +0 -95
  78. data/lib/cantango/configuration/execution_modes.rb +0 -21
  79. data/lib/cantango/configuration/modes.rb +0 -8
  80. data/lib/cantango/configuration/registry.rb +0 -7
  81. data/lib/cantango/configuration/registry/clazz.rb +0 -94
  82. data/spec/cantango/configuration/execution_modes_spec.rb +0 -15
  83. data/spec/cantango/configuration/localhosts_spec.rb +0 -9
  84. data/spec/cantango/configuration/shared/execution_modes_ex.rb +0 -14
  85. data/spec/cantango/configuration_spec.rb +0 -112
data/README.mdown CHANGED
@@ -42,6 +42,22 @@ CanTango.config.accounts do |accounts|
42
42
  end
43
43
  ```
44
44
 
45
+ ## Registry
46
+
47
+ The Registry namespace contains registries useful for configuration and other purposes.
48
+
49
+ * CanTango::Registry
50
+ * Base
51
+ * Hash
52
+ * Clazz
53
+
54
+ ## Adapter
55
+
56
+ * Compiler
57
+ * Moneta
58
+
59
+ The Compiler and Moneta adapters are used when Caching/Persisting rules in a data store.
60
+
45
61
  ## Contributing to cantango-config
46
62
 
47
63
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9.2
1
+ 0.2.0
@@ -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.9.2"
8
+ s.version = "0.2.0"
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-08}
12
+ s.date = %q{2011-12-12}
13
13
  s.description = %q{Configuration DSL for configuring CanTango}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -28,72 +28,78 @@ Gem::Specification.new do |s|
28
28
  "cantango-config.gemspec",
29
29
  "lib/cantango/adapter/compiler.rb",
30
30
  "lib/cantango/adapter/moneta.rb",
31
+ "lib/cantango/category.rb",
31
32
  "lib/cantango/class_methods.rb",
32
33
  "lib/cantango/config.rb",
34
+ "lib/cantango/config/ability.rb",
35
+ "lib/cantango/config/ability/engine.rb",
36
+ "lib/cantango/config/ability/modes.rb",
37
+ "lib/cantango/config/ability/modes/execution.rb",
38
+ "lib/cantango/config/account.rb",
39
+ "lib/cantango/config/accounts.rb",
40
+ "lib/cantango/config/adapters.rb",
41
+ "lib/cantango/config/autoload.rb",
42
+ "lib/cantango/config/categories.rb",
43
+ "lib/cantango/config/class_methods.rb",
44
+ "lib/cantango/config/debug.rb",
45
+ "lib/cantango/config/engines.rb",
46
+ "lib/cantango/config/engines/available.rb",
47
+ "lib/cantango/config/engines/order.rb",
48
+ "lib/cantango/config/factory.rb",
49
+ "lib/cantango/config/guest.rb",
50
+ "lib/cantango/config/helpers.rb",
51
+ "lib/cantango/config/hooks.rb",
52
+ "lib/cantango/config/localhosts.rb",
53
+ "lib/cantango/config/models.rb",
54
+ "lib/cantango/config/models/actions.rb",
55
+ "lib/cantango/config/models/active_record.rb",
56
+ "lib/cantango/config/models/data_mapper.rb",
57
+ "lib/cantango/config/models/generic.rb",
58
+ "lib/cantango/config/models/mongo.rb",
59
+ "lib/cantango/config/models/mongo_mapper.rb",
60
+ "lib/cantango/config/models/mongoid.rb",
61
+ "lib/cantango/config/orms.rb",
62
+ "lib/cantango/config/user.rb",
63
+ "lib/cantango/config/users.rb",
33
64
  "lib/cantango/config_ext.rb",
34
65
  "lib/cantango/config_ext/loader.rb",
35
66
  "lib/cantango/config_ext/loader/yaml.rb",
36
- "lib/cantango/configuration.rb",
37
- "lib/cantango/configuration/ability.rb",
38
- "lib/cantango/configuration/account.rb",
39
- "lib/cantango/configuration/accounts.rb",
40
- "lib/cantango/configuration/adapters.rb",
41
- "lib/cantango/configuration/autoload.rb",
42
- "lib/cantango/configuration/categories.rb",
43
- "lib/cantango/configuration/category.rb",
44
- "lib/cantango/configuration/debug.rb",
45
- "lib/cantango/configuration/engine.rb",
46
- "lib/cantango/configuration/engines.rb",
47
- "lib/cantango/configuration/execution_modes.rb",
48
- "lib/cantango/configuration/factory.rb",
49
- "lib/cantango/configuration/guest.rb",
50
- "lib/cantango/configuration/hooks.rb",
51
- "lib/cantango/configuration/localhosts.rb",
52
- "lib/cantango/configuration/models.rb",
53
- "lib/cantango/configuration/models/actions.rb",
54
- "lib/cantango/configuration/models/active_record.rb",
55
- "lib/cantango/configuration/models/data_mapper.rb",
56
- "lib/cantango/configuration/models/generic.rb",
57
- "lib/cantango/configuration/models/mongo.rb",
58
- "lib/cantango/configuration/models/mongo_mapper.rb",
59
- "lib/cantango/configuration/models/mongoid.rb",
60
- "lib/cantango/configuration/modes.rb",
61
- "lib/cantango/configuration/orms.rb",
62
- "lib/cantango/configuration/registry.rb",
63
- "lib/cantango/configuration/registry/base.rb",
64
- "lib/cantango/configuration/registry/clazz.rb",
65
- "lib/cantango/configuration/registry/hash.rb",
66
- "lib/cantango/configuration/user.rb",
67
- "lib/cantango/configuration/users.rb",
67
+ "lib/cantango/registry.rb",
68
+ "lib/cantango/registry/base.rb",
69
+ "lib/cantango/registry/clazz.rb",
70
+ "lib/cantango/registry/hash.rb",
71
+ "spec/cantango/category_spec.rb",
72
+ "spec/cantango/config/ability/modes/execution_spec.rb",
73
+ "spec/cantango/config/ability/modes_spec.rb",
74
+ "spec/cantango/config/ability_spec.rb",
75
+ "spec/cantango/config/account_spec.rb",
76
+ "spec/cantango/config/accounts_spec.rb",
77
+ "spec/cantango/config/adapters_spec.rb",
78
+ "spec/cantango/config/autoload_spec.rb",
79
+ "spec/cantango/config/categories_spec.rb",
80
+ "spec/cantango/config/class_methods_spec.rb",
81
+ "spec/cantango/config/debug_spec.rb",
82
+ "spec/cantango/config/engines/available_spec.rb",
83
+ "spec/cantango/config/engines/engine_shared.rb",
84
+ "spec/cantango/config/engines/order_spec.rb",
85
+ "spec/cantango/config/engines_spec.rb",
86
+ "spec/cantango/config/factory_spec.rb",
87
+ "spec/cantango/config/guest/find_guest_default_way_spec.rb",
88
+ "spec/cantango/config/guest_spec.rb",
89
+ "spec/cantango/config/helpers_spec.rb",
90
+ "spec/cantango/config/localhosts_spec.rb",
91
+ "spec/cantango/config/models_spec.rb",
92
+ "spec/cantango/config/orms_spec.rb",
93
+ "spec/cantango/config/shared/factory_ex.rb",
94
+ "spec/cantango/config/user_spec.rb",
95
+ "spec/cantango/config/users_spec.rb",
68
96
  "spec/cantango/config_spec.rb",
69
- "spec/cantango/configuration/ability_spec.rb",
70
- "spec/cantango/configuration/account_spec.rb",
71
- "spec/cantango/configuration/accounts_spec.rb",
72
- "spec/cantango/configuration/adapters_spec.rb",
73
- "spec/cantango/configuration/autoload_spec.rb",
74
- "spec/cantango/configuration/categories_spec.rb",
75
- "spec/cantango/configuration/debug_spec.rb",
76
- "spec/cantango/configuration/engines/engine_shared.rb",
77
- "spec/cantango/configuration/engines_spec.rb",
78
- "spec/cantango/configuration/execution_modes_spec.rb",
79
- "spec/cantango/configuration/factory_spec.rb",
80
- "spec/cantango/configuration/guest/find_guest_default_way_spec.rb",
81
- "spec/cantango/configuration/guest_spec.rb",
82
- "spec/cantango/configuration/localhosts_spec.rb",
83
- "spec/cantango/configuration/models_spec.rb",
84
- "spec/cantango/configuration/modes_spec.rb",
85
- "spec/cantango/configuration/orms_spec.rb",
86
- "spec/cantango/configuration/registry/base_spec.rb",
87
- "spec/cantango/configuration/registry/candidate_spec.rb",
88
- "spec/cantango/configuration/registry/hash_spec.rb",
89
- "spec/cantango/configuration/shared/execution_modes_ex.rb",
90
- "spec/cantango/configuration/shared/factory_ex.rb",
91
- "spec/cantango/configuration/shared/registry/base_ex.rb",
92
- "spec/cantango/configuration/shared/registry/clazz_ex.rb",
93
- "spec/cantango/configuration/shared/registry/hash_ex.rb",
94
- "spec/cantango/configuration/user_spec.rb",
95
- "spec/cantango/configuration/users_spec.rb",
96
- "spec/cantango/configuration_spec.rb",
97
+ "spec/cantango/registry/base_spec.rb",
98
+ "spec/cantango/registry/clazz_spec.rb",
99
+ "spec/cantango/registry/hash_spec.rb",
100
+ "spec/cantango/registry/shared/base_ex.rb",
101
+ "spec/cantango/registry/shared/clazz_ex.rb",
102
+ "spec/cantango/registry/shared/hash_ex.rb",
97
103
  "spec/db/database.yml",
98
104
  "spec/factories/project.rb",
99
105
  "spec/fixtures/models.rb",
@@ -0,0 +1,18 @@
1
+ module CanTango
2
+ class Category
3
+ def initialize *subjects
4
+ @subjects = subjects.flatten
5
+ end
6
+
7
+ def subjects
8
+ @subjects ||= []
9
+ end
10
+
11
+ # test if a particular category has a certain subject
12
+ def has_any? subject, &block
13
+ found = subjects.include? subject
14
+ yield if found && block
15
+ found
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,15 @@
1
1
  module CanTango
2
2
  module ClassMethods
3
+ def self.extended base
4
+ end
5
+
6
+ def configure &block
7
+ conf = CanTango::Config.instance
8
+ yield conf if block
9
+ conf
10
+ end
11
+
12
+ alias_method :config, :configure
3
13
  # Engine hook
4
14
  # Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built.
5
15
  # More importantly, will run upon every request in development, but only once (during boot-up) in production and test.
@@ -1,6 +1,8 @@
1
1
  require 'sugar-high/array'
2
2
  require 'sugar-high/blank'
3
3
  require 'hashie'
4
+ require 'set'
5
+ require 'singleton'
4
6
  require 'sweetloader'
5
7
 
6
8
  require 'cantango/core'
@@ -9,7 +11,46 @@ SweetLoader.namespaces = {:CanTango => 'cantango'}
9
11
  SweetLoader.mode = :require
10
12
 
11
13
  module CanTango
12
- autoload_modules :Configuration, :ClassMethods
13
- include ClassMethods
14
+ sweetload :Registry, :ClassMethods, :Category
15
+ extend ClassMethods
16
+
17
+ class Config
18
+ sweetload :Models, :Engines, :Factory, :Ability
19
+ sweetload :Categories
20
+ sweetload :Autoload, :Adapters, :Debug, :Orms, :Localhosts, :Hooks, :Helpers
21
+ sweetload :Account, :Accounts
22
+ sweetload :User, :Guest, :Users
23
+ sweetload :ClassMethods
24
+
25
+ include Singleton
26
+ extend ClassMethods
27
+
28
+ def ability
29
+ @ability ||= CanTango::Config::Ability.instance
30
+ @ability.default_class ||= CanTango::Ability::Executor::Modal # from cantango-core
31
+ @ability
32
+ end
33
+
34
+ def debug!
35
+ debug.on!
36
+ end
37
+
38
+ # Turn on default engines and enable compile adapter
39
+ # i.e compilation of rules via sourcify
40
+ def default_settings!
41
+ engines.all :off
42
+ end
43
+
44
+ def clear!
45
+ CanTango::Configuration.components.each do |component|
46
+ if respond_to? component
47
+ component = send(component)
48
+ component.send(:clear!) if component.respond_to? :clear!
49
+ end
50
+ end
51
+ engines.clear!
52
+ end
53
+ end
14
54
  end
55
+
15
56
  require 'cantango/config_ext'
@@ -1,11 +1,16 @@
1
1
  module CanTango
2
- class Configuration
2
+ class Config
3
3
  class Ability
4
+ sweetload :Engine, :Modes
5
+
4
6
  include Singleton
5
7
  include ClassExt
6
8
 
7
- include CanTango::Configuration::Factory
8
- include CanTango::Configuration::ExecutionModes
9
+ include CanTango::Config::Factory
10
+
11
+ def modes
12
+ Modes.instance
13
+ end
9
14
 
10
15
  def default_executor_class
11
16
  @default_executor_class ||= CanTango::Ability::Executor::Modal
@@ -0,0 +1,45 @@
1
+ require 'singleton'
2
+
3
+ module CanTango
4
+ class Config
5
+ class Ability
6
+ # allow either block or direct access
7
+ # engine(:permission) do |permission|
8
+ # engine(:permission).config_path
9
+ def engine name, &block
10
+ engine = find_engine(name)
11
+ yield engine if block
12
+ engine
13
+ end
14
+
15
+ protected
16
+
17
+ def find_engine name
18
+ raise ArgumentError, "Must be label for an engine" if !name.kind_of_label?
19
+ name = name.to_s.singularize
20
+ engines.send(name) if engines.available? name
21
+ end
22
+
23
+ class Engine
24
+ include Singleton
25
+
26
+ def set state = :on
27
+ raise ArgumentError, "Must be :on or :off" unless !state || [:on, :off].include?(state)
28
+ @state = state || :on
29
+ end
30
+
31
+ def reset!
32
+ @state = nil
33
+ end
34
+
35
+ def on?
36
+ @state == :on
37
+ end
38
+
39
+ def off?
40
+ !on?
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,16 @@
1
+ module CanTango
2
+ class Config
3
+ class Ability
4
+ class Modes < CanTango::Registry::Clazz
5
+ include Singleton
6
+
7
+ sweetload :Execution
8
+
9
+ def execution
10
+ Execution.instance
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ module CanTango
2
+ class Config
3
+ class Ability
4
+ class Modes
5
+ class Execution < CanTango::Registry::Base
6
+ include Singleton
7
+
8
+ def default
9
+ @default ||= [:no_cache]
10
+ end
11
+
12
+ def available
13
+ [:cache, :no_cache]
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module CanTango
2
- class Configuration
2
+ class Config
3
3
  class Account
4
4
  include Singleton
5
5
  include ClassExt
@@ -1,13 +1,12 @@
1
1
  module CanTango
2
- class Configuration
3
- class Accounts < Registry::Clazz
2
+ class Config
3
+ class Accounts < CanTango::Registry::Clazz
4
4
  include Singleton
5
5
 
6
6
  def register_account clazz
7
7
  register account_name(clazz), clazz
8
8
  self
9
9
  end
10
- alias_method :register_class, :register_account
11
10
 
12
11
  protected
13
12
 
@@ -1,10 +1,10 @@
1
1
  module CanTango
2
- class Configuration
3
- class Adapters < Registry::Base
2
+ class Config
3
+ class Adapters < CanTango::Registry::Base
4
4
  include Singleton
5
5
 
6
6
  def adapter name
7
- raise "Unknown adapter #{name}" if !available_adapters.include? name.to_sym
7
+ raise "Unknown adapter #{name}" if !available.include? name.to_sym
8
8
  require "cantango/adapter/#{name}"
9
9
  end
10
10
 
@@ -12,7 +12,7 @@ module CanTango
12
12
  names.each {|name| adapter name }
13
13
  end
14
14
 
15
- def available_adapters
15
+ def available
16
16
  [:moneta, :compiler]
17
17
  end
18
18
  end
@@ -1,5 +1,5 @@
1
1
  module CanTango
2
- class Configuration
2
+ class Config
3
3
  class Autoload
4
4
  include Singleton
5
5
 
@@ -1,7 +1,6 @@
1
1
  module CanTango
2
- class Configuration
3
- class Categories < Registry::Hash
4
-
2
+ class Config
3
+ class Categories < CanTango::Registry::Hash
5
4
  include Singleton
6
5
 
7
6
  def [] label
@@ -11,7 +10,7 @@ module CanTango
11
10
  end
12
11
 
13
12
  def category label, &block
14
- cat = Category.new self[label]
13
+ cat = CanTango::Category.new self[label]
15
14
  yield cat if block
16
15
  cat
17
16
  end