excursion 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/excursion/configuration.rb +1 -1
- data/lib/excursion/{datasources/datasource.rb → datastores/datastore.rb} +2 -2
- data/lib/excursion/{datasources → datastores}/file.rb +7 -10
- data/lib/excursion/{datasources → datastores}/memcache.rb +9 -9
- data/lib/excursion/exceptions/datastores.rb +7 -0
- data/lib/excursion/helpers/application_helper.rb +2 -0
- data/lib/excursion/helpers/url_helper.rb +11 -0
- data/lib/excursion/pool/application.rb +44 -16
- data/lib/excursion/pool.rb +22 -15
- data/lib/excursion/version.rb +1 -1
- data/lib/excursion.rb +8 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +64 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/excursion.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +63 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/doc/README_FOR_APP +2 -0
- data/spec/dummy/log/development.log +5066 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +241 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/excursion/datastores/file_spec.rb +118 -0
- data/spec/excursion/datastores/memcache_spec.rb +119 -0
- data/spec/excursion/helpers/application_helper_spec.rb +48 -0
- data/spec/excursion/helpers/url_helper_spec.rb +55 -0
- data/spec/excursion/helpers_spec.rb +65 -0
- data/spec/excursion/pool/application_spec.rb +214 -0
- data/spec/excursion/pool_spec.rb +203 -0
- data/spec/excursion_spec.rb +4 -0
- data/spec/spec_helper.rb +21 -1
- data/spec/support/mocks.rb +51 -0
- metadata +126 -8
- data/lib/excursion/exceptions/datasources.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3dfd7605be2886786008e1c04475bf20279c51d
|
4
|
+
data.tar.gz: 5ff9b50daa9541d28268394c45dd3293d6e176f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b61c03942b8842cfe658091e496586977d9d2e8c6c2c7e8be428a90d684da786272983b0d780936172d8ad06f5bd8d9c1352b45313fc5750f7c4797184f6522
|
7
|
+
data.tar.gz: e2945a3964b874db4877b02c4b66c9b7ab5d1134d6230568016f323e04f6b5e0d6ff3b82e426224aa6010b5f962ec6e0071d58cad46fb63076dc173e33d4d3fc
|
@@ -6,7 +6,7 @@ module Excursion
|
|
6
6
|
# include_pattern: to only include certain routes
|
7
7
|
register_app: true, # whether or not to register the app automatically on init
|
8
8
|
default_url_options: {}, # default_url_options used when building routes for this app
|
9
|
-
retry_limit: 3 # retry limit for
|
9
|
+
retry_limit: 3 # retry limit for datastores that user remote servers
|
10
10
|
}
|
11
11
|
|
12
12
|
#attr_reader *DEFAULT_CONFIGURATION_OPTIONS.keys
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require 'excursion/
|
2
|
+
require 'excursion/datastores/datastore'
|
3
3
|
|
4
4
|
module Excursion
|
5
|
-
module
|
6
|
-
class File <
|
5
|
+
module Datastores
|
6
|
+
class File < Datastore
|
7
7
|
|
8
8
|
def read(key)
|
9
9
|
read_file[key.to_s]
|
@@ -28,14 +28,11 @@ module Excursion
|
|
28
28
|
|
29
29
|
protected
|
30
30
|
|
31
|
-
def initialize(path
|
32
|
-
path
|
33
|
-
raise DatasourceConfigurationError, "You must configure the :file datasource with a datasource_file path" if path.nil?
|
31
|
+
def initialize(path)
|
32
|
+
raise DatastoreConfigurationError if path.nil? || path.to_s.empty?
|
34
33
|
@path = ::File.expand_path(path)
|
35
|
-
rescue DatasourceConfigurationError => e
|
36
|
-
raise e
|
37
34
|
rescue
|
38
|
-
raise
|
35
|
+
raise DatastoreConfigurationError, "Could not initialize the :file datastore with path: '#{path}'"
|
39
36
|
end
|
40
37
|
|
41
38
|
def exists?
|
@@ -52,7 +49,7 @@ module Excursion
|
|
52
49
|
FileUtils.mkpath(::File.dirname(@path))
|
53
50
|
::File.open(@path, 'w') { |f| f.write(results.to_yaml)}
|
54
51
|
rescue
|
55
|
-
raise
|
52
|
+
raise DatastoreConfigurationError, "Could not write to the excursion route pool file: #{@path}"
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'dalli'
|
2
|
-
require 'excursion/
|
2
|
+
require 'excursion/datastores/datastore'
|
3
3
|
require 'excursion/exceptions/memcache'
|
4
4
|
|
5
5
|
module Excursion
|
6
|
-
module
|
7
|
-
class Memcache <
|
6
|
+
module Datastores
|
7
|
+
class Memcache < Datastore
|
8
8
|
|
9
9
|
def read(key)
|
10
10
|
@client.get(key.to_s)
|
@@ -14,14 +14,15 @@ module Excursion
|
|
14
14
|
alias_method :get, :read
|
15
15
|
|
16
16
|
def write(key, value)
|
17
|
-
@client.set(key.to_s, value)
|
17
|
+
value if @client.set(key.to_s, value)
|
18
18
|
rescue Dalli::RingError => e
|
19
19
|
rescue_from_dalli_ring_error(e) && retry
|
20
20
|
end
|
21
21
|
alias_method :set, :write
|
22
22
|
|
23
23
|
def delete(key)
|
24
|
-
@client.
|
24
|
+
value = @client.get(key)
|
25
|
+
value if @client.delete(key)
|
25
26
|
rescue Dalli::RingError => e
|
26
27
|
rescue_from_dalli_ring_error(e) && retry
|
27
28
|
end
|
@@ -29,9 +30,8 @@ module Excursion
|
|
29
30
|
|
30
31
|
protected
|
31
32
|
|
32
|
-
def initialize(server
|
33
|
-
server
|
34
|
-
raise MemcacheConfigurationError, "You must configure the :memcache datasource with a memcache_server" if server.nil?
|
33
|
+
def initialize(server)
|
34
|
+
raise MemcacheConfigurationError, "Memcache server cannot be nil" if server.nil? || server.to_s.empty?
|
35
35
|
@client = Dalli::Client.new(server, {namespace: "excursion"})
|
36
36
|
end
|
37
37
|
|
@@ -47,7 +47,7 @@ module Excursion
|
|
47
47
|
raise MemcacheServerError, "Excursion memcache server is down! Retried #{retries} times."
|
48
48
|
end
|
49
49
|
|
50
|
-
STDERR.puts "Excursion memcache server has gone away! Retrying..."
|
50
|
+
#STDERR.puts "Excursion memcache server has gone away! Retrying..."
|
51
51
|
sleep 1 # give it a chance to come back
|
52
52
|
@dalli_retries += 1
|
53
53
|
end
|
@@ -10,6 +10,8 @@ module Excursion
|
|
10
10
|
def method_missing(meth, *args)
|
11
11
|
if meth.to_s.match(/\A(#{routes.collect { |name,route| name }.join("|")})_(url|path)\Z/)
|
12
12
|
ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper.create(routes.get($1.to_sym), @application.default_url_options).call(Rails.application.routes, args)
|
13
|
+
# Playing with getting Rails3 working
|
14
|
+
#ActionDispatch::Http::URL.url_for(@application.default_url_options.merge({path: replaced_path(routes.get($1.to_sym), args) }))
|
13
15
|
else
|
14
16
|
super
|
15
17
|
end
|
@@ -20,6 +22,15 @@ module Excursion
|
|
20
22
|
def initialize(app)
|
21
23
|
@application = app
|
22
24
|
end
|
25
|
+
|
26
|
+
# Playing with getting Rails3 working
|
27
|
+
#def replaced_path(route, args)
|
28
|
+
# path = route.path.spec.to_s.dup
|
29
|
+
# route.required_parts.zip(args) do |part, arg|
|
30
|
+
# path.gsub!(/(\*|:)#{part}/, Journey::Router::Utils.escape_fragment(arg.to_param))
|
31
|
+
# end
|
32
|
+
# path
|
33
|
+
#end
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
@@ -4,7 +4,7 @@ module Excursion
|
|
4
4
|
attr_reader :name, :default_url_options
|
5
5
|
|
6
6
|
def self.from_cache(cached)
|
7
|
-
new
|
7
|
+
new(cached[:name], cached)
|
8
8
|
end
|
9
9
|
|
10
10
|
def route(key)
|
@@ -16,6 +16,8 @@ module Excursion
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def routes=(routes)
|
19
|
+
return @routes = routes if routes.is_a?(ActionDispatch::Routing::RouteSet::NamedRouteCollection)
|
20
|
+
raise ArgumentError, 'routes must be a Hash or NamedRouteCollection' unless routes.is_a?(Hash)
|
19
21
|
@routes = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
|
20
22
|
routes.each do |name, route|
|
21
23
|
@routes.add(name, route)
|
@@ -24,38 +26,64 @@ module Excursion
|
|
24
26
|
|
25
27
|
def set_routes(routes)
|
26
28
|
self.routes = routes
|
27
|
-
self
|
28
29
|
end
|
29
30
|
|
30
31
|
def to_cache
|
31
|
-
{
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
{
|
33
|
+
name: @name,
|
34
|
+
routes: Hash[routes.map { |name, route| [name.to_sym, route.path.spec.to_s] }],
|
35
|
+
default_url_options: @default_url_options,
|
36
|
+
registered_at: @registered_at
|
35
37
|
}
|
36
38
|
end
|
37
39
|
|
40
|
+
def from_cache(cached)
|
41
|
+
@routes = routes_from_cache(cached[:routes]) if cached.has_key?(:routes)
|
42
|
+
@default_url_options = cached[:default_url_options]
|
43
|
+
@registered_at = (Time.at(cached[:registered_at]) rescue Time.now)
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def initialize(name, config, routes=nil)
|
49
|
+
@name = name
|
50
|
+
from_cache(config)
|
51
|
+
set_routes(routes) unless routes.nil?
|
52
|
+
end
|
53
|
+
|
38
54
|
def routes_from_cache(routes)
|
39
55
|
collection = ActionDispatch::Routing::RouteSet::NamedRouteCollection.new
|
40
56
|
routes.each do |name, path|
|
41
|
-
collection.add(name,
|
57
|
+
collection.add(name, journey_route(name, Rails.application, journey_path(path), {required_defaults: []}))
|
42
58
|
end
|
43
59
|
collection
|
44
60
|
end
|
61
|
+
|
62
|
+
def journey_route(name, app, path, options)
|
63
|
+
journey_route_class.new(name, app, path, options)
|
64
|
+
end
|
45
65
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
66
|
+
def journey_route_class
|
67
|
+
if Excursion.rails3?
|
68
|
+
Journey::Route
|
69
|
+
elsif Excursion.rails4?
|
70
|
+
ActionDispatch::Journey::Route
|
71
|
+
end
|
52
72
|
end
|
53
73
|
|
54
|
-
|
74
|
+
def journey_path(path)
|
75
|
+
journey_path_class.new(path)
|
76
|
+
end
|
55
77
|
|
56
|
-
def
|
57
|
-
|
78
|
+
def journey_path_class
|
79
|
+
if Excursion.rails3?
|
80
|
+
Journey::Path::Pattern
|
81
|
+
elsif Excursion.rails4?
|
82
|
+
ActionDispatch::Journey::Path::Pattern
|
83
|
+
end
|
58
84
|
end
|
85
|
+
|
86
|
+
|
59
87
|
end
|
60
88
|
end
|
61
89
|
end
|
data/lib/excursion/pool.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'excursion/pool/application'
|
2
2
|
require 'excursion/exceptions/pool'
|
3
|
-
require 'excursion/exceptions/
|
3
|
+
require 'excursion/exceptions/datastores'
|
4
4
|
|
5
5
|
module Excursion
|
6
6
|
module Pool
|
@@ -9,33 +9,40 @@ module Excursion
|
|
9
9
|
def self.application(name)
|
10
10
|
return @@applications[name] if @@applications.has_key?(name)
|
11
11
|
|
12
|
-
app_yaml =
|
12
|
+
app_yaml = datastore.get(name)
|
13
13
|
@@applications[name] = Application.from_cache(app_yaml) unless app_yaml.nil?
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.register_application(app)
|
17
|
+
raise ArgumentError, "app must be an instance of Rails::Application" unless app.is_a?(Rails::Application)
|
18
|
+
|
17
19
|
name = app.class.name.underscore.split("/").first
|
18
|
-
config = {
|
20
|
+
config = {default_url_options: Excursion.configuration.default_url_options}
|
19
21
|
|
20
|
-
@@applications[name] = Application.new(config, app.routes.named_routes)
|
21
|
-
|
22
|
+
@@applications[name] = Application.new(name, config, app.routes.named_routes)
|
23
|
+
datastore.set(name, @@applications[name].to_cache)
|
22
24
|
end
|
23
25
|
|
24
26
|
def self.remove_application(app)
|
27
|
+
raise ArgumentError, "app must be an instance of Rails::Application" unless app.is_a?(Rails::Application)
|
28
|
+
|
25
29
|
name = app.class.name.underscore.split("/").first
|
26
|
-
|
30
|
+
datastore.delete(name)
|
27
31
|
@@applications.delete(name)
|
28
32
|
end
|
29
33
|
|
30
|
-
def self.
|
31
|
-
raise
|
32
|
-
require "excursion/
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def self.datastore
|
35
|
+
raise NoDatastoreError, "You must configure excursion with a datastore." if Excursion.configuration.datastore.nil?
|
36
|
+
require "excursion/datastores/#{Excursion.configuration.datastore.to_s}"
|
37
|
+
|
38
|
+
case Excursion.configuration.datastore.to_sym
|
39
|
+
when :file
|
40
|
+
raise DatastoreConfigurationError, "You must configure the :file datastore with a datastore_file path" if Excursion.configuration.datastore_file.nil?
|
41
|
+
@@datastore ||= Excursion::Datastores::File.new(Excursion.configuration.datastore_file)
|
42
|
+
when :memcache
|
43
|
+
raise MemcacheConfigurationError, "You must configure the :memcache datastore with a memcache_server" if Excursion.configuration.memcache_server.nil?
|
44
|
+
@@datastore ||= Excursion::Datastores::Memcache.new(Excursion.configuration.memcache_server)
|
45
|
+
end
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
data/lib/excursion/version.rb
CHANGED
data/lib/excursion.rb
CHANGED
@@ -0,0 +1,261 @@
|
|
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"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| | |-- images
|
161
|
+
| | |-- javascripts
|
162
|
+
| | `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| |-- assets
|
177
|
+
| `-- tasks
|
178
|
+
|-- log
|
179
|
+
|-- public
|
180
|
+
|-- script
|
181
|
+
|-- test
|
182
|
+
| |-- fixtures
|
183
|
+
| |-- functional
|
184
|
+
| |-- integration
|
185
|
+
| |-- performance
|
186
|
+
| `-- unit
|
187
|
+
|-- tmp
|
188
|
+
| `-- cache
|
189
|
+
| `-- assets
|
190
|
+
`-- vendor
|
191
|
+
|-- assets
|
192
|
+
| |-- javascripts
|
193
|
+
| `-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|