ixtlan-core 0.1.0 → 0.1.1

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.
@@ -1,12 +1,12 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Schedules</title>
4
+ <title><%= app_const_base %></title>
5
5
  <%%= stylesheet_link_tag :all %>
6
6
  <%%= javascript_include_tag :defaults %>
7
7
  <%%= csrf_meta_tag %>
8
8
  <%% if controller.respond_to?(:current_user) && controller.send(:current_user) != nil %>
9
- <meta "http-equiv"="refresh" content="#{Configuration.instance.idle_session_timeout * 60}" />
9
+ <meta "http-equiv"="refresh" content="#{controller.session_idle_timeout * 60 + 5}" />
10
10
  <%% end %>
11
11
  </head>
12
12
  <body>
@@ -22,8 +22,8 @@
22
22
 
23
23
  # idle session timeout configuration (in minutes)
24
24
  # -----------------------------------------------
25
- # config_instance.register("idle_session_timeout") do |config|
26
- # Rails.configuration.idle_session_timeout = config.idle_session_timeout
25
+ # config_instance.register("session_idle_timeout") do |config|
26
+ # Rails.configuration.session_idle_timeout = config.session_idle_timeout
27
27
  # end
28
28
 
29
29
  # audit log manager
@@ -54,7 +54,7 @@
54
54
 
55
55
  # idle session timeout configuration
56
56
  # ----------------------------------
57
- # config.idle_session_timeout = 30 #minutes
57
+ # config.session_idle_timeout = 30 #minutes
58
58
 
59
59
  # audit log manager
60
60
  # -----------------
@@ -42,13 +42,16 @@ module Ixtlan
42
42
 
43
43
  def cache_headers
44
44
  if(respond_to?(:current_user) && current_user)
45
- case self.class.instance_variable_get(:@mode)
45
+ mode = self.class.instance_variable_get(:@mode)
46
+ case mode
46
47
  when :private
47
48
  no_caching(self.class.instance_variable_get(:@no_store))
48
49
  when :protected
49
50
  only_browser_can_cache(self.class.instance_variable_get(:@no_store))
50
51
  when :public
51
52
  allow_browser_and_proxy_to_cache(self.class.instance_variable_get(:@no_store))
53
+ else
54
+ send mode if mode
52
55
  end
53
56
  # else
54
57
  # allow_browser_and_proxy_to_cache(self.class.instance_variable_get(:@no_store))
@@ -59,8 +62,7 @@ module Ixtlan
59
62
  base.class_eval do
60
63
  def self.cache_headers(mode = nil, no_store = true)
61
64
  if(mode)
62
- raise "supported modi are :private, :protected and :public" unless [:private, :protected, :public].member? mode.to_sym
63
- @mode = mode
65
+ @mode = mode.to_sym
64
66
  end
65
67
  @no_store = no_store
66
68
  end
@@ -13,9 +13,14 @@ module Ixtlan
13
13
  Thread.current[:ixtlan_configuration] ||= instance_old
14
14
  end
15
15
  def clear_instance
16
- Thread.current[:ixtlan_configruation] = nil
16
+ Thread.current[:ixtlan_configuration] = nil
17
17
  end
18
18
  end
19
+
20
+ private
21
+ def self.registry
22
+ @registry ||= {}
23
+ end
19
24
  end
20
25
  end
21
26
 
@@ -27,7 +32,7 @@ module Ixtlan
27
32
 
28
33
  def fire_on_change
29
34
  registry.each do |name, callback|
30
- logger.debug{ "call #{name}" }
35
+ logger.debug{ "configure #{name}" }
31
36
  callback.call(self)
32
37
  end
33
38
  end
@@ -35,9 +40,8 @@ module Ixtlan
35
40
  private
36
41
 
37
42
  def registry
38
- @registry ||= {}
43
+ self.class.registry
39
44
  end
40
-
41
45
  end
42
46
  end
43
47
  end
@@ -31,7 +31,7 @@ module Ixtlan
31
31
  ActiveRecord::Generators::ModelGenerator.class_option :singleton, :type => :boolean, :default => false
32
32
  end
33
33
 
34
- config.before_configuration do |app|
34
+ config.before_initialize do |app|
35
35
  app.config.class.class_eval do
