amberbit-config 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +59 -0
- data/Rakefile +36 -0
- data/VERSION +1 -0
- data/amberbit-config.gemspec +120 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/amber_bit_app_config.rb +74 -0
- data/lib/amberbit-config.rb +3 -0
- data/lib/hash_struct.rb +9 -0
- data/spec/library_spec.rb +20 -0
- data/spec/plugin_spec.rb +31 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/testapp/README +243 -0
- data/spec/testapp/Rakefile +11 -0
- data/spec/testapp/app/controllers/application_controller.rb +10 -0
- data/spec/testapp/app/helpers/application_helper.rb +3 -0
- data/spec/testapp/config/application/config.yml +8 -0
- data/spec/testapp/config/application/default.yml +6 -0
- data/spec/testapp/config/boot.rb +110 -0
- data/spec/testapp/config/environment.rb +14 -0
- data/spec/testapp/config/environments/development.rb +17 -0
- data/spec/testapp/config/environments/production.rb +28 -0
- data/spec/testapp/config/environments/test.rb +28 -0
- data/spec/testapp/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/testapp/config/initializers/inflections.rb +10 -0
- data/spec/testapp/config/initializers/mime_types.rb +5 -0
- data/spec/testapp/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/testapp/config/initializers/session_store.rb +15 -0
- data/spec/testapp/config/locales/en.yml +5 -0
- data/spec/testapp/config/routes.rb +43 -0
- data/spec/testapp/db/test.sqlite3 +0 -0
- data/spec/testapp/doc/README_FOR_APP +2 -0
- data/spec/testapp/log/development.log +0 -0
- data/spec/testapp/log/production.log +0 -0
- data/spec/testapp/log/server.log +0 -0
- data/spec/testapp/log/test.log +0 -0
- data/spec/testapp/public/404.html +30 -0
- data/spec/testapp/public/422.html +30 -0
- data/spec/testapp/public/500.html +30 -0
- data/spec/testapp/public/favicon.ico +0 -0
- data/spec/testapp/public/images/rails.png +0 -0
- data/spec/testapp/public/index.html +275 -0
- data/spec/testapp/public/javascripts/application.js +2 -0
- data/spec/testapp/public/javascripts/controls.js +963 -0
- data/spec/testapp/public/javascripts/dragdrop.js +973 -0
- data/spec/testapp/public/javascripts/effects.js +1128 -0
- data/spec/testapp/public/javascripts/prototype.js +4320 -0
- data/spec/testapp/public/robots.txt +5 -0
- data/spec/testapp/script/about +4 -0
- data/spec/testapp/script/console +3 -0
- data/spec/testapp/script/dbconsole +3 -0
- data/spec/testapp/script/destroy +3 -0
- data/spec/testapp/script/generate +3 -0
- data/spec/testapp/script/performance/benchmarker +3 -0
- data/spec/testapp/script/performance/profiler +3 -0
- data/spec/testapp/script/plugin +3 -0
- data/spec/testapp/script/runner +3 -0
- data/spec/testapp/script/server +3 -0
- data/spec/testapp/test/performance/browsing_test.rb +9 -0
- data/spec/testapp/test/test_helper.rb +38 -0
- data/tasks/amberbit_app_config_tasks.rake +79 -0
- data/uninstall.rb +1 -0
- metadata +148 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Amberbit Config
|
2
|
+
===============
|
3
|
+
|
4
|
+
Provides simple global configuration for Ruby on Rails application using YAML files.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
============
|
8
|
+
|
9
|
+
$ ./script/plugin install git://github.com/amberbit/amberbit-config.git
|
10
|
+
$ rake amberbit:config:setup
|
11
|
+
|
12
|
+
Usage
|
13
|
+
=====
|
14
|
+
|
15
|
+
Place your application configuration default values into #{RAILS_ROOT}/config/application/default.yml:
|
16
|
+
|
17
|
+
default:
|
18
|
+
application:
|
19
|
+
name: SuperApp
|
20
|
+
url: http://localhost:3000/
|
21
|
+
|
22
|
+
test:
|
23
|
+
# overwrite application.url key only in test env
|
24
|
+
application:
|
25
|
+
url: http://testhost:3000/
|
26
|
+
|
27
|
+
And overwrite values you wish on per-installation basis in #{RAILS_ROOT}/config/application/config.yml:
|
28
|
+
|
29
|
+
default:
|
30
|
+
application:
|
31
|
+
name: SuperApp specially for you
|
32
|
+
|
33
|
+
production:
|
34
|
+
application:
|
35
|
+
url: http://yoursuperhiperdomain.com
|
36
|
+
|
37
|
+
In your application Ruby code you can access the values in 2 following ways:
|
38
|
+
|
39
|
+
AppConfig['application']['name'] #=> SuperApp specially for you
|
40
|
+
|
41
|
+
or
|
42
|
+
|
43
|
+
AppConfig.application.name #=> SuperApp specially for you
|
44
|
+
|
45
|
+
Keys are deep-merged, for example:
|
46
|
+
production env:
|
47
|
+
|
48
|
+
AppConfig.application.name #=> SuperApp specially for you
|
49
|
+
AppConfig.application.url #=> http://yoursuperhiperdomain.com
|
50
|
+
|
51
|
+
development env:
|
52
|
+
|
53
|
+
AppConfig.application.name #=> SuperApp specially for you
|
54
|
+
AppConfig.application.url #=> http://localhost:3000/
|
55
|
+
|
56
|
+
|
57
|
+
Copyright (c) 2008/2009 Wojciech Piekutowski, released under the MIT license
|
58
|
+
Copyright (c) 2009 Hubert Łępicki, released under the MIT license
|
59
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
desc 'Default: run Specs.'
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
|
9
|
+
desc 'Run specs on the plugin.'
|
10
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the amberbit_app_config plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'AmberbitAppConfig'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'jeweler'
|
26
|
+
Jeweler::Tasks.new do |gemspec|
|
27
|
+
gemspec.name = "amberbit-config"
|
28
|
+
gemspec.summary = "Yet Another AppConfig for Rails but not only"
|
29
|
+
gemspec.description = "Reads YAML files with configuration. Allows you to specify default configuration file you can store in repository and overwrite it with custom configuration file for each application instance and environment."
|
30
|
+
gemspec.email = "hubert.lepicki@amberbit.com"
|
31
|
+
gemspec.homepage = "http://github.com/amberbit/amberbit-config"
|
32
|
+
gemspec.authors = ["Wojciech Piekutowski", "Hubert Lepicki"]
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
36
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{amberbit-config}
|
8
|
+
s.version = "1.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Wojciech Piekutowski", "Hubert Lepicki"]
|
12
|
+
s.date = %q{2010-08-22}
|
13
|
+
s.description = %q{Reads YAML files with configuration. Allows you to specify default configuration file you can store in repository and overwrite it with custom configuration file for each application instance and environment.}
|
14
|
+
s.email = %q{hubert.lepicki@amberbit.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"amberbit-config.gemspec",
|
24
|
+
"init.rb",
|
25
|
+
"install.rb",
|
26
|
+
"lib/amber_bit_app_config.rb",
|
27
|
+
"lib/amberbit-config.rb",
|
28
|
+
"lib/hash_struct.rb",
|
29
|
+
"spec/library_spec.rb",
|
30
|
+
"spec/plugin_spec.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"spec/testapp/README",
|
34
|
+
"spec/testapp/Rakefile",
|
35
|
+
"spec/testapp/app/controllers/application_controller.rb",
|
36
|
+
"spec/testapp/app/helpers/application_helper.rb",
|
37
|
+
"spec/testapp/config/application/config.yml",
|
38
|
+
"spec/testapp/config/application/default.yml",
|
39
|
+
"spec/testapp/config/boot.rb",
|
40
|
+
"spec/testapp/config/environment.rb",
|
41
|
+
"spec/testapp/config/environments/development.rb",
|
42
|
+
"spec/testapp/config/environments/production.rb",
|
43
|
+
"spec/testapp/config/environments/test.rb",
|
44
|
+
"spec/testapp/config/initializers/backtrace_silencers.rb",
|
45
|
+
"spec/testapp/config/initializers/inflections.rb",
|
46
|
+
"spec/testapp/config/initializers/mime_types.rb",
|
47
|
+
"spec/testapp/config/initializers/new_rails_defaults.rb",
|
48
|
+
"spec/testapp/config/initializers/session_store.rb",
|
49
|
+
"spec/testapp/config/locales/en.yml",
|
50
|
+
"spec/testapp/config/routes.rb",
|
51
|
+
"spec/testapp/db/test.sqlite3",
|
52
|
+
"spec/testapp/doc/README_FOR_APP",
|
53
|
+
"spec/testapp/log/development.log",
|
54
|
+
"spec/testapp/log/production.log",
|
55
|
+
"spec/testapp/log/server.log",
|
56
|
+
"spec/testapp/log/test.log",
|
57
|
+
"spec/testapp/public/404.html",
|
58
|
+
"spec/testapp/public/422.html",
|
59
|
+
"spec/testapp/public/500.html",
|
60
|
+
"spec/testapp/public/favicon.ico",
|
61
|
+
"spec/testapp/public/images/rails.png",
|
62
|
+
"spec/testapp/public/index.html",
|
63
|
+
"spec/testapp/public/javascripts/application.js",
|
64
|
+
"spec/testapp/public/javascripts/controls.js",
|
65
|
+
"spec/testapp/public/javascripts/dragdrop.js",
|
66
|
+
"spec/testapp/public/javascripts/effects.js",
|
67
|
+
"spec/testapp/public/javascripts/prototype.js",
|
68
|
+
"spec/testapp/public/robots.txt",
|
69
|
+
"spec/testapp/script/about",
|
70
|
+
"spec/testapp/script/console",
|
71
|
+
"spec/testapp/script/dbconsole",
|
72
|
+
"spec/testapp/script/destroy",
|
73
|
+
"spec/testapp/script/generate",
|
74
|
+
"spec/testapp/script/performance/benchmarker",
|
75
|
+
"spec/testapp/script/performance/profiler",
|
76
|
+
"spec/testapp/script/plugin",
|
77
|
+
"spec/testapp/script/runner",
|
78
|
+
"spec/testapp/script/server",
|
79
|
+
"spec/testapp/test/performance/browsing_test.rb",
|
80
|
+
"spec/testapp/test/test_helper.rb",
|
81
|
+
"tasks/amberbit_app_config_tasks.rake",
|
82
|
+
"uninstall.rb"
|
83
|
+
]
|
84
|
+
s.homepage = %q{http://github.com/amberbit/amberbit-config}
|
85
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
86
|
+
s.require_paths = ["lib"]
|
87
|
+
s.rubygems_version = %q{1.3.7}
|
88
|
+
s.summary = %q{Yet Another AppConfig for Rails but not only}
|
89
|
+
s.test_files = [
|
90
|
+
"spec/testapp/config/boot.rb",
|
91
|
+
"spec/testapp/config/environment.rb",
|
92
|
+
"spec/testapp/config/environments/development.rb",
|
93
|
+
"spec/testapp/config/environments/production.rb",
|
94
|
+
"spec/testapp/config/environments/test.rb",
|
95
|
+
"spec/testapp/config/initializers/backtrace_silencers.rb",
|
96
|
+
"spec/testapp/config/initializers/mime_types.rb",
|
97
|
+
"spec/testapp/config/initializers/new_rails_defaults.rb",
|
98
|
+
"spec/testapp/config/initializers/session_store.rb",
|
99
|
+
"spec/testapp/config/initializers/inflections.rb",
|
100
|
+
"spec/testapp/config/routes.rb",
|
101
|
+
"spec/testapp/test/test_helper.rb",
|
102
|
+
"spec/testapp/test/performance/browsing_test.rb",
|
103
|
+
"spec/testapp/app/controllers/application_controller.rb",
|
104
|
+
"spec/testapp/app/helpers/application_helper.rb",
|
105
|
+
"spec/library_spec.rb",
|
106
|
+
"spec/plugin_spec.rb",
|
107
|
+
"spec/spec_helper.rb"
|
108
|
+
]
|
109
|
+
|
110
|
+
if s.respond_to? :specification_version then
|
111
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
112
|
+
s.specification_version = 3
|
113
|
+
|
114
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
115
|
+
else
|
116
|
+
end
|
117
|
+
else
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Defines class used for storing application-wide setting values.
|
2
|
+
# == Usage:
|
3
|
+
#
|
4
|
+
# Say, config/applications/default.yml looks like this:
|
5
|
+
#
|
6
|
+
# default:
|
7
|
+
# my_app_name: Super App
|
8
|
+
#
|
9
|
+
# Then in your ruby code:
|
10
|
+
#
|
11
|
+
# AppConfig['my_app_name'] #=> "Super App"
|
12
|
+
#
|
13
|
+
# or
|
14
|
+
#
|
15
|
+
# AppConfig.my_app_name #=> "Super App"
|
16
|
+
#
|
17
|
+
module AmberBitAppConfig
|
18
|
+
# Turns object into HashStruct object or array of HashStructs
|
19
|
+
def self.to_hashstruct(object)
|
20
|
+
case object
|
21
|
+
when Array
|
22
|
+
object.map { |el| to_hashstruct(el) }
|
23
|
+
when Hash
|
24
|
+
mapped = {}
|
25
|
+
object.each { |key,value| mapped[key] = to_hashstruct(value) }
|
26
|
+
HashStruct.new(mapped)
|
27
|
+
when Object
|
28
|
+
object
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Recursivelly merges two hashes
|
33
|
+
def self.special_merge!(h1, h2)
|
34
|
+
h2.each do |key, new_val|
|
35
|
+
h1[key] = new_val.is_a?(Hash) ? special_merge!(h1[key] || {}, new_val) : new_val
|
36
|
+
end
|
37
|
+
h1
|
38
|
+
end
|
39
|
+
|
40
|
+
# Loads YAML file, converts it's values to Hash and merges with current config hash
|
41
|
+
# passed as 2nd parameter. Merged hash of options is returned by this method.
|
42
|
+
def self.process_config(file, current_config = nil)
|
43
|
+
new_config = YAML.load_file(file) || {}
|
44
|
+
default_config = new_config['default']
|
45
|
+
|
46
|
+
env_config = defined?(Rails) ? new_config[Rails.env] : nil
|
47
|
+
|
48
|
+
config =
|
49
|
+
if default_config.nil? && env_config.nil?
|
50
|
+
{}
|
51
|
+
elsif default_config.nil? && !env_config.nil?
|
52
|
+
env_config
|
53
|
+
elsif !default_config.nil? && env_config.nil?
|
54
|
+
default_config
|
55
|
+
elsif !default_config.nil? && !env_config.nil?
|
56
|
+
special_merge!(default_config, env_config)
|
57
|
+
end
|
58
|
+
|
59
|
+
current_config.nil? ? config : special_merge!(current_config, config)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.initialize(default_file = File.join(Rails.root, 'config', 'application', 'default.yml'),
|
63
|
+
config_file = File.join(Rails.root, 'config', 'application', 'config.yml'))
|
64
|
+
|
65
|
+
return unless File.exist?(default_file)
|
66
|
+
|
67
|
+
config = process_config(default_file)
|
68
|
+
if File.exist? config_file
|
69
|
+
config = process_config(config_file, config)
|
70
|
+
end
|
71
|
+
Object.const_set('AppConfig', to_hashstruct(config))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
data/lib/hash_struct.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'lib/amberbit-config'
|
3
|
+
|
4
|
+
describe AmberBitAppConfig do
|
5
|
+
before :each do
|
6
|
+
File.open("/tmp/test_default.yml", "w+") do |f|
|
7
|
+
f.write "default:\n whatever: testtest"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not load any config when just requiring library" do
|
12
|
+
defined?(AppConfig).should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be possible to specify custom path for configuration files directory" do
|
16
|
+
AmberBitAppConfig.initialize("/tmp/test_default.yml", "/tmp/test_config.yml")
|
17
|
+
AppConfig.whatever.should eql("testtest")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/spec/plugin_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'lib/amber_bit_app_config.rb'
|
3
|
+
|
4
|
+
describe AmberBitAppConfig do
|
5
|
+
it "should load initial config on Rails startup" do
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/testapp/config/environment")
|
7
|
+
require 'spec/rails'
|
8
|
+
AppConfig.should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should load values from default.yml" do
|
12
|
+
AppConfig['app'].should be_instance_of(HashStruct)
|
13
|
+
AppConfig['app']['name'].should eql("MyApp")
|
14
|
+
AppConfig.app.name.should eql("MyApp")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should overwrite values defined in default.yml by values defined in config.yml" do
|
18
|
+
AppConfig['current_file_name'].should eql("config.yml")
|
19
|
+
AppConfig.current_file_name.should eql("config.yml")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should overwrite values defined in default.yml by values defined in config.yml in nested keys" do
|
23
|
+
AppConfig.app.url.should eql("http://myapp.localhost")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should overwrite values defined in default section by values from current enviromnent section" do
|
27
|
+
AppConfig['current_env'].should eql("test")
|
28
|
+
AppConfig.current_env.should eql("test")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
|
5
|
+
Spec::Runner.configure do |config|
|
6
|
+
# == Fixtures
|
7
|
+
#
|
8
|
+
# You can declare fixtures for each example_group like this:
|
9
|
+
# describe "...." do
|
10
|
+
# fixtures :table_a, :table_b
|
11
|
+
#
|
12
|
+
# Alternatively, if you prefer to declare them only once, you can
|
13
|
+
# do so right here. Just uncomment the next line and replace the fixture
|
14
|
+
# names with your fixtures.
|
15
|
+
#
|
16
|
+
# config.global_fixtures = :table_a, :table_b
|
17
|
+
#
|
18
|
+
# If you declare global fixtures, be aware that they will be declared
|
19
|
+
# for all of your examples, even those that don't use them.
|
20
|
+
#
|
21
|
+
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
22
|
+
#
|
23
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
24
|
+
#
|
25
|
+
# == Mock Framework
|
26
|
+
#
|
27
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
28
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
29
|
+
#
|
30
|
+
# config.mock_with :mocha
|
31
|
+
# config.mock_with :flexmock
|
32
|
+
# config.mock_with :rr
|
33
|
+
#
|
34
|
+
# == Notes
|
35
|
+
#
|
36
|
+
# For more information take a look at Spec::Example::Configuration and Spec::Runner
|
37
|
+
end
|
38
|
+
|
data/spec/testapp/README
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb" templates
|
7
|
+
that are primarily responsible for inserting pre-built data in between HTML tags.
|
8
|
+
The model contains the "smart" domain objects (such as Account, Product, Person,
|
9
|
+
Post) that holds all the business logic and knows how to persist themselves to
|
10
|
+
a database. The controller handles the incoming requests (such as Save New Account,
|
11
|
+
Update Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting Started
|
29
|
+
|
30
|
+
1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
|
31
|
+
and your application name. Ex: rails myapp
|
32
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
33
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
|
34
|
+
4. Follow the guidelines to start developing your application
|
35
|
+
|
36
|
+
|
37
|
+
== Web Servers
|
38
|
+
|
39
|
+
By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
|
40
|
+
with a variety of other web servers.
|
41
|
+
|
42
|
+
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
|
43
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
44
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
45
|
+
More info at: http://mongrel.rubyforge.org
|
46
|
+
|
47
|
+
Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
|
48
|
+
Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
|
49
|
+
FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
|
50
|
+
|
51
|
+
== Apache .htaccess example for FCGI/CGI
|
52
|
+
|
53
|
+
# General Apache options
|
54
|
+
AddHandler fastcgi-script .fcgi
|
55
|
+
AddHandler cgi-script .cgi
|
56
|
+
Options +FollowSymLinks +ExecCGI
|
57
|
+
|
58
|
+
# If you don't want Rails to look in certain directories,
|
59
|
+
# use the following rewrite rules so that Apache won't rewrite certain requests
|
60
|
+
#
|
61
|
+
# Example:
|
62
|
+
# RewriteCond %{REQUEST_URI} ^/notrails.*
|
63
|
+
# RewriteRule .* - [L]
|
64
|
+
|
65
|
+
# Redirect all requests not available on the filesystem to Rails
|
66
|
+
# By default the cgi dispatcher is used which is very slow
|
67
|
+
#
|
68
|
+
# For better performance replace the dispatcher with the fastcgi one
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
72
|
+
RewriteEngine On
|
73
|
+
|
74
|
+
# If your Rails application is accessed via an Alias directive,
|
75
|
+
# then you MUST also set the RewriteBase in this htaccess file.
|
76
|
+
#
|
77
|
+
# Example:
|
78
|
+
# Alias /myrailsapp /path/to/myrailsapp/public
|
79
|
+
# RewriteBase /myrailsapp
|
80
|
+
|
81
|
+
RewriteRule ^$ index.html [QSA]
|
82
|
+
RewriteRule ^([^.]+)$ $1.html [QSA]
|
83
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
84
|
+
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
|
85
|
+
|
86
|
+
# In case Rails experiences terminal errors
|
87
|
+
# Instead of displaying this message you can supply a file here which will be rendered instead
|
88
|
+
#
|
89
|
+
# Example:
|
90
|
+
# ErrorDocument 500 /500.html
|
91
|
+
|
92
|
+
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
|
93
|
+
|
94
|
+
|
95
|
+
== Debugging Rails
|
96
|
+
|
97
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
98
|
+
will help you debug it and get it back on the rails.
|
99
|
+
|
100
|
+
First area to check is the application log files. Have "tail -f" commands running
|
101
|
+
on the server.log and development.log. Rails will automatically display debugging
|
102
|
+
and runtime information to these files. Debugging info will also be shown in the
|
103
|
+
browser on requests from 127.0.0.1.
|
104
|
+
|
105
|
+
You can also log your own messages directly into the log file from your code using
|
106
|
+
the Ruby logger class from inside your controllers. Example:
|
107
|
+
|
108
|
+
class WeblogController < ActionController::Base
|
109
|
+
def destroy
|
110
|
+
@weblog = Weblog.find(params[:id])
|
111
|
+
@weblog.destroy
|
112
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
The result will be a message in your log file along the lines of:
|
117
|
+
|
118
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
|
119
|
+
|
120
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
121
|
+
|
122
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
|
123
|
+
|
124
|
+
* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
|
125
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
126
|
+
|
127
|
+
These two online (and free) books will bring you up to speed on the Ruby language
|
128
|
+
and also on programming in general.
|
129
|
+
|
130
|
+
|
131
|
+
== Debugger
|
132
|
+
|
133
|
+
Debugger support is available through the debugger command when you start your Mongrel or
|
134
|
+
Webrick server with --debugger. This means that you can break out of execution at any point
|
135
|
+
in the code, investigate and change the model, AND then resume execution!
|
136
|
+
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
|
137
|
+
Example:
|
138
|
+
|
139
|
+
class WeblogController < ActionController::Base
|
140
|
+
def index
|
141
|
+
@posts = Post.find(:all)
|
142
|
+
debugger
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
So the controller will accept the action, run the first line, then present you
|
147
|
+
with a IRB prompt in the server window. Here you can do things like:
|
148
|
+
|
149
|
+
>> @posts.inspect
|
150
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
151
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
152
|
+
>> @posts.first.title = "hello from a debugger"
|
153
|
+
=> "hello from a debugger"
|
154
|
+
|
155
|
+
...and even better is that you can examine how your runtime objects actually work:
|
156
|
+
|
157
|
+
>> f = @posts.first
|
158
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
159
|
+
>> f.
|
160
|
+
Display all 152 possibilities? (y or n)
|
161
|
+
|
162
|
+
Finally, when you're ready to resume execution, you enter "cont"
|
163
|
+
|
164
|
+
|
165
|
+
== Console
|
166
|
+
|
167
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
168
|
+
Here you'll have all parts of the application configured, just like it is when the
|
169
|
+
application is running. You can inspect domain models, change values, and save to the
|
170
|
+
database. Starting the script without arguments will launch it in the development environment.
|
171
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
172
|
+
|
173
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
174
|
+
|
175
|
+
== dbconsole
|
176
|
+
|
177
|
+
You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
|
178
|
+
You would be connected to the database with the credentials defined in database.yml.
|
179
|
+
Starting the script without arguments will connect you to the development database. Passing an
|
180
|
+
argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
|
181
|
+
Currently works for mysql, postgresql and sqlite.
|
182
|
+
|
183
|
+
== Description of Contents
|
184
|
+
|
185
|
+
app
|
186
|
+
Holds all the code that's specific to this particular application.
|
187
|
+
|
188
|
+
app/controllers
|
189
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
190
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
191
|
+
which itself descends from ActionController::Base.
|
192
|
+
|
193
|
+
app/models
|
194
|
+
Holds models that should be named like post.rb.
|
195
|
+
Most models will descend from ActiveRecord::Base.
|
196
|
+
|
197
|
+
app/views
|
198
|
+
Holds the template files for the view that should be named like
|
199
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
|
200
|
+
syntax.
|
201
|
+
|
202
|
+
app/views/layouts
|
203
|
+
Holds the template files for layouts to be used with views. This models the common
|
204
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
205
|
+
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
|
206
|
+
call <% yield %> to render the view using this layout.
|
207
|
+
|
208
|
+
app/helpers
|
209
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
210
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
211
|
+
wrap functionality for your views into methods.
|
212
|
+
|
213
|
+
config
|
214
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
215
|
+
|
216
|
+
db
|
217
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
218
|
+
the sequence of Migrations for your schema.
|
219
|
+
|
220
|
+
doc
|
221
|
+
This directory is where your application documentation will be stored when generated
|
222
|
+
using <tt>rake doc:app</tt>
|
223
|
+
|
224
|
+
lib
|
225
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
226
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
227
|
+
|
228
|
+
public
|
229
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
230
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
231
|
+
set as the DOCUMENT_ROOT of your web server.
|
232
|
+
|
233
|
+
script
|
234
|
+
Helper scripts for automation and generation.
|
235
|
+
|
236
|
+
test
|
237
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
238
|
+
test files will be generated for you and placed in this directory.
|
239
|
+
|
240
|
+
vendor
|
241
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
242
|
+
If the app has frozen rails, those gems also go here, under vendor/rails/.
|
243
|
+
This directory is in the load path.
|