user_query 0.1.0
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/ChangeLog +4 -0
- data/README +45 -0
- data/Rakefile +359 -0
- data/Releases +6 -0
- data/TODO +0 -0
- data/examples/userqueryex/HOWTO.txt +5 -0
- data/examples/userqueryex/README +183 -0
- data/examples/userqueryex/Rakefile +10 -0
- data/examples/userqueryex/WHAT.txt +16 -0
- data/examples/userqueryex/app/controllers/application.rb +4 -0
- data/examples/userqueryex/app/controllers/entries_controller.rb +68 -0
- data/examples/userqueryex/app/helpers/application_helper.rb +3 -0
- data/examples/userqueryex/app/helpers/entries_helper.rb +2 -0
- data/examples/userqueryex/app/models/entry.rb +8 -0
- data/examples/userqueryex/app/views/entries/_form.rhtml +20 -0
- data/examples/userqueryex/app/views/entries/edit.rhtml +9 -0
- data/examples/userqueryex/app/views/entries/list.rhtml +75 -0
- data/examples/userqueryex/app/views/entries/new.rhtml +8 -0
- data/examples/userqueryex/app/views/entries/show.rhtml +8 -0
- data/examples/userqueryex/app/views/layouts/entries.rhtml +13 -0
- data/examples/userqueryex/config/boot.rb +44 -0
- data/examples/userqueryex/config/database.yml +36 -0
- data/examples/userqueryex/config/environment.rb +54 -0
- data/examples/userqueryex/config/environments/development.rb +21 -0
- data/examples/userqueryex/config/environments/production.rb +18 -0
- data/examples/userqueryex/config/environments/test.rb +19 -0
- data/examples/userqueryex/config/routes.rb +22 -0
- data/examples/userqueryex/db/migrate/001_entry_migration.rb +16 -0
- data/examples/userqueryex/db/schema.rb +15 -0
- data/examples/userqueryex/doc/README_FOR_APP +2 -0
- data/examples/userqueryex/public/404.html +8 -0
- data/examples/userqueryex/public/500.html +8 -0
- data/examples/userqueryex/public/dispatch.cgi +10 -0
- data/examples/userqueryex/public/dispatch.fcgi +24 -0
- data/examples/userqueryex/public/dispatch.rb +10 -0
- data/examples/userqueryex/public/favicon.ico +0 -0
- data/examples/userqueryex/public/images/rails.png +0 -0
- data/examples/userqueryex/public/javascripts/application.js +2 -0
- data/examples/userqueryex/public/javascripts/controls.js +815 -0
- data/examples/userqueryex/public/javascripts/dragdrop.js +913 -0
- data/examples/userqueryex/public/javascripts/effects.js +958 -0
- data/examples/userqueryex/public/javascripts/prototype.js +2006 -0
- data/examples/userqueryex/public/robots.txt +1 -0
- data/examples/userqueryex/public/stylesheets/scaffold.css +74 -0
- data/examples/userqueryex/script/about +3 -0
- data/examples/userqueryex/script/breakpointer +3 -0
- data/examples/userqueryex/script/console +3 -0
- data/examples/userqueryex/script/destroy +3 -0
- data/examples/userqueryex/script/generate +3 -0
- data/examples/userqueryex/script/performance/benchmarker +3 -0
- data/examples/userqueryex/script/performance/profiler +3 -0
- data/examples/userqueryex/script/plugin +3 -0
- data/examples/userqueryex/script/process/reaper +3 -0
- data/examples/userqueryex/script/process/spawner +3 -0
- data/examples/userqueryex/script/runner +3 -0
- data/examples/userqueryex/script/server +3 -0
- data/examples/userqueryex/test/fixtures/entries.yml +5 -0
- data/examples/userqueryex/test/functional/entries_controller_test.rb +88 -0
- data/examples/userqueryex/test/test_helper.rb +28 -0
- data/examples/userqueryex/test/unit/entry_test.rb +10 -0
- data/lib/user_query.rb +10 -0
- data/lib/user_query/generator.rb +219 -0
- data/lib/user_query/parameters.rb +93 -0
- data/lib/user_query/parser.rb +762 -0
- data/lib/user_query/schema.rb +159 -0
- data/lib/user_query/user_query_version.rb +6 -0
- data/test/parser_test.rb +539 -0
- data/test/schema_test.rb +142 -0
- metadata +148 -0
data/ChangeLog
ADDED
data/README
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= UserQuery
|
2
|
+
|
3
|
+
This is the rubyforge.com UserQuery package.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install userquery
|
8
|
+
|
9
|
+
== For User Documentation, see
|
10
|
+
|
11
|
+
http://rubyforge.org/projects/userquery/
|
12
|
+
|
13
|
+
The RubyForge package userquery allows users to do general queries on SQL database table columns using a simple query language. The package parses tokens from the user's query and generates SQL WHERE clauses immune to SQL injection attacks.
|
14
|
+
|
15
|
+
For example, if a user wants to search for all entries records on a DATETIME field named date, the user can enter: "11/1/2006" into a text field associated with searching on the date column.
|
16
|
+
|
17
|
+
UserQuery will intuitively convert this query into an SQL WHERE clause fragment:
|
18
|
+
|
19
|
+
(
|
20
|
+
(entries.date >= '2006-11-01 00:00:00')
|
21
|
+
AND
|
22
|
+
(entries.date < '2006-11-02 00:00:00')
|
23
|
+
)
|
24
|
+
|
25
|
+
The user query syntax includes "NOT", "OR", "AND" operators, grouping with parentheses, well as relational operators like "LESS THAN 5" or ">= $500". Keyword searching, like "foo AND NOT 'bar baz'" using SQL LIKE operators is configurable.This package deals with currencies, conversions between currencies and monetary values in an object-oriented fashion.
|
26
|
+
|
27
|
+
== Home page
|
28
|
+
|
29
|
+
* {UserQuery Home}[http://userquery.rubyforge.org]
|
30
|
+
|
31
|
+
== Additional directories
|
32
|
+
|
33
|
+
[./lib/...] the UserQuery library
|
34
|
+
[./test/...] unit and functional test
|
35
|
+
[./examples/...] example programs
|
36
|
+
|
37
|
+
== Credits
|
38
|
+
|
39
|
+
UserQuery was developed by:
|
40
|
+
|
41
|
+
* Kurt Stephens -- ruby-userquery(at)umleta.com
|
42
|
+
|
43
|
+
== Contributors
|
44
|
+
|
45
|
+
Maybe you?
|
data/Rakefile
ADDED
@@ -0,0 +1,359 @@
|
|
1
|
+
# Rakefile for userquery -*- ruby -*-
|
2
|
+
# Adapted from RubyGems/Rakefile
|
3
|
+
# upload_package NOT WORKING YET
|
4
|
+
|
5
|
+
#################################################################
|
6
|
+
|
7
|
+
PKG_Name = 'UserQuery'
|
8
|
+
def package_version
|
9
|
+
'0.1.0'
|
10
|
+
end
|
11
|
+
def package_description
|
12
|
+
%{UserQuery generates SQL WHERE clauses from a simple user query expression. Can integrate with ActiveRecord or be used stand-alone.
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
#################################################################
|
17
|
+
|
18
|
+
#require 'rubygems'
|
19
|
+
require 'rake/clean'
|
20
|
+
require 'rake/testtask'
|
21
|
+
require 'rake/packagetask'
|
22
|
+
require 'rake/gempackagetask'
|
23
|
+
require 'rake/rdoctask'
|
24
|
+
|
25
|
+
#################################################################
|
26
|
+
|
27
|
+
|
28
|
+
def announce(msg='')
|
29
|
+
STDERR.puts msg
|
30
|
+
end
|
31
|
+
|
32
|
+
PKG_NAME = PKG_Name.gsub(/[a-z][A-Z]/) {|x| "#{x[0,1]}_#{x[1,1]}"}.downcase
|
33
|
+
RUBY_FORGE_PROJECT = PKG_NAME
|
34
|
+
|
35
|
+
if ENV['REL']
|
36
|
+
PKG_VERSION = ENV['REL']
|
37
|
+
CURRENT_VERSION = package_version
|
38
|
+
else
|
39
|
+
PKG_VERSION = package_version
|
40
|
+
CURRENT_VERSION = PKG_VERSION
|
41
|
+
end
|
42
|
+
|
43
|
+
CLEAN.include("COMMENTS")
|
44
|
+
CLOBBER.include(
|
45
|
+
"test/data",
|
46
|
+
"test/temp",
|
47
|
+
'scripts/*.hieraki',
|
48
|
+
'data__',
|
49
|
+
'html',
|
50
|
+
'pkgs/sources/sources*.gem',
|
51
|
+
'.config',
|
52
|
+
'**/debug.log',
|
53
|
+
'**/development.log',
|
54
|
+
'logs'
|
55
|
+
)
|
56
|
+
|
57
|
+
task :default => [:test]
|
58
|
+
|
59
|
+
Rake::TestTask.new(:test) do |t|
|
60
|
+
t.test_files = FileList['test/*test*.rb']
|
61
|
+
end
|
62
|
+
|
63
|
+
Rake::TestTask.new(:functional) do |t|
|
64
|
+
t.test_files = FileList['test/functional*.rb']
|
65
|
+
end
|
66
|
+
|
67
|
+
Rake::TestTask.new(:alltests) do |t|
|
68
|
+
t.test_files = FileList['test/{*test,functional}*.rb']
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Run the tests for a build"
|
72
|
+
task :build_tests do
|
73
|
+
html_dir = ENV['TESTRESULTS'] || 'html/tests'
|
74
|
+
ruby %{-Ilib scripts/buildtests.rb #{html_dir}}
|
75
|
+
open("#{html_dir}/summary.html") do |inf|
|
76
|
+
open("#{html_dir}/summary.new", "w") do |outf|
|
77
|
+
inf.each do |line|
|
78
|
+
if line =~ /td align/
|
79
|
+
line = " <td align=\"left\">#{Time.now}</td><td align=\"right\">"
|
80
|
+
end
|
81
|
+
outf.puts line
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
mv "#{html_dir}/summary.html", "#{html_dir}/summary.old"
|
86
|
+
mv "#{html_dir}/summary.new", "#{html_dir}/summary.html"
|
87
|
+
end
|
88
|
+
|
89
|
+
# Shortcuts for test targets
|
90
|
+
task :tf => [:functional]
|
91
|
+
task :tu => [:test]
|
92
|
+
task :ta => [:alltests]
|
93
|
+
|
94
|
+
task :gemtest do
|
95
|
+
ruby %{-Ilib -rscripts/runtest -e 'run_tests("test/test_gempaths.rb", true)'}
|
96
|
+
end
|
97
|
+
|
98
|
+
# --------------------------------------------------------------------
|
99
|
+
# Creating a release
|
100
|
+
|
101
|
+
desc "Make a new release"
|
102
|
+
task :release => [
|
103
|
+
:prerelease,
|
104
|
+
:clobber,
|
105
|
+
:alltests,
|
106
|
+
:update_version,
|
107
|
+
:package,
|
108
|
+
:tag] do
|
109
|
+
|
110
|
+
announce
|
111
|
+
announce "**************************************************************"
|
112
|
+
announce "* Release #{PKG_VERSION} Complete."
|
113
|
+
announce "* Packages ready to upload."
|
114
|
+
announce "**************************************************************"
|
115
|
+
announce
|
116
|
+
end
|
117
|
+
|
118
|
+
# Validate that everything is ready to go for a release.
|
119
|
+
task :prerelease do
|
120
|
+
announce
|
121
|
+
announce "**************************************************************"
|
122
|
+
announce "* Making #{PKG_Name} Release #{PKG_VERSION}"
|
123
|
+
announce "* (current version #{CURRENT_VERSION})"
|
124
|
+
announce "**************************************************************"
|
125
|
+
announce
|
126
|
+
|
127
|
+
# Is a release number supplied?
|
128
|
+
unless ENV['REL']
|
129
|
+
fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
|
130
|
+
end
|
131
|
+
|
132
|
+
# Is the release different than the current release.
|
133
|
+
# (or is REUSE set?)
|
134
|
+
if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
|
135
|
+
fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
|
136
|
+
end
|
137
|
+
|
138
|
+
# Are all source files checked in?
|
139
|
+
if ENV['RELTEST']
|
140
|
+
announce "Release Task Testing, skipping checked-in file test"
|
141
|
+
else
|
142
|
+
announce "Checking for unchecked-in files..."
|
143
|
+
data = `set -x; svn status | grep -v '?'`
|
144
|
+
unless data =~ /^$/
|
145
|
+
fail "svn status is not clean ... do you have unchecked-in files?"
|
146
|
+
end
|
147
|
+
announce "No outstanding checkins found ... OK"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
task :update_version => [:prerelease] do
|
152
|
+
if PKG_VERSION == CURRENT_VERSION && ! ENV['FORCE']
|
153
|
+
announce "No version change ... skipping version update"
|
154
|
+
else
|
155
|
+
announce "Updating #{PKG_Name} version to #{PKG_VERSION}"
|
156
|
+
version_rb = "lib/#{PKG_NAME}/#{PKG_NAME}_version.rb"
|
157
|
+
open(version_rb, "w") do |f|
|
158
|
+
f.puts "# DO NOT EDIT"
|
159
|
+
f.puts "# This file is auto-generated by build scripts."
|
160
|
+
f.puts "# See: rake update_version"
|
161
|
+
f.puts "module #{PKG_Name}"
|
162
|
+
f.puts " #{PKG_Name}Version = '#{PKG_VERSION}'"
|
163
|
+
f.puts "end"
|
164
|
+
end
|
165
|
+
if ENV['RELTEST']
|
166
|
+
announce "Release Task Testing, skipping commiting of new version"
|
167
|
+
else
|
168
|
+
sh %{svn commit -m "Updated to version #{PKG_VERSION}" #{version_rb}}
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# FIX ME for SVN
|
174
|
+
task :tag => [:prerelease] do
|
175
|
+
reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
|
176
|
+
reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE']
|
177
|
+
announce "Tagging repo with [#{reltag}]"
|
178
|
+
if ENV['RELTEST']
|
179
|
+
announce "Release Task Testing, skipping repo tagging"
|
180
|
+
else
|
181
|
+
sh %{echo cvs tag #{reltag}}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# --------------------------------------------------------------------
|
186
|
+
# Create a task to build the RDOC documentation tree.
|
187
|
+
|
188
|
+
desc "Create the RDOC html files"
|
189
|
+
rd = Rake::RDocTask.new("rdoc") { |rdoc|
|
190
|
+
rdoc.rdoc_dir = 'html'
|
191
|
+
rdoc.title = "#{PKG_Name}"
|
192
|
+
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
193
|
+
rdoc.rdoc_files.include('README', 'TODO', 'Releases')
|
194
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
195
|
+
# rdoc.rdoc_files.include('test/**/*.rb')
|
196
|
+
}
|
197
|
+
|
198
|
+
file "html/index.html" => [:rdoc]
|
199
|
+
|
200
|
+
desc "Publish the RDOCs on RubyForge"
|
201
|
+
task :publish_rdoc => ["html/index.html"] do
|
202
|
+
# NOTE: This task assumes that you have an SSH alias setup for rubyforge.
|
203
|
+
mkdir_p "emptydir"
|
204
|
+
sh "scp -rq emptydir rubyforge:/var/www/gforge-projects/#{RUBY_FORGE_PROJECT}/rdoc"
|
205
|
+
sh "scp -rq html/* rubyforge:/var/www/gforge-projects/#{RUBY_FORGE_PROJECT}/rdoc"
|
206
|
+
rm_r "emptydir"
|
207
|
+
end
|
208
|
+
|
209
|
+
# Wiki Doc Targets
|
210
|
+
|
211
|
+
desc "Upload the Hieraki Data"
|
212
|
+
task :upload => [:upload_gemdoc]
|
213
|
+
|
214
|
+
task :upload_gemdoc => ['scripts/gemdoc.hieraki'] do
|
215
|
+
ruby %{scripts/upload_gemdoc.rb}
|
216
|
+
end
|
217
|
+
|
218
|
+
desc "Build the Hieraki documentation"
|
219
|
+
task :hieraki => ['scripts/gemdoc.hieraki', 'scripts/specdoc.hieraki']
|
220
|
+
|
221
|
+
file 'scripts/gemdoc.hieraki' => ['scripts/gemdoc.rb', 'scripts/gemdoc.data'] do
|
222
|
+
chdir('scripts') do
|
223
|
+
ruby %{-I../lib gemdoc.rb <gemdoc.data >gemdoc.hieraki}
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
file 'scripts/specdoc.hieraki' =>
|
228
|
+
['scripts/specdoc.rb', 'scripts/specdoc.data', 'scripts/specdoc.yaml'] do
|
229
|
+
chdir('scripts') do
|
230
|
+
ruby %{-I../lib specdoc.rb >specdoc.hieraki}
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# Package tasks
|
235
|
+
|
236
|
+
PKG_FILES = FileList[
|
237
|
+
"Rakefile", "ChangeLog", "Releases", "TODO", "README",
|
238
|
+
# "setup.rb",
|
239
|
+
# "post-install.rb",
|
240
|
+
"bin/*",
|
241
|
+
"doc/*.css", "doc/*.rb",
|
242
|
+
"examples/**/*",
|
243
|
+
# "gemspecs/**/*",
|
244
|
+
"lib/**/*.rb",
|
245
|
+
# "pkgs/**/*",
|
246
|
+
"redist/*.gem",
|
247
|
+
"scripts/*.rb",
|
248
|
+
"test/**/*"
|
249
|
+
]
|
250
|
+
PKG_FILES.exclude(%r(^(test/temp|examples/.*/*.log)(/|$)))
|
251
|
+
|
252
|
+
Rake::PackageTask.new("package") do |p|
|
253
|
+
p.name = PKG_NAME
|
254
|
+
p.version = PKG_VERSION
|
255
|
+
p.need_tar = true
|
256
|
+
p.need_zip = true
|
257
|
+
p.package_files = PKG_FILES
|
258
|
+
end
|
259
|
+
|
260
|
+
Spec = Gem::Specification.new do |s|
|
261
|
+
s.name = PKG_NAME
|
262
|
+
s.version = PKG_VERSION
|
263
|
+
s.summary = "#{PKG_Name} GEM"
|
264
|
+
s.description = package_description
|
265
|
+
s.files = PKG_FILES.to_a
|
266
|
+
s.require_path = 'lib'
|
267
|
+
s.author = "Kurt Stephens"
|
268
|
+
s.email = "ruby-#{PKG_NAME}@umleta.com"
|
269
|
+
s.homepage = "http://#{PKG_NAME}.rubyforge.org"
|
270
|
+
s.rubyforge_project = "#{RUBY_FORGE_PROJECT}"
|
271
|
+
#s.bindir = "bin" # Use these for applications.
|
272
|
+
#s.executables = ["update_rubygems"]
|
273
|
+
certdir = ENV['CERT_DIR']
|
274
|
+
if certdir
|
275
|
+
s.signing_key = File.join(certdir, 'gem-umleta-private_key.pem')
|
276
|
+
s.cert_chain = [File.join(certdir, 'gem-umleta-public_cert.pem')]
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
# Add console output about signing the Gem
|
281
|
+
file "pkg/#{Spec.full_name}.gem" do
|
282
|
+
puts "Signed with certificates in '#{ENV['CERT_DIR']}'" if ENV['CERT_DIR']
|
283
|
+
end
|
284
|
+
|
285
|
+
Rake::GemPackageTask.new(Spec) do |p| end
|
286
|
+
|
287
|
+
GEMSPEC = "pkg/#{PKG_NAME}.gemspec"
|
288
|
+
desc "Build the Gem spec file for the #{PKG_NAME} package"
|
289
|
+
task :gemspec => GEMSPEC
|
290
|
+
file "pkg/#{PKG_NAME}.gemspec" => ["pkg", "Rakefile"] do |t|
|
291
|
+
open(t.name, "w") do |f| f.puts Spec.to_yaml end
|
292
|
+
end
|
293
|
+
|
294
|
+
# Automated upload to rubyforge.org
|
295
|
+
PACKAGE_FILES = FileList["pkg/#{PKG_NAME}-#{PKG_VERSION}.*"]
|
296
|
+
task :upload_package do
|
297
|
+
# From activesuport/Rakefile,
|
298
|
+
# See: http://dev.rubyonrails.org/svn/rails/tags/rel_1-1-6/activesupport/Rakefile
|
299
|
+
`rubyforge login`
|
300
|
+
|
301
|
+
files = PACKAGE_FILES
|
302
|
+
files.each do |filename|
|
303
|
+
basename = File.basename(filename)
|
304
|
+
puts "Releasing #{basename}..."
|
305
|
+
|
306
|
+
release_command = "rubyforge add_release #{RUBY_FORGE_PROJECT} #{RUBY_FORGE_PROJECT} 'REL #{PKG_VERSION}' #{filename}"
|
307
|
+
puts release_command
|
308
|
+
system(release_command)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
desc "Install #{PKG_Name}"
|
314
|
+
task :install do
|
315
|
+
ruby 'install.rb'
|
316
|
+
end
|
317
|
+
|
318
|
+
# Run 'gem' (using local bin and lib directories).
|
319
|
+
# e.g.
|
320
|
+
# rake rungem -- install -r blahblah --test
|
321
|
+
|
322
|
+
desc "Run local 'gem'"
|
323
|
+
task :rungem do
|
324
|
+
ARGV.shift
|
325
|
+
exec "ruby -Ilib bin/gem #{ARGV.join(' ')}"
|
326
|
+
end
|
327
|
+
|
328
|
+
# Misc Tasks ---------------------------------------------------------
|
329
|
+
|
330
|
+
def egrep(pattern)
|
331
|
+
Dir['**/*.rb'].each do |fn|
|
332
|
+
count = 0
|
333
|
+
open(fn) do |f|
|
334
|
+
while line = f.gets
|
335
|
+
count += 1
|
336
|
+
if line =~ pattern
|
337
|
+
puts "#{fn}:#{count}:#{line}"
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
desc "Look for TODO and FIXME tags in the code"
|
345
|
+
task :todo do
|
346
|
+
egrep /#.*(FIXME|TODO|TBD)/
|
347
|
+
end
|
348
|
+
|
349
|
+
desc "Look for Debugging print lines"
|
350
|
+
task :dbg do
|
351
|
+
egrep /\bDBG|\bbreakpoint\b/
|
352
|
+
end
|
353
|
+
|
354
|
+
desc "List all ruby files"
|
355
|
+
task :rubyfiles do
|
356
|
+
puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
|
357
|
+
puts Dir['bin/*'].reject { |fn| fn =~ /CVS|.svn|(~$)|(\.rb$)/ }
|
358
|
+
end
|
359
|
+
|
data/Releases
ADDED
data/TODO
ADDED
File without changes
|
@@ -0,0 +1,183 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application and persistence framework that includes everything
|
4
|
+
needed to create database-backed web-applications according to the
|
5
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
6
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
7
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
8
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
9
|
+
the business logic and knows how to persist themselves to a database. The
|
10
|
+
controller handles the incoming requests (such as Save New Account, Update
|
11
|
+
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. Start the web server: <tt>ruby script/server</tt> (run with --help for options)
|
31
|
+
2. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
|
32
|
+
3. Follow the guidelines to start developing your application
|
33
|
+
|
34
|
+
|
35
|
+
== Web servers
|
36
|
+
|
37
|
+
Rails uses the built-in web server in Ruby called WEBrick by default, so you don't
|
38
|
+
have to install or configure anything to play around.
|
39
|
+
|
40
|
+
If you have lighttpd installed, though, it'll be used instead when running script/server.
|
41
|
+
It's considerably faster than WEBrick and suited for production use, but requires additional
|
42
|
+
installation and currently only works well on OS X/Unix (Windows users are encouraged
|
43
|
+
to start with WEBrick). We recommend version 1.4.11 and higher. You can download it from
|
44
|
+
http://www.lighttpd.net.
|
45
|
+
|
46
|
+
If you want something that's halfway between WEBrick and lighttpd, we heartily recommend
|
47
|
+
Mongrel. It's a Ruby-based web server with a C-component (so it requires compilation) that
|
48
|
+
also works very well with Windows. See more at http://mongrel.rubyforge.org/.
|
49
|
+
|
50
|
+
But of course its also possible to run Rails with the premiere open source web server Apache.
|
51
|
+
To get decent performance, though, you'll need to install FastCGI. For Apache 1.3, you want
|
52
|
+
to use mod_fastcgi. For Apache 2.0+, you want to use mod_fcgid.
|
53
|
+
|
54
|
+
See http://wiki.rubyonrails.com/rails/pages/FastCGI for more information on FastCGI.
|
55
|
+
|
56
|
+
== Example for Apache conf
|
57
|
+
|
58
|
+
<VirtualHost *:80>
|
59
|
+
ServerName rails
|
60
|
+
DocumentRoot /path/application/public/
|
61
|
+
ErrorLog /path/application/log/server.log
|
62
|
+
|
63
|
+
<Directory /path/application/public/>
|
64
|
+
Options ExecCGI FollowSymLinks
|
65
|
+
AllowOverride all
|
66
|
+
Allow from all
|
67
|
+
Order allow,deny
|
68
|
+
</Directory>
|
69
|
+
</VirtualHost>
|
70
|
+
|
71
|
+
NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
|
72
|
+
should be on and ".cgi" should respond. All requests from 127.0.0.1 go
|
73
|
+
through CGI, so no Apache restart is necessary for changes. All other requests
|
74
|
+
go through FCGI (or mod_ruby), which requires a restart to show changes.
|
75
|
+
|
76
|
+
|
77
|
+
== Debugging Rails
|
78
|
+
|
79
|
+
Have "tail -f" commands running on both the server.log, production.log, and
|
80
|
+
test.log files. Rails will automatically display debugging and runtime
|
81
|
+
information to these files. Debugging info will also be shown in the browser
|
82
|
+
on requests from 127.0.0.1.
|
83
|
+
|
84
|
+
|
85
|
+
== Breakpoints
|
86
|
+
|
87
|
+
Breakpoint support is available through the script/breakpointer client. This
|
88
|
+
means that you can break out of execution at any point in the code, investigate
|
89
|
+
and change the model, AND then resume execution! Example:
|
90
|
+
|
91
|
+
class WeblogController < ActionController::Base
|
92
|
+
def index
|
93
|
+
@posts = Post.find_all
|
94
|
+
breakpoint "Breaking out from the list"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
So the controller will accept the action, run the first line, then present you
|
99
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
100
|
+
|
101
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
102
|
+
|
103
|
+
>> @posts.inspect
|
104
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
105
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
106
|
+
>> @posts.first.title = "hello from a breakpoint"
|
107
|
+
=> "hello from a breakpoint"
|
108
|
+
|
109
|
+
...and even better is that you can examine how your runtime objects actually work:
|
110
|
+
|
111
|
+
>> f = @posts.first
|
112
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
113
|
+
>> f.
|
114
|
+
Display all 152 possibilities? (y or n)
|
115
|
+
|
116
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
117
|
+
|
118
|
+
|
119
|
+
== Console
|
120
|
+
|
121
|
+
You can interact with the domain model by starting the console through script/console.
|
122
|
+
Here you'll have all parts of the application configured, just like it is when the
|
123
|
+
application is running. You can inspect domain models, change values, and save to the
|
124
|
+
database. Starting the script without arguments will launch it in the development environment.
|
125
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
126
|
+
|
127
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
== Description of contents
|
132
|
+
|
133
|
+
app
|
134
|
+
Holds all the code that's specific to this particular application.
|
135
|
+
|
136
|
+
app/controllers
|
137
|
+
Holds controllers that should be named like weblog_controller.rb for
|
138
|
+
automated URL mapping. All controllers should descend from
|
139
|
+
ActionController::Base.
|
140
|
+
|
141
|
+
app/models
|
142
|
+
Holds models that should be named like post.rb.
|
143
|
+
Most models will descend from ActiveRecord::Base.
|
144
|
+
|
145
|
+
app/views
|
146
|
+
Holds the template files for the view that should be named like
|
147
|
+
weblog/index.rhtml for the WeblogController#index action. All views use eRuby
|
148
|
+
syntax. This directory can also be used to keep stylesheets, images, and so on
|
149
|
+
that can be symlinked to public.
|
150
|
+
|
151
|
+
app/helpers
|
152
|
+
Holds view helpers that should be named like weblog_helper.rb.
|
153
|
+
|
154
|
+
app/apis
|
155
|
+
Holds API classes for web services.
|
156
|
+
|
157
|
+
config
|
158
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
159
|
+
|
160
|
+
components
|
161
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
162
|
+
|
163
|
+
db
|
164
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
165
|
+
the sequence of Migrations for your schema.
|
166
|
+
|
167
|
+
lib
|
168
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
169
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
170
|
+
|
171
|
+
public
|
172
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
173
|
+
and javascripts. Also contains the dispatchers and the default HTML files.
|
174
|
+
|
175
|
+
script
|
176
|
+
Helper scripts for automation and generation.
|
177
|
+
|
178
|
+
test
|
179
|
+
Unit and functional tests along with fixtures.
|
180
|
+
|
181
|
+
vendor
|
182
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
183
|
+
This directory is in the load path.
|