chanko 2.0.0 → 2.0.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.
- data/.travis.yml +4 -2
- data/README.md +21 -6
- data/Rakefile +2 -9
- data/chanko.gemspec +1 -0
- data/lib/chanko/active_if.rb +26 -9
- data/lib/chanko/config.rb +2 -0
- data/lib/chanko/exception_handler.rb +32 -5
- data/lib/chanko/unit.rb +5 -1
- data/lib/chanko/version.rb +1 -1
- data/spec/chanko/exception_handler_spec.rb +21 -0
- data/spec/chanko/unit_spec.rb +84 -20
- data/spec/dummy/README.md +12 -0
- data/spec/spec_helper.rb +3 -0
- metadata +20 -4
- data/spec/dummy/README.rdoc +0 -261
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
# Chanko
|
1
|
+
# Chanko [](https://travis-ci.org/cookpad/chanko) [](https://codeclimate.com/github/cookpad/chanko) [](https://coveralls.io/r/cookpad/chanko)
|
2
|
+
|
3
|
+
http://cookpad.github.com/chanko/
|
4
|
+
|
2
5
|
Chanko provides a simple framework for rapidly and safely prototyping new
|
3
6
|
features in your production Rails app, and exposing these prototypes to
|
4
7
|
specified segments of your user base.
|
5
8
|
|
6
|
-
With Chanko, you can release many
|
7
|
-
|
8
|
-
automatically
|
9
|
+
With Chanko, you can release many features concurrently and manage target users independently.
|
10
|
+
When any errors are raised from chanko's features,
|
11
|
+
it will be automatically hidden and fallback to its normal behavior.
|
9
12
|
|
10
13
|
|
11
14
|
## Requirements
|
@@ -21,10 +24,19 @@ gem "chanko"
|
|
21
24
|
```
|
22
25
|
|
23
26
|
## Files
|
24
|
-
Chanko provides a generator to create
|
27
|
+
Chanko provides a generator to create templates of an unit.
|
25
28
|
|
26
29
|
```
|
27
|
-
$ rails generate chanko:
|
30
|
+
$ rails generate chanko:unit example_unit
|
31
|
+
create app/units/example_unit
|
32
|
+
create app/units/example_unit/example_unit.rb
|
33
|
+
create app/units/example_unit/views/.gitkeep
|
34
|
+
create app/units/example_unit/images/.gitkeep
|
35
|
+
create app/units/example_unit/javascripts/.gitkeep
|
36
|
+
create app/units/example_unit/stylesheets/.gitkeep
|
37
|
+
create app/assets/images/units/example_unit
|
38
|
+
create app/assets/javascripts/units/example_unit
|
39
|
+
create app/assets/stylesheets/units/example_unit
|
28
40
|
```
|
29
41
|
|
30
42
|
## Invoke
|
@@ -57,6 +69,7 @@ end
|
|
57
69
|
```
|
58
70
|
|
59
71
|
## Unit
|
72
|
+
You can see [the real example of an unit module file](https://github.com/cookpad/chanko/blob/master/spec/dummy/app/units/entry_deletion/entry_deletion.rb).
|
60
73
|
|
61
74
|
### module
|
62
75
|
You can define your MVC code here.
|
@@ -163,6 +176,8 @@ Chanko provides an example rails application in spec/dummy directory.
|
|
163
176
|
```
|
164
177
|
$ git clone git@github.com:cookpad/chanko.git
|
165
178
|
$ cd chanko/spec/dummy
|
179
|
+
$ bundle install
|
180
|
+
$ bundle exec rake db:create db:migrate
|
166
181
|
$ rails s
|
167
182
|
$ open http://localhost:3000
|
168
183
|
```
|
data/Rakefile
CHANGED
@@ -1,12 +1,5 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
4
|
-
require "rspec/core/rake_task"
|
5
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
-
spec.pattern = "spec/**/*_spec.rb"
|
7
|
-
spec.rspec_opts = ["-cfs"]
|
8
|
-
end
|
9
|
-
rescue LoadError => e
|
10
|
-
end
|
11
|
-
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
5
|
task :default => :spec
|
data/chanko.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.add_dependency "rails", ">= 3.0.10"
|
20
20
|
gem.add_development_dependency "coffee-rails", ">= 3.0.10"
|
21
|
+
gem.add_development_dependency "coveralls"
|
21
22
|
gem.add_development_dependency "jquery-rails"
|
22
23
|
gem.add_development_dependency "pry"
|
23
24
|
gem.add_development_dependency "rspec-rails", "2.12.2"
|
data/lib/chanko/active_if.rb
CHANGED
@@ -33,26 +33,43 @@ module Chanko
|
|
33
33
|
def blocks
|
34
34
|
@blocks ||= begin
|
35
35
|
conditions.map do |condition|
|
36
|
-
|
36
|
+
Block.new(condition)
|
37
37
|
end << @block
|
38
38
|
end.compact
|
39
39
|
end
|
40
40
|
|
41
|
-
class
|
42
|
-
def initialize(*
|
43
|
-
@
|
41
|
+
class Block
|
42
|
+
def initialize(*conditions)
|
43
|
+
@conditions = conditions
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def call(context, options)
|
47
|
+
block.call(context, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def block
|
51
|
+
condition = @conditions.first
|
52
|
+
condition.is_a?(Block) ? condition : ActiveIf.find(condition)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Any < Block
|
57
|
+
def block
|
47
58
|
proc do |context, options|
|
48
|
-
|
49
|
-
|
59
|
+
@conditions.any? do |condition|
|
60
|
+
Block.new(condition).call(context, options)
|
50
61
|
end
|
51
62
|
end
|
52
63
|
end
|
64
|
+
end
|
53
65
|
|
54
|
-
|
55
|
-
|
66
|
+
class None < Block
|
67
|
+
def block
|
68
|
+
proc do |context, options|
|
69
|
+
@conditions.none? do |condition|
|
70
|
+
Block.new(condition).call(context, options)
|
71
|
+
end
|
72
|
+
end
|
56
73
|
end
|
57
74
|
end
|
58
75
|
end
|
data/lib/chanko/config.rb
CHANGED
@@ -7,6 +7,7 @@ module Chanko
|
|
7
7
|
:cache_units,
|
8
8
|
:compatible_css_class,
|
9
9
|
:enable_logger,
|
10
|
+
:propagated_errors,
|
10
11
|
:proxy_method_name,
|
11
12
|
:raise_error,
|
12
13
|
:resolver,
|
@@ -18,6 +19,7 @@ module Chanko
|
|
18
19
|
self.backtrace_limit = 10
|
19
20
|
self.compatible_css_class = false
|
20
21
|
self.enable_logger = true
|
22
|
+
self.propagated_errors = []
|
21
23
|
self.proxy_method_name = :unit
|
22
24
|
self.raise_error = Rails.env.development?
|
23
25
|
self.resolver = ActionView::OptimizedFileSystemResolver
|
@@ -1,10 +1,37 @@
|
|
1
1
|
module Chanko
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class ExceptionHandler
|
3
|
+
def self.handle(*args)
|
4
|
+
new(*args).handle
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :exception, :unit
|
8
|
+
|
9
|
+
def initialize(exception, unit = nil)
|
10
|
+
@exception = exception
|
11
|
+
@unit = unit
|
12
|
+
end
|
13
|
+
|
14
|
+
def handle
|
15
|
+
if propagated?
|
16
|
+
raise exception
|
17
|
+
else
|
18
|
+
log
|
19
|
+
raise exception if raised?
|
7
20
|
end
|
8
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def propagated?
|
26
|
+
Config.propagated_errors.any? {|klass| exception.is_a?(klass) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def raised?
|
30
|
+
unit.try(:raise_error?) || Config.raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
def log
|
34
|
+
Logger.debug(exception)
|
35
|
+
end
|
9
36
|
end
|
10
37
|
end
|
data/lib/chanko/unit.rb
CHANGED
@@ -49,6 +49,10 @@ module Chanko
|
|
49
49
|
ActiveIf::Any.new(*labels)
|
50
50
|
end
|
51
51
|
|
52
|
+
def none(*labels)
|
53
|
+
ActiveIf::None.new(*labels)
|
54
|
+
end
|
55
|
+
|
52
56
|
def raise_error
|
53
57
|
@raise_error = true
|
54
58
|
end
|
@@ -67,7 +71,7 @@ module Chanko
|
|
67
71
|
end
|
68
72
|
|
69
73
|
def view_path
|
70
|
-
"#{Config.units_directory_path}/#{unit_name}/views"
|
74
|
+
Rails.root.join("#{Config.units_directory_path}/#{unit_name}/views").to_s
|
71
75
|
end
|
72
76
|
|
73
77
|
def find_function(identifier, label)
|
data/lib/chanko/version.rb
CHANGED
@@ -14,6 +14,27 @@ module Chanko
|
|
14
14
|
Exception.new
|
15
15
|
end
|
16
16
|
|
17
|
+
context "when Config.propagated_errors includes given error" do
|
18
|
+
before do
|
19
|
+
Config.propagated_errors << Exception
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises up error without any logging" do
|
23
|
+
Logger.should_not_receive(:debug)
|
24
|
+
expect { described_class.handle(error, insensitive_unit) }.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when Config.propagated_errors does not include given error" do
|
29
|
+
before do
|
30
|
+
Config.propagated_errors << StandardError
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises up no error" do
|
34
|
+
expect { described_class.handle(error, insensitive_unit) }.not_to raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
17
38
|
context "when Config.raise_error is false" do
|
18
39
|
it "raises up no error" do
|
19
40
|
expect { described_class.handle(error, insensitive_unit) }.not_to raise_error
|
data/spec/chanko/unit_spec.rb
CHANGED
@@ -14,7 +14,7 @@ module Chanko
|
|
14
14
|
Class.new { include Chanko::Helper }.new
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "
|
17
|
+
describe "about active_if" do
|
18
18
|
before do
|
19
19
|
ActiveIf.define(:true) { true }
|
20
20
|
ActiveIf.define(:false) { false }
|
@@ -26,38 +26,102 @@ module Chanko
|
|
26
26
|
|
27
27
|
subject { unit.active?(view) }
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
describe ".active_if" do
|
30
|
+
context "in default configuration" do
|
31
|
+
it "is configured to return always true" do
|
32
|
+
should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when labels are specified" do
|
37
|
+
before do
|
38
|
+
unit.active_if(:true, :false)
|
39
|
+
end
|
40
|
+
specify "all of defined conditions must pass" do
|
41
|
+
should be_false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when block is passed" do
|
46
|
+
before do
|
47
|
+
unit.active_if(:true) { false }
|
48
|
+
end
|
49
|
+
specify "all of defined conditions and block must pass" do
|
50
|
+
should be_false
|
51
|
+
end
|
32
52
|
end
|
33
53
|
end
|
34
54
|
|
35
|
-
|
36
|
-
|
37
|
-
|
55
|
+
describe ".any" do
|
56
|
+
context "when conditions returned true and false" do
|
57
|
+
before do
|
58
|
+
unit.instance_eval do
|
59
|
+
active_if any(:true, :false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
it { should be_true }
|
38
63
|
end
|
39
|
-
|
40
|
-
|
64
|
+
|
65
|
+
context "when all conditions returned false" do
|
66
|
+
before do
|
67
|
+
unit.instance_eval do
|
68
|
+
active_if any(:false, :false)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
it { should be_false }
|
41
72
|
end
|
42
73
|
end
|
43
74
|
|
44
|
-
|
45
|
-
|
46
|
-
|
75
|
+
describe ".none" do
|
76
|
+
context "when all conditions returned false" do
|
77
|
+
before do
|
78
|
+
unit.instance_eval do
|
79
|
+
active_if none(:false, :false)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
it { should be_true }
|
47
83
|
end
|
48
|
-
|
49
|
-
|
84
|
+
|
85
|
+
context "when conditions returned true and false" do
|
86
|
+
before do
|
87
|
+
unit.instance_eval do
|
88
|
+
active_if none(:true, :false)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
it { should be_false }
|
50
92
|
end
|
51
93
|
end
|
52
94
|
|
53
|
-
context "when any
|
54
|
-
|
55
|
-
|
56
|
-
|
95
|
+
context "when using 'any' and 'none'" do
|
96
|
+
context "'any' in 'none'" do
|
97
|
+
before do
|
98
|
+
unit.instance_eval do
|
99
|
+
active_if none(any(:true, :false))
|
100
|
+
end
|
101
|
+
end
|
102
|
+
it "returns negatived result of inner-expression" do
|
103
|
+
should be_false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "'none' in 'any'" do
|
108
|
+
before do
|
109
|
+
unit.instance_eval do
|
110
|
+
active_if any(none(:true), :false)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
it "uses none(:true) as false" do
|
114
|
+
should be_false
|
57
115
|
end
|
58
116
|
end
|
59
|
-
|
60
|
-
|
117
|
+
|
118
|
+
context "more nested" do
|
119
|
+
before do
|
120
|
+
unit.instance_eval do
|
121
|
+
active_if any(any(none(:false), :false), :false)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
it { should be_true }
|
61
125
|
end
|
62
126
|
end
|
63
127
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Chanko example
|
2
|
+
This is an example rails application using Chanko.
|
3
|
+
This application has a unit called EntryDeletion,
|
4
|
+
which extends MVC logics to provide a feature to delete entries.
|
5
|
+
|
6
|
+
## Start
|
7
|
+
```
|
8
|
+
$ bundle install
|
9
|
+
$ bundle exec rake db:create db:migrate
|
10
|
+
$ rails s
|
11
|
+
$ open http://localhost:3000
|
12
|
+
```
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chanko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 3.0.10
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: coveralls
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: jquery-rails
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -239,7 +255,7 @@ files:
|
|
239
255
|
- spec/chanko/unit_proxy_spec.rb
|
240
256
|
- spec/chanko/unit_spec.rb
|
241
257
|
- spec/controllers/application_controller_spec.rb
|
242
|
-
- spec/dummy/README.
|
258
|
+
- spec/dummy/README.md
|
243
259
|
- spec/dummy/Rakefile
|
244
260
|
- spec/dummy/app/assets/javascripts/application.js
|
245
261
|
- spec/dummy/app/assets/stylesheets/application.css
|
@@ -327,7 +343,7 @@ test_files:
|
|
327
343
|
- spec/chanko/unit_proxy_spec.rb
|
328
344
|
- spec/chanko/unit_spec.rb
|
329
345
|
- spec/controllers/application_controller_spec.rb
|
330
|
-
- spec/dummy/README.
|
346
|
+
- spec/dummy/README.md
|
331
347
|
- spec/dummy/Rakefile
|
332
348
|
- spec/dummy/app/assets/javascripts/application.js
|
333
349
|
- spec/dummy/app/assets/stylesheets/application.css
|
data/spec/dummy/README.rdoc
DELETED
@@ -1,261 +0,0 @@
|
|
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
|
-
| `-- tasks
|
177
|
-
|-- log
|
178
|
-
|-- public
|
179
|
-
|-- script
|
180
|
-
|-- test
|
181
|
-
| |-- fixtures
|
182
|
-
| |-- functional
|
183
|
-
| |-- integration
|
184
|
-
| |-- performance
|
185
|
-
| `-- unit
|
186
|
-
|-- tmp
|
187
|
-
| |-- cache
|
188
|
-
| |-- pids
|
189
|
-
| |-- sessions
|
190
|
-
| `-- sockets
|
191
|
-
`-- vendor
|
192
|
-
|-- assets
|
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.
|