36
36
  attr_accessor :configuration_model
37
37
  def configuration_model=(clazz)
@@ -0,0 +1,54 @@
1
+ require 'ixtlan/core/configuration_manager'
2
+ require 'slf4r/ruby_logger'
3
+
4
+ class ConfigModel
5
+
6
+ def self.instance
7
+ @called = called + 1
8
+ @instance ||= self.new
9
+ end
10
+
11
+ def self.after_save(method)
12
+ @method = method.to_sym
13
+ end
14
+
15
+ def self.save_method
16
+ @method
17
+ end
18
+
19
+ def self.called
20
+ @called ||= 0
21
+ end
22
+
23
+ def save
24
+ send self.class.save_method if self.class.save_method
25
+ end
26
+ end
27
+
28
+ describe Ixtlan::Core::ConfigurationManager do
29
+
30
+ before :all do
31
+ ConfigModel.send :include, Ixtlan::Core::ConfigurationManager
32
+ end
33
+
34
+ it "should register listeners and fire change events" do
35
+ count = 0
36
+ ConfigModel.instance.register("counter") do
37
+ count += 1
38
+ end
39
+ ConfigModel.instance.save
40
+ count.should == 1
41
+ end
42
+
43
+ it "should use instance method only once per thread" do
44
+ base = ConfigModel.called > 0 ? ConfigModel.called : 1
45
+ ConfigModel.instance
46
+ ConfigModel.called.should == base
47
+ ConfigModel.instance
48
+ ConfigModel.called.should == base
49
+ ConfigModel.clear_instance # clear thread local variable
50
+ ConfigModel.instance
51
+ ConfigModel.called.should == 1 + base
52
+ end
53
+
54
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - mkristian
@@ -14,41 +14,55 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-01 00:00:00 +05:30
17
+ date: 2011-03-22 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rails
21
+ name: slf4r
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 4
30
+ - 2
31
+ version: 0.4.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rails
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - "="
26
40
  - !ruby/object:Gem::Version
27
41
  segments:
28
42
  - 3
29
43
  - 0
30
- - 1
31
- version: 3.0.1
44
+ - 5
45
+ version: 3.0.5
32
46
  type: :development
33
- version_requirements: *id001
47
+ version_requirements: *id002
34
48
  - !ruby/object:Gem::Dependency
35
49
  name: rspec
36
50
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
51
+ requirement: &id003 !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "="
40
54
  - !ruby/object:Gem::Version
41
55
  segments:
42
56
  - 2
57
+ - 4
43
58
  - 0
44
- - 1
45
- version: 2.0.1
59
+ version: 2.4.0
46
60
  type: :development
47
- version_requirements: *id002
61
+ version_requirements: *id003
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: cucumber
50
64
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
65
+ requirement: &id004 !ruby/object:Gem::Requirement
52
66
  requirements:
53
67
  - - "="
54
68
  - !ruby/object:Gem::Version
@@ -58,21 +72,24 @@ dependencies:
58
72
  - 4
59
73
  version: 0.9.4
60
74
  type: :development
61
- version_requirements: *id003
75
+ version_requirements: *id004
62
76
  - !ruby/object:Gem::Dependency
63
- name: rake
77
+ name: ruby-maven
64
78
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
79
+ requirement: &id005 !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - "="
68
82
  - !ruby/object:Gem::Version
69
83
  segments:
70
84
  - 0
71
85
  - 8
72
- - 7
73
- version: 0.8.7
86
+ - 3
87
+ - 0
88
+ - 2
89
+ - 1
90
+ version: 0.8.3.0.2.1
74
91
  type: :development
75
- version_requirements: *id004
92
+ version_requirements: *id005
76
93
  description: base for some gems related to protect privacy and increase security along some other utils
77
94
  email:
78
95
  - m.kristian@web.de
@@ -83,9 +100,6 @@ extensions: []
83
100
  extra_rdoc_files: []
84
101
 
85
102
  files:
86
- - README.textile
87
- - features/step_definitions/simple_steps.rb
88
- - features/generators.feature
89
103
  - lib/ixtlan-core.rb
90
104
  - lib/generators/model/model_generator.rb
