datum 0.9.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +25 -1
- data/README.md +2 -130
- data/Rakefile +3 -9
- data/lib/datum/container.rb +64 -0
- data/lib/datum/datum.rb +51 -0
- data/lib/datum/helpers.rb +58 -0
- data/lib/datum/version.rb +8 -27
- data/lib/datum.rb +21 -93
- data/lib/plan9/structures.rb +71 -0
- data/lib/support/scenario.rb +14 -0
- data/lib/support/test.rb +27 -0
- metadata +29 -124
- data/lib/datum/context.rb +0 -55
- data/lib/datum/db_tasks.rb +0 -108
- data/lib/datum/driver_helper.rb +0 -109
- data/lib/datum/enable_notification.rb +0 -27
- data/lib/datum/enable_task.rb +0 -148
- data/lib/datum/railtie.rb +0 -14
- data/lib/datum/verification_task.rb +0 -154
- data/lib/datum/verify_helpers/20120726105125_create_datum_versions.rb +0 -18
- data/lib/datum/verify_helpers/datum_version.rb +0 -8
- data/lib/datum/verify_helpers/datum_version_test.rb +0 -11
- data/lib/generators/datum/USAGE +0 -0
- data/lib/generators/datum/datum_generator.rb +0 -104
- data/lib/generators/datum/templates/datum_migration.rb +0 -21
- data/lib/generators/datum/templates/datum_model.rb +0 -6
- data/lib/tasks/datum.rake +0 -49
- data/test/datum_test.rb +0 -17
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/application.rb +0 -61
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.example +0 -42
- data/test/dummy/config/database.sqlite +0 -25
- data/test/dummy/config/database.yml +0 -55
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -58
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/schema.rb +0 -16
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/test/lib/datum/utils/application.rb +0 -57
- data/test/dummy/test/lib/datum/utils/database.yml +0 -42
- data/test/dummy/test/test_helper.rb +0 -13
- data/test/dummy/test/unit/enable_task_test.rb +0 -70
- data/test/test_helper.rb +0 -10
@@ -1,154 +0,0 @@
|
|
1
|
-
module Datum
|
2
|
-
# some reports of connections / settings issues.
|
3
|
-
# verify allows for a full check of the datum db scenarios
|
4
|
-
# intended to be used as part of enable to report datum readiness
|
5
|
-
class VerificationTask
|
6
|
-
|
7
|
-
|
8
|
-
def disable_user_questions
|
9
|
-
@@ask_user = false
|
10
|
-
end
|
11
|
-
|
12
|
-
def rock
|
13
|
-
|
14
|
-
puts "\n### !!!Datum Verification !!!"
|
15
|
-
puts "### !!!This command DROPS the Datum Database!!!"
|
16
|
-
|
17
|
-
if @@ask_user
|
18
|
-
puts "\n>>>>>>>>>>>>>>>> Proceed with Datum Verification? y/n"
|
19
|
-
continue = STDIN.gets.chomp
|
20
|
-
unless continue == 'y' || continue == 'yes'
|
21
|
-
puts "\n ... Canceling Datum Verification\n "
|
22
|
-
exit!
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
database_ready = false
|
27
|
-
database_removed = false
|
28
|
-
files_removed = false
|
29
|
-
|
30
|
-
begin
|
31
|
-
dbtsks = DbTasks.new
|
32
|
-
puts "\n Dropping Existing Datum Database...\n "
|
33
|
-
dbtsks.drop
|
34
|
-
puts "\n Drop complete\n "
|
35
|
-
puts "\n Verifing Datum functionality...\n "
|
36
|
-
dbtsks.create
|
37
|
-
puts " >> Database created"
|
38
|
-
copy_verification_files
|
39
|
-
puts " >> Directories verified\n "
|
40
|
-
dbtsks.migrate
|
41
|
-
database_ready = true
|
42
|
-
puts " >> Migration complete"
|
43
|
-
seed_verification_table
|
44
|
-
puts " >> Storage verified"
|
45
|
-
puts " >> Attempting data driven test cases from database"
|
46
|
-
exec_test
|
47
|
-
puts " >> Database driven test complete"
|
48
|
-
dbtsks.dump
|
49
|
-
puts " >> Fixtures generated"
|
50
|
-
remove_verification_table_data
|
51
|
-
dbtsks.load
|
52
|
-
puts " >> Fixture data uploaded"
|
53
|
-
dbtsks.localize({:table => "datum_versions"})
|
54
|
-
puts " >> Localization complete"
|
55
|
-
dbtsks.drop
|
56
|
-
database_removed = true
|
57
|
-
puts " >> Database dropped"
|
58
|
-
puts " >> Attempting data driven test cases from file"
|
59
|
-
exec_test
|
60
|
-
puts " >> Data file driven test complete"
|
61
|
-
remove_verification_files
|
62
|
-
files_removed = true
|
63
|
-
puts " \n ... Core Datum functionality verified!\n "
|
64
|
-
rescue Exception => exc
|
65
|
-
puts " >> !!!! Verification failed !!!!"
|
66
|
-
puts "#{exc}"
|
67
|
-
puts "\n### !!! Please file email datum@tyemill.com with the above output !!!"
|
68
|
-
ensure
|
69
|
-
remove_verification_table_data if database_ready && !database_removed
|
70
|
-
remove_verification_files unless files_removed
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
protected
|
75
|
-
|
76
|
-
def seed_verification_table
|
77
|
-
DatumVersion.create([
|
78
|
-
{:version => "0.0.1"},
|
79
|
-
{:version => "0.8.0"},
|
80
|
-
{:version => "0.8.1"},
|
81
|
-
{:version => "0.8.2"},
|
82
|
-
{:version => "0.8.3"},
|
83
|
-
{:version => "0.8.4"},
|
84
|
-
{:version => "0.8.5"},
|
85
|
-
{:version => "0.8.6"},
|
86
|
-
{:version => "0.8.7"},
|
87
|
-
{:version => "0.9.0"},
|
88
|
-
{:version => "0.9.1"},
|
89
|
-
{:version => "0.9.2"}])
|
90
|
-
end
|
91
|
-
|
92
|
-
def exec_test
|
93
|
-
puts " >> Starting data-driven test cases...\n "
|
94
|
-
result = system "ruby -Itest #{@@test_src}"
|
95
|
-
raise 'Datum Testcases did not complete successfully!' if !result
|
96
|
-
puts "\n "
|
97
|
-
end
|
98
|
-
|
99
|
-
def remove_verification_table_data
|
100
|
-
DatumVersion.delete_all
|
101
|
-
end
|
102
|
-
|
103
|
-
def copy_verification_files
|
104
|
-
# need to make sure all existing fixtures are moved to prevent
|
105
|
-
# overwritting or unwanted data in verification process
|
106
|
-
FileUtils.cp_r "#{@@local_path}", "#{@@datum_tmp}"
|
107
|
-
FileUtils.remove_dir "#{@@local_path}"
|
108
|
-
(Datum::EnableTask.new).create_directories
|
109
|
-
|
110
|
-
FileUtils.cp_r @@migration_src, "#{@@local_path}/migrate"
|
111
|
-
FileUtils.cp_r @@model_src, "#{@@local_path}/models"
|
112
|
-
FileUtils.cp_r @@test_src, "#{@@unit_dir}"
|
113
|
-
end
|
114
|
-
|
115
|
-
# delete: the migration, the fixture, the ruby file, the model
|
116
|
-
def remove_verification_files
|
117
|
-
|
118
|
-
# need to move fixtures back
|
119
|
-
FileUtils.remove_dir "#{@@local_path}"
|
120
|
-
FileUtils.cp_r "#{@@datum_tmp}", "#{@@local_path}"
|
121
|
-
FileUtils.remove_dir "#{@@datum_tmp}"
|
122
|
-
|
123
|
-
files = [@@test_drop]
|
124
|
-
files.each { |file|
|
125
|
-
context.log "Removing file: #{file}"
|
126
|
-
FileUtils.remove_file file
|
127
|
-
}
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
@@ask_user = true
|
133
|
-
@@local_path = "#{Rails.root}/test/lib/datum"
|
134
|
-
@@datum_tmp = "#{Rails.root}/test/lib/datum_tmp"
|
135
|
-
@@gem_path = File.expand_path(File.dirname(__FILE__))
|
136
|
-
@@migration_file = "20120726105125_create_datum_versions.rb"
|
137
|
-
@@version_str = "DatumVersion"
|
138
|
-
@@version_tbl = @@version_str.tableize
|
139
|
-
@@version_single = @@version_tbl.singularize
|
140
|
-
@@model_file = "#{@@version_single}.rb"
|
141
|
-
@@fixture_file = "#{@@version_tbl}.yml"
|
142
|
-
@@test_file = "#{@@version_single}_test.rb"
|
143
|
-
@@ruby_file = "#{@@version_tbl}.rb"
|
144
|
-
@@migration_src = "#{@@gem_path}/verify_helpers/#{@@migration_file}"
|
145
|
-
@@model_src = "#{@@gem_path}/verify_helpers/#{@@model_file}"
|
146
|
-
@@test_src = "#{@@gem_path}/verify_helpers/#{@@test_file}"
|
147
|
-
@@unit_dir = "#{Rails.root}/test/unit"
|
148
|
-
@@test_drop = "#{@@unit_dir}/#{@@test_file}"
|
149
|
-
|
150
|
-
def context
|
151
|
-
return Datum::Context
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# used to help verify basic datum functionality
|
2
|
-
# see rake datum:db:verify for details
|
3
|
-
class CreateDatumVersions < ActiveRecord::Migration
|
4
|
-
|
5
|
-
ActiveRecord::Base.establish_connection :datum
|
6
|
-
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
7
|
-
|
8
|
-
def self.up
|
9
|
-
create_table :datum_versions do |t|
|
10
|
-
t.string :version
|
11
|
-
t.timestamps
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.down
|
16
|
-
drop_table :datum_versions
|
17
|
-
end
|
18
|
-
end
|
data/lib/generators/datum/USAGE
DELETED
File without changes
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'rails/generators/migration'
|
2
|
-
require 'rails/generators/generated_attribute'
|
3
|
-
|
4
|
-
# Generator code was modified from https://github.com/ryanb/nifty-generators/
|
5
|
-
# Nifty Generators is Copyright (c) 2011 Ryan Bates and distributed via the
|
6
|
-
# MIT License
|
7
|
-
class DatumGenerator < Rails::Generators::Base
|
8
|
-
include Rails::Generators::Migration
|
9
|
-
no_tasks { attr_accessor :scaffold_name, :model_attributes}
|
10
|
-
source_root File.expand_path('../templates', __FILE__)
|
11
|
-
|
12
|
-
argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
|
13
|
-
argument :args_for_m, :type => :array, :default => [], :banner => 'model:attributes'
|
14
|
-
|
15
|
-
class_option :skip_migration,
|
16
|
-
:desc => 'Don\'t generate migration file for model.', :type => :boolean
|
17
|
-
|
18
|
-
class_option :skip_model,
|
19
|
-
:desc => 'Don\'t generate a model or migration file.', :type => :boolean
|
20
|
-
|
21
|
-
def initialize(*args, &block)
|
22
|
-
super
|
23
|
-
print_usage unless scaffold_name.underscore =~ /^[a-z][a-z0-9_\/]+$/
|
24
|
-
|
25
|
-
@datum_path = "test/lib/datum"
|
26
|
-
@model_attributes = []
|
27
|
-
@skip_model = options.skip_model?
|
28
|
-
|
29
|
-
args_for_m.each do |arg|
|
30
|
-
if arg.include?(':')
|
31
|
-
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
@model_attributes.uniq!
|
36
|
-
|
37
|
-
if @model_attributes.empty?
|
38
|
-
@skip_model = true # skip model if no attributes
|
39
|
-
if model_exists?
|
40
|
-
model_columns_for_attributes.each do |column|
|
41
|
-
@model_attributes << Rails::Generators::GeneratedAttribute.new(
|
42
|
-
column.name.to_s, column.type.to_s)
|
43
|
-
end
|
44
|
-
else
|
45
|
-
@model_attributes << Rails::Generators::GeneratedAttribute.new(
|
46
|
-
'name', 'string')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def create_model
|
52
|
-
unless @skip_model
|
53
|
-
template 'datum_model.rb', "#{@datum_path}/models/#{model_path}.rb"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
def create_migration
|
57
|
-
unless @skip_model || options.skip_migration?
|
58
|
-
migration_template 'datum_migration.rb',
|
59
|
-
"#{@datum_path}/migrate/create_#{model_path.pluralize.gsub('/', '_')}.rb"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def plural_name
|
66
|
-
scaffold_name.underscore.pluralize
|
67
|
-
end
|
68
|
-
|
69
|
-
def plural_class_name
|
70
|
-
plural_name.camelize
|
71
|
-
end
|
72
|
-
|
73
|
-
def table_name
|
74
|
-
if scaffold_name.include?('::') && @namespace_model
|
75
|
-
plural_name.gsub('/', '_')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def class_name
|
80
|
-
scaffold_name.split('::').last.camelize
|
81
|
-
end
|
82
|
-
|
83
|
-
def model_path
|
84
|
-
class_name.underscore
|
85
|
-
end
|
86
|
-
|
87
|
-
def model_exists?
|
88
|
-
File.exist? destination_path("#{@datum_path}/models/#{singular_name}.rb")
|
89
|
-
end
|
90
|
-
|
91
|
-
def destination_path(path)
|
92
|
-
File.join(destination_root, path)
|
93
|
-
end
|
94
|
-
|
95
|
-
# FIXME: Should be proxied to ActiveRecord::Generators::Base
|
96
|
-
# Implement the required interface for Rails::Generators::Migration.
|
97
|
-
def self.next_migration_number(dirname) #:nodoc:
|
98
|
-
if ActiveRecord::Base.timestamped_migrations
|
99
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
100
|
-
else
|
101
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
class Create<%= class_name.pluralize.delete('::') %> < ActiveRecord::Migration
|
3
|
-
|
4
|
-
ActiveRecord::Base.establish_connection :datum
|
5
|
-
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
6
|
-
|
7
|
-
def self.up
|
8
|
-
create_table :<%= table_name || plural_name.split('/').last %> do |t|
|
9
|
-
<%- for attribute in model_attributes -%>
|
10
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
11
|
-
<%- end -%>
|
12
|
-
<%- unless options[:skip_timestamps] -%>
|
13
|
-
t.timestamps
|
14
|
-
<%- end -%>
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.down
|
19
|
-
drop_table :<%= table_name || plural_name.split('/').last %>
|
20
|
-
end
|
21
|
-
end
|
data/lib/tasks/datum.rake
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require "datum/verification_task"
|
2
|
-
require "datum/enable_task"
|
3
|
-
require "datum/db_tasks"
|
4
|
-
|
5
|
-
namespace :datum do
|
6
|
-
|
7
|
-
desc "Enable datum functionality"
|
8
|
-
task :enable => :environment do
|
9
|
-
(Datum::EnableTask.new).rock
|
10
|
-
end
|
11
|
-
|
12
|
-
namespace :db do
|
13
|
-
|
14
|
-
desc "Create datum database"
|
15
|
-
task :create => :environment do invoke "create" end
|
16
|
-
|
17
|
-
desc "Migrate datum database"
|
18
|
-
task :migrate => :environment do invoke "migrate" end
|
19
|
-
|
20
|
-
desc "Drop datum database"
|
21
|
-
task :drop => :environment do invoke "drop" end
|
22
|
-
|
23
|
-
desc "Dump data as fixtures from datum database"
|
24
|
-
task :dump => :environment do invoke "dump" end
|
25
|
-
|
26
|
-
desc "Loads datum fixtures IF table is empty"
|
27
|
-
task :load_when_empty => :environment do invoke "load_when_empty" end
|
28
|
-
|
29
|
-
desc "Loads fixtures specific to datum database"
|
30
|
-
task :load => :environment do invoke "load" end
|
31
|
-
|
32
|
-
desc "Prepares datum for use via create, migrate, load"
|
33
|
-
task :prepare => :environment do invoke "prepare" end
|
34
|
-
|
35
|
-
#desc "Quick verification of basic datum functionality"
|
36
|
-
#task :verify do invoke "verify" end
|
37
|
-
|
38
|
-
desc "Enables datum execution without database dependency"
|
39
|
-
task :localize, [:table] => [:environment] do |t, args|
|
40
|
-
(Datum::DbTasks.new).localize args
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def invoke method
|
45
|
-
(Datum::DbTasks.new).send(method)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
data/test/datum_test.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
class DatumTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
#test "db_migrate should migrate" do
|
7
|
-
# puts "this is the second test...."
|
8
|
-
# Rake.application.rake_require "tasks/datum"
|
9
|
-
# DatumTasks.migrate
|
10
|
-
# assert_equal 0, 1, "Nope"
|
11
|
-
# puts "... Path: #{Rails.env}"
|
12
|
-
#end
|
13
|
-
|
14
|
-
# test "truth" do
|
15
|
-
# assert_kind_of Module, Datum
|
16
|
-
# end
|
17
|
-
end
|
data/test/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.
|
data/test/dummy/Rakefile
DELETED
@@ -1,7 +0,0 @@
|
|
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
|
@@ -1,15 +0,0 @@
|
|
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 .
|