ixtlan-core 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,46 +1,74 @@
|
|
1
|
+
require 'slf4r'
|
1
2
|
module Ixtlan
|
2
3
|
module Core
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
module Configuration
|
5
|
+
module Module
|
6
|
+
def self.included(model)
|
7
|
+
raise "configuration class must have instance method" unless model.respond_to? :instance
|
8
|
+
model.class_eval do
|
9
|
+
class << self
|
10
|
+
alias :instance_old :instance
|
11
|
+
def instance
|
12
|
+
Thread.current[:ixtlan_configuration] ||= instance_old
|
13
|
+
end
|
14
|
+
def clear_instance
|
15
|
+
Thread.current[:ixtlan_configuration] = nil
|
16
|
+
end
|
14
17
|
end
|
15
|
-
|
16
|
-
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Manager
|
23
|
+
|
24
|
+
include Slf4r::Logger
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.registry
|
29
|
+
@registry ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def registry
|
33
|
+
self.class.registry
|
34
|
+
end
|
35
|
+
|
36
|
+
def model
|
37
|
+
unless @model
|
38
|
+
if @model_name
|
39
|
+
@model = @model_name.constantize
|
40
|
+
else
|
41
|
+
@model = ::Configuration
|
17
42
|
end
|
43
|
+
@model.send :include, Module unless @model.respond_to? :clear_instance
|
18
44
|
end
|
45
|
+
@model
|
46
|
+
end
|
19
47
|
|
20
|
-
|
21
|
-
|
22
|
-
|
48
|
+
public
|
49
|
+
|
50
|
+
def setup(model)
|
51
|
+
if model
|
52
|
+
@model_name = model.to_s.classify
|
23
53
|
end
|
24
54
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
55
|
+
|
56
|
+
def register(name, &block)
|
57
|
+
raise "need block" unless block
|
58
|
+
logger.info{"register config for: #{name}"}
|
59
|
+
registry[name.to_sym] = block
|
60
|
+
end
|
61
|
+
|
62
|
+
def cleanup
|
63
|
+
model.clear_instance
|
64
|
+
end
|
65
|
+
|
66
|
+
def configure
|
67
|
+
registry.each do |name, callback|
|
68
|
+
logger.debug{ "configure #{name}" }
|
69
|
+
callback.call(model.instance)
|
70
|
+
end
|
37
71
|
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def registry
|
43
|
-
self.class.registry
|
44
72
|
end
|
45
73
|
end
|
46
74
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Ixtlan
|
2
2
|
module Core
|
3
3
|
class ConfigurationRack
|
4
|
-
def initialize(app)
|
4
|
+
def initialize(app, config_manager)
|
5
5
|
@app = app
|
6
|
+
@manager = config_manager
|
6
7
|
end
|
7
8
|
|
8
9
|
def call(env)
|
9
|
-
model = Rails.application.config.configuration_model
|
10
10
|
# configure all registered components with current config
|
11
|
-
|
11
|
+
@manager.configure
|
12
12
|
result = @app.call(env)
|
13
|
-
|
13
|
+
@manager.cleanup
|
14
14
|
result
|
15
15
|
end
|
16
16
|
|
data/lib/ixtlan/core/railtie.rb
CHANGED
@@ -22,7 +22,7 @@ module Ixtlan
|
|
22
22
|
alias :available_views_old :available_views
|
23
23
|
def available_views
|
24
24
|
if options[:singleton]
|
25
|
-
%w(
|
25
|
+
%w(edit show _form)
|
26
26
|
else
|
27
27
|
available_views_old
|
28
28
|
end
|
@@ -47,22 +47,20 @@ module Ixtlan
|
|
47
47
|
end
|
48
48
|
|
49
49
|
config.before_initialize do |app|
|
50
|
-
app.config.
|
51
|
-
|
52
|
-
def configuration_model=(clazz)
|
53
|
-
clazz.send(:include, Ixtlan::Core::ConfigurationManager) #unless clazz.kind_of?(Ixtlan::Core::ConfigurationManager)
|
54
|
-
@configuration_model = clazz
|
55
|
-
end
|
56
|
-
end
|
50
|
+
app.config.configuration_manager = Configuration::Manager.new
|
51
|
+
|
57
52
|
::ActionController::Base.send(:include, Ixtlan::Core::ExtraHeaders)
|
58
53
|
::ActionController::Base.send(:include, Ixtlan::Core::XFrameHeaders)
|
59
54
|
::ActionController::Base.send(:include, Ixtlan::Core::XContentTypeHeaders)
|
60
55
|
::ActionController::Base.send(:include, Ixtlan::Core::XXssProtectionHeaders)
|
61
56
|
::ActionController::Base.send(:include, Ixtlan::Core::CacheHeaders)
|
62
57
|
|
63
|
-
app.config.middleware.use
|
58
|
+
app.config.middleware.use(Ixtlan::Core::ConfigurationRack, app.config.configuration_manager)
|
64
59
|
end
|
60
|
+
|
65
61
|
config.after_initialize do |app|
|
62
|
+
app.config.configuration_manager.setup(app.config.configuration_model) if app.config.respond_to? :configuration_model
|
63
|
+
|
66
64
|
if defined? ::DataMapper
|
67
65
|
|
68
66
|
::DataMapper::Resource.send(:include,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'ixtlan/core/configuration_manager'
|
2
2
|
require 'slf4r/ruby_logger'
|
3
|
+
require 'active_support/core_ext/string'
|
3
4
|
|
4
5
|
class ConfigModel
|
5
6
|
|
@@ -25,19 +26,23 @@ class ConfigModel
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
describe Ixtlan::Core::
|
29
|
+
describe Ixtlan::Core::Configuration::Manager do
|
29
30
|
|
30
31
|
before :all do
|
31
|
-
ConfigModel.send :include, Ixtlan::Core::
|
32
|
+
ConfigModel.send :include, Ixtlan::Core::Configuration::Module
|
32
33
|
end
|
33
34
|
|
34
35
|
it "should register listeners and fire change events" do
|
35
36
|
count = 0
|
36
|
-
|
37
|
+
clazz = nil
|
38
|
+
subject.register("counter") do |c|
|
37
39
|
count += 1
|
40
|
+
clazz = c.class
|
38
41
|
end
|
39
|
-
|
42
|
+
subject.setup(:config_model)
|
43
|
+
subject.configure
|
40
44
|
count.should == 1
|
45
|
+
clazz.should == ConfigModel
|
41
46
|
end
|
42
47
|
|
43
48
|
it "should use instance method only once per thread" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ixtlan-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.7.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- mkristian
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-04 00:00:00 +05:30
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|