91
105
  - lib/generators/scaffold/scaffold_generator.rb
@@ -117,10 +131,11 @@ files:
117
131
  - lib/ixtlan/core/cache_headers.rb
118
132
  - lib/ixtlan/core/configuration_rack.rb
119
133
  - lib/ixtlan/core/controllers/configuration_controller.rb
134
+ - spec/configuration_manager_spec.rb
120
135
  has_rdoc: true
121
136
  homepage: http://github.com/mkristian/ixtlan-core
122
- licenses: []
123
-
137
+ licenses:
138
+ - MIT-LICENSE
124
139
  post_install_message:
125
140
  rdoc_options:
126
141
  - --main
@@ -148,5 +163,5 @@ rubygems_version: 1.3.6
148
163
  signing_key:
149
164
  specification_version: 3
150
165
  summary: cache header control, dynamic configuration, and rails generator templates
151
- test_files: []
152
-
166
+ test_files:
167
+ - spec/configuration_manager_spec.rb
data/README.textile DELETED
@@ -1,31 +0,0 @@
1
- h1. Ixtlan
2
-
3
- p. this project is just a compilation of things I am doing all over the place in my projects. there is a focus on privacy protection which needs a strong security in the first place.
4
-
5
- p. this gem is quite invasive in terms of default templates of rails3. first it adds json serializers and looks for a lot of switches from other gems like 'ixtlan-audit', 'ixtlan-session-timeout', 'ixtlan-error-handler', 'rails-resty-generators', etc
6
-
7
- h2. setup generator
8
-
9
- p. this just adds an preinitializer to the rails application which allows to keep the config/database.yml almost as is and allows to put the passwords for the production database into a 'production.yml' - just ignore that production.yml from git and keep it only on the deployed server. same you can do for an external mail provider.
10
-
11
- p. further if you can configure a configuration (singleton) model which allows to register components which can notified when a configuration changes.
12
-
13
- p. since the model generator also needs to work nice with rails-resty-generators it add beside the "reference/belongs_to" also a "has_one" and "has_many" types. this allows to generate the ruby models along with java GWT models in a similar manner (note: restrictions and short comings are there . . .).
14
-
15
- h2. cache headers
16
-
17
- p. that is the only "real" feature of the ixtlan-core gem. with this you can control the cache header with three predefined modi:
18
-
19
- * private: no caching of data for any proxy or browser
20
-
21
- * protected: only browser can cache
22
-
23
- * public: proxies and browsers can cache as desired
24
-
25
- of any sensitive data go for the private mode.
26
-
27
- p. this control is only active when there is logged in user, i.e. controller.current_user != null. also when the controller does not set the cache-header the rails default is used.
28
-
29
- h3. credits
30
-
31
- p. the cache header uses http://code.google.com/p/doctype/wiki/ArticleHttpCaching as specification
@@ -1,5 +0,0 @@
1
- Feature: Generators for Ixtlan Audit
2
-
3
- Scenario: The slf4r rails template creates a rails application which uses slf4r-wrapper
4
- Given I create new rails application with template "simple.template"
5
- Then the output should contain "setup slf4r logger wrapper with ActiveSupport::BufferedLogger"
@@ -1,22 +0,0 @@
1
- require 'fileutils'
2
- Given /^I create new rails application with template "(.*)"$/ do |template|
3
- name = template.sub(/.template$/, '')
4
- directory = File.join('target', name)
5
- rails_version = ENV['RAILS_VERSION'] || '3.0.1'
6
-
7
- ruby = defined?(JRUBY_VERSION) ? "jruby" : "ruby"
8
- rails_command = "#{ENV['GEM_HOME']}/bin/rails"
9
- rails_command = "-S rails" unless File.exists?(rails_command)
10
- command = "#{rails_command} _#{rails_version}_ new #{directory} -f -m templates/#{template}"
11
- FileUtils.rm_rf(directory)
12
-
13
- system "#{ruby} #{command}"
14
-
15
- @result = File.read("target/#{name}/log/development.log")
16
- puts @result
17
- end
18
-
19
- Then /^the output should contain \"(.*)\"$/ do |expected|
20
- (@result =~ /.*#{expected}.*/).should_not be_nil
21
- end
22
-