apache-config-generator 0.2.6 → 0.2.7

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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apache-config-generator (0.2.6)
4
+ apache-config-generator (0.2.7)
5
5
  rainbow
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  autotest (4.4.2)
11
11
  diff-lcs (1.1.2)
12
- mocha (0.9.9)
12
+ mocha (0.9.10)
13
13
  rake
14
14
  nokogiri (1.4.3.1)
15
15
  rainbow (1.1)
@@ -2,6 +2,8 @@
2
2
 
3
3
  Programmatically construct your Apache configuration using a powerful DSL built in Ruby.
4
4
 
5
+ As of version 0.2.7, your destination config directory is destroyed and re-created each time the apache:create Rake task is run.
6
+
5
7
  == Installation
6
8
 
7
9
  <tt>gem install apache-config-generator</tt>
@@ -92,6 +94,8 @@ The above config is transformed into the following:
92
94
  RewriteCond "%{HTTP_REFERER}" "^!my-cool-website\.cool\.wow"
93
95
  RewriteRule "\.(gif|jpg|png|pdf)$" "/lol-image-stealer.html" [L,R]
94
96
 
97
+ The destination configs directory is destroyed and re-created each time the apache:create Rake task is run.
98
+
95
99
  == Using Apache::Config separately
96
100
 
97
101
  Include the gem and access the methods on Apache::Config directly. See test/example_standalone.rb
data/Rakefile CHANGED
@@ -20,3 +20,9 @@ end
20
20
  task :reek do
21
21
  system('reek -c config/config.reek lib/*')
22
22
  end
23
+
24
+ task :gem do
25
+ system %{rm *.gem}
26
+ system %{gem build apache-config-generator.gemspec}
27
+ system %{gem install apache-config-generator-*.gem}
28
+ end
@@ -1 +1,6 @@
1
1
  Autotest.add_discovery { "rspec2" }
2
+
3
+ Autotest.add_hook(:initialize) do |at|
4
+ at.add_exception(%r{^./test/.*})
5
+ end
6
+
@@ -1,17 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'fileutils'
4
+ require 'rubygems'
5
+ require 'rainbow'
4
6
 
5
7
  if !ARGV[0]
6
- puts "Directory name required."
8
+ puts "Directory name required.".foreground(:red)
7
9
  exit 1
8
10
  end
9
11
 
10
12
  if File.directory?(ARGV[0])
11
- puts "You can't overwrite an existing directory."
13
+ puts "You can't overwrite an existing directory.".foreground(:red)
12
14
  exit 1
13
15
  end
14
16
 
17
+ puts "Copying skel files...".foreground(:green)
15
18
  FileUtils.cp_r File.expand_path(File.join(File.dirname(__FILE__), '..', 'skel')), ARGV[0]
19
+
20
+ puts "Making config directories...".foreground(:green)
16
21
  FileUtils.mkdir_p File.join(ARGV[0], 'source')
22
+ FileUtils.mkdir_p File.join(ARGV[0], 'conf.d-original')
17
23
  FileUtils.mkdir_p File.join(ARGV[0], 'conf.d')
24
+
25
+ print "Complete! ".bright.foreground(:green)
26
+ print "cd #{ARGV[0]}".bright.foreground(:yellow)
27
+ print " and run ".foreground(:green)
28
+ print "bundle exec rake -T ".bright.foreground(:yellow)
29
+ puts "to get started.".foreground(:green)
@@ -92,16 +92,38 @@ module Apache
92
92
  def build(target, &block)
93
93
  config = build_and_return(&block)
94
94
 
95
- FileUtils.mkdir_p File.split(target).first
96
- File.open(target, 'w') { |file| file.puts [ "# Generated by apache-config-generator #{Time.now.to_s}", config ].flatten * "\n" }
95
+ if !disabled?
96
+ FileUtils.mkdir_p File.split(target).first
97
+ File.open(target, 'w') { |file| file.puts generate_config_file(config) * "\n" }
98
+ @was_written = true
99
+ end
97
100
 
98
101
  config
99
102
  end
100
103
 
104
+ # If included in a configuration, will not generate the config file in the Rake task
105
+ def disable!
106
+ @is_disabled = true
107
+ end
108
+
109
+ def disabled?
110
+ @is_disabled
111
+ end
112
+
113
+ def written?
114
+ @was_written
115
+ end
116
+
117
+ def generate_config_file(config)
118
+ [ "# Generated by apache-config-generator #{Time.now.to_s}", config ].flatten
119
+ end
120
+
101
121
  # Reset the current settings
102
122
  def reset!
103
123
  @config = []
104
124
  @line_indent = 0
125
+ @is_disabled = false
126
+ @was_written = false
105
127
  end
106
128
 
107
129
  # Indent the string by the current @line_indent level
@@ -0,0 +1,8 @@
1
+ class Hash
2
+ def to_sym_keys
3
+ Hash[self.collect { |key, value|
4
+ value = value.to_sym_keys if value.kind_of?(Hash)
5
+ [ key.to_sym, value ]
6
+ }]
7
+ end
8
+ end
@@ -5,6 +5,15 @@ include Apache::Rake::Support
5
5
 
6
6
  task :default => 'apache:create'
7
7
 
8
+ def capture_stdout
9
+ buffer = StringIO.new
10
+ $stdout = buffer
11
+ yield
12
+ $stdout = STDOUT
13
+ buffer.rewind
14
+ buffer.read
15
+ end
16
+
8
17
  namespace :apache do
9
18
  desc "Create all defined configs for the specified environment"
10
19
  task :create, :environment do |t, args|
@@ -16,20 +25,28 @@ namespace :apache do
16
25
  APACHE_ENV = (args[:environment] || get_default_environment).to_sym
17
26
  end
18
27
 
19
- config[:source_path] = File.expand_path(config[:source])
20
- config[:dest_path] = File.expand_path(config[:destination])
21
-
22
28
  Apache::Config.rotate_logs_path = config[:rotate_logs_path]
23
29
 
24
- FileUtils.mkdir_p config[:dest_path]
25
- Dir.chdir config[:dest_path]
30
+ FileUtils.rm_rf config[:destination_path]
31
+ FileUtils.mkdir_p config[:destination_path]
32
+ Dir.chdir config[:destination_path]
26
33
 
27
- # using CONFIG is deprecated
28
34
  CONFIG = config
29
35
 
36
+ ENVIRONMENT_CONFIG = (config[:environments][APACHE_ENV] rescue nil)
37
+
30
38
  Dir[File.join(config[:source_path], '**', '*.rb')].each do |file|
31
- puts file.foreground(:green)
32
- require file
39
+ Apache::Config.reset!
40
+ output = capture_stdout { require file }
41
+
42
+ if Apache::Config.written?
43
+ if Apache::Config.disabled?
44
+ puts file.foreground(:blue)
45
+ else
46
+ puts file.foreground(:green)
47
+ end
48
+ puts output
49
+ end
33
50
  end
34
51
  end
35
52
 
@@ -1,16 +1,44 @@
1
1
  require 'yaml'
2
2
  require 'fileutils'
3
+ require 'apache/hash'
3
4
 
4
5
  module Apache
5
6
  module Rake
6
7
  module Support
7
8
  def config
8
- @config ||= Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
9
+ if !@config
10
+ @config = YAML.load_file('config.yml').to_sym_keys
11
+ config_paths!
12
+
13
+ class << @config
14
+ def [](which)
15
+ if which == :dest_path
16
+ print "config[:dest_path] is deprecated.".foreground(:red).bright
17
+ puts " Use config[:destination_path] instead.".foreground(:red)
18
+
19
+ self[:destination_path]
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ @config
9
28
  end
10
29
 
11
- def get_environments
12
- config[:source_path] = File.expand_path(config[:source])
30
+ def config_paths!
31
+ [ :source, :destination ].each do |which|
32
+ begin
33
+ @config[:"#{which}_path"] = File.expand_path(@config[which])
34
+ rescue StandardError
35
+ puts "#{which.to_s.bright} is not defined in the configuration file.".foreground(:red)
36
+ exit 1
37
+ end
38
+ end
39
+ end
13
40
 
41
+ def get_environments
14
42
  Dir[File.join(config[:source_path], '**', '*.rb')].collect { |file|
15
43
  File.readlines(file).find_all { |line| line[%r{(if_environment|build_if)}] }.collect { |line| line.scan(%r{:[a-z_]+}) }
16
44
  }.flatten.uniq.sort.collect { |name| name[1..-1] }
@@ -1,3 +1,3 @@
1
1
  module Apache
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -1,2 +1,5 @@
1
1
  source :rubygems
2
- gem 'apache-config-generator'
2
+
3
+ gem 'apache-config-generator', '>= 0.2.7'
4
+ gem 'rake'
5
+
@@ -1,3 +1 @@
1
- require 'rubygems'
2
-
3
- require 'apache/rake/create'
1
+ require 'apache/rake/apache/create'
@@ -33,6 +33,40 @@ describe Apache::Config, "builds configurations" do
33
33
  end
34
34
  end
35
35
 
36
+ describe '.disable!' do
37
+ context 'is enabled by default' do
38
+ it { apache.instance_variable_get(:@is_disabled).should be_false }
39
+ it { apache.disabled?.should be_false }
40
+
41
+ context 'writes config' do
42
+ before {
43
+ FileUtils.expects(:mkdir_p).once
44
+ File.expects(:open).once
45
+ apache.build("here") { cats }
46
+ }
47
+
48
+ it { apache.written?.should == true }
49
+ end
50
+ end
51
+
52
+ context 'disable' do
53
+ before { apache.disable! }
54
+
55
+ it { apache.instance_variable_get(:@is_disabled).should be_true }
56
+ it { apache.disabled?.should be_true }
57
+
58
+ context 'does not write config' do
59
+ before {
60
+ FileUtils.expects(:mkdir_p).never
61
+ File.expects(:open).never
62
+ apache.build("here") { disable!; cats }
63
+ }
64
+
65
+ it { apache.written?.should == false }
66
+ end
67
+ end
68
+ end
69
+
36
70
  it "should handle indent" do
37
71
  apache.line_indent = 1
38
72
 
@@ -84,9 +118,13 @@ describe Apache::Config, "builds configurations" do
84
118
  end
85
119
 
86
120
  it "should handle a build" do
121
+ apache.written?.should be_false
122
+
87
123
  FileUtils.mkdir_p 'test'
88
124
  apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
89
125
  FileUtils.rm 'test/fake.conf'
126
+
127
+ apache.written?.should be_true
90
128
  end
91
129
 
92
130
  it "should handle building if the environment is correct" do
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'lib/apache/hash'
3
+
4
+ describe Hash do
5
+ describe '#to_sym_keys' do
6
+ subject { test_hash.to_sym_keys }
7
+
8
+ context 'no nested hashes' do
9
+ let(:test_hash) { {
10
+ 'hello' => 'goodbye',
11
+ :other => 'this'
12
+ } }
13
+
14
+ it { should == {
15
+ :hello => 'goodbye',
16
+ :other => 'this'
17
+ } }
18
+ end
19
+
20
+ context 'nested hash' do
21
+ let(:test_hash) { {
22
+ 'hello' => 'goodbye',
23
+ :other => {
24
+ 'this' => 'that'
25
+ }
26
+ } }
27
+
28
+ it { should == {
29
+ :hello => 'goodbye',
30
+ :other => {
31
+ :this => 'that'
32
+ }
33
+ } }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'apache/rake/support'
3
+
4
+ describe Apache::Rake::Support do
5
+ include Apache::Rake::Support
6
+
7
+ let(:source) { '/source' }
8
+ let(:destination) { '/destination/available' }
9
+
10
+ describe 'config_paths!' do
11
+ before {
12
+ @config = {
13
+ :source => 'cats',
14
+ :destination => 'dogs'
15
+ }
16
+ }
17
+
18
+ subject { config_paths!; @config }
19
+
20
+ its([:source_path]) { should == File.expand_path('cats') }
21
+ its([:destination_path]) { should == File.expand_path('dogs') }
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ Rspec.configure do |config|
2
+ config.mock_with :mocha
3
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apache-config-generator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Bintz
@@ -15,13 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-29 00:00:00 -05:00
18
+ date: 2011-01-06 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: bundler
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ">="
@@ -32,12 +30,12 @@ dependencies:
32
30
  - 0
33
31
  - 0
34
32
  version: 1.0.0
33
+ requirement: *id001
34
+ name: bundler
35
+ prerelease: false
35
36
  type: :development
36
- version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: rspec
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ~>
@@ -48,12 +46,12 @@ dependencies:
48
46
  - 0
49
47
  - 0
50
48
  version: 2.0.0
49
+ requirement: *id002
50
+ name: rspec
51
+ prerelease: false
51
52
  type: :development
52
- version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: nokogiri
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
55
  none: false
58
56
  requirements:
59
57
  - - ">="
@@ -62,12 +60,12 @@ dependencies:
62
60
  segments:
63
61
  - 0
64
62
  version: "0"
63
+ requirement: *id003
64
+ name: nokogiri
65
+ prerelease: false
65
66
  type: :development
66
- version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
68
- name: mocha
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
69
  none: false
72
70
  requirements:
73
71
  - - ">="
@@ -76,12 +74,12 @@ dependencies:
76
74
  segments:
77
75
  - 0
78
76
  version: "0"
77
+ requirement: *id004
78
+ name: mocha
79
+ prerelease: false
79
80
  type: :development
80
- version_requirements: *id004
81
81
  - !ruby/object:Gem::Dependency
82
- name: autotest
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
85
83
  none: false
86
84
  requirements:
87
85
  - - ">="
@@ -90,12 +88,12 @@ dependencies:
90
88
  segments:
91
89
  - 0
92
90
  version: "0"
91
+ requirement: *id005
92
+ name: autotest
93
+ prerelease: false
93
94
  type: :development
94
- version_requirements: *id005
95
95
  - !ruby/object:Gem::Dependency
96
- name: reek
97
- prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
99
97
  none: false
100
98
  requirements:
101
99
  - - ">="
@@ -104,12 +102,12 @@ dependencies:
104
102
  segments:
105
103
  - 0
106
104
  version: "0"
105
+ requirement: *id006
106
+ name: reek
107
+ prerelease: false
107
108
  type: :development
108
- version_requirements: *id006
109
109
  - !ruby/object:Gem::Dependency
110
- name: rainbow
111
- prerelease: false
112
- requirement: &id007 !ruby/object:Gem::Requirement
110
+ version_requirements: &id007 !ruby/object:Gem::Requirement
113
111
  none: false
114
112
  requirements:
115
113
  - - ">="
@@ -118,8 +116,10 @@ dependencies:
118
116
  segments:
119
117
  - 0
120
118
  version: "0"
119
+ requirement: *id007
120
+ name: rainbow
121
+ prerelease: false
121
122
  type: :runtime
122
- version_requirements: *id007
123
123
  description: A Ruby DSL for programmatically generating Apache configs
124
124
  email: john@coswellproductions.com
125
125
  executables:
@@ -142,6 +142,7 @@ files:
142
142
  - lib/apache/apachify.rb
143
143
  - lib/apache/config.rb
144
144
  - lib/apache/directory.rb
145
+ - lib/apache/hash.rb
145
146
  - lib/apache/logging.rb
146
147
  - lib/apache/master.rb
147
148
  - lib/apache/modules.rb
@@ -160,12 +161,14 @@ files:
160
161
  - spec/apache/apachify_spec.rb
161
162
  - spec/apache/config_spec.rb
162
163
  - spec/apache/directory_spec.rb
164
+ - spec/apache/hash_spec.rb
163
165
  - spec/apache/logging_spec.rb
164
166
  - spec/apache/master_spec.rb
165
167
  - spec/apache/modules_spec.rb
166
168
  - spec/apache/mpm_prefork_spec.rb
167
169
  - spec/apache/performance_spec.rb
168
170
  - spec/apache/permissions_spec.rb
171
+ - spec/apache/rake/support_spec.rb
169
172
  - spec/apache/rewrites_spec.rb
170
173
  - spec/spec_helper.rb
171
174
  - test/config/httpd.rb