user_query 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/ChangeLog +4 -0
  2. data/README +45 -0
  3. data/Rakefile +359 -0
  4. data/Releases +6 -0
  5. data/TODO +0 -0
  6. data/examples/userqueryex/HOWTO.txt +5 -0
  7. data/examples/userqueryex/README +183 -0
  8. data/examples/userqueryex/Rakefile +10 -0
  9. data/examples/userqueryex/WHAT.txt +16 -0
  10. data/examples/userqueryex/app/controllers/application.rb +4 -0
  11. data/examples/userqueryex/app/controllers/entries_controller.rb +68 -0
  12. data/examples/userqueryex/app/helpers/application_helper.rb +3 -0
  13. data/examples/userqueryex/app/helpers/entries_helper.rb +2 -0
  14. data/examples/userqueryex/app/models/entry.rb +8 -0
  15. data/examples/userqueryex/app/views/entries/_form.rhtml +20 -0
  16. data/examples/userqueryex/app/views/entries/edit.rhtml +9 -0
  17. data/examples/userqueryex/app/views/entries/list.rhtml +75 -0
  18. data/examples/userqueryex/app/views/entries/new.rhtml +8 -0
  19. data/examples/userqueryex/app/views/entries/show.rhtml +8 -0
  20. data/examples/userqueryex/app/views/layouts/entries.rhtml +13 -0
  21. data/examples/userqueryex/config/boot.rb +44 -0
  22. data/examples/userqueryex/config/database.yml +36 -0
  23. data/examples/userqueryex/config/environment.rb +54 -0
  24. data/examples/userqueryex/config/environments/development.rb +21 -0
  25. data/examples/userqueryex/config/environments/production.rb +18 -0
  26. data/examples/userqueryex/config/environments/test.rb +19 -0
  27. data/examples/userqueryex/config/routes.rb +22 -0
  28. data/examples/userqueryex/db/migrate/001_entry_migration.rb +16 -0
  29. data/examples/userqueryex/db/schema.rb +15 -0
  30. data/examples/userqueryex/doc/README_FOR_APP +2 -0
  31. data/examples/userqueryex/public/404.html +8 -0
  32. data/examples/userqueryex/public/500.html +8 -0
  33. data/examples/userqueryex/public/dispatch.cgi +10 -0
  34. data/examples/userqueryex/public/dispatch.fcgi +24 -0
  35. data/examples/userqueryex/public/dispatch.rb +10 -0
  36. data/examples/userqueryex/public/favicon.ico +0 -0
  37. data/examples/userqueryex/public/images/rails.png +0 -0
  38. data/examples/userqueryex/public/javascripts/application.js +2 -0
  39. data/examples/userqueryex/public/javascripts/controls.js +815 -0
  40. data/examples/userqueryex/public/javascripts/dragdrop.js +913 -0
  41. data/examples/userqueryex/public/javascripts/effects.js +958 -0
  42. data/examples/userqueryex/public/javascripts/prototype.js +2006 -0
  43. data/examples/userqueryex/public/robots.txt +1 -0
  44. data/examples/userqueryex/public/stylesheets/scaffold.css +74 -0
  45. data/examples/userqueryex/script/about +3 -0
  46. data/examples/userqueryex/script/breakpointer +3 -0
  47. data/examples/userqueryex/script/console +3 -0
  48. data/examples/userqueryex/script/destroy +3 -0
  49. data/examples/userqueryex/script/generate +3 -0
  50. data/examples/userqueryex/script/performance/benchmarker +3 -0
  51. data/examples/userqueryex/script/performance/profiler +3 -0
  52. data/examples/userqueryex/script/plugin +3 -0
  53. data/examples/userqueryex/script/process/reaper +3 -0
  54. data/examples/userqueryex/script/process/spawner +3 -0
  55. data/examples/userqueryex/script/runner +3 -0
  56. data/examples/userqueryex/script/server +3 -0
  57. data/examples/userqueryex/test/fixtures/entries.yml +5 -0
  58. data/examples/userqueryex/test/functional/entries_controller_test.rb +88 -0
  59. data/examples/userqueryex/test/test_helper.rb +28 -0
  60. data/examples/userqueryex/test/unit/entry_test.rb +10 -0
  61. data/lib/user_query.rb +10 -0
  62. data/lib/user_query/generator.rb +219 -0
  63. data/lib/user_query/parameters.rb +93 -0
  64. data/lib/user_query/parser.rb +762 -0
  65. data/lib/user_query/schema.rb +159 -0
  66. data/lib/user_query/user_query_version.rb +6 -0
  67. data/test/parser_test.rb +539 -0
  68. data/test/schema_test.rb +142 -0
  69. metadata +148 -0
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,16 @@
1
+ rails userqueryex
2
+ svn add userqueryex
3
+ svn ci -m 'UserQuery Example.'
4
+ svn rm --force log/
5
+ svn ci -m 'Remove log/ from svn.' log
6
+
7
+ # edit config/database.yml
8
+ script/generate migration Foo
9
+ rake migrate
10
+
11
+ script/generate scaffold Entry
12
+ svn status | grep '?' | cut -d' ' -f 7- | xargs svn add
13
+
14
+ svn rm --force public/index.html
15
+ # edit config/routes.rb # map.connect '', :controller => 'entries'
16
+
@@ -0,0 +1,4 @@
1
+ # Filters added to this controller will be run for all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+ class ApplicationController < ActionController::Base
4
+ end
@@ -0,0 +1,68 @@
1
+ require 'user_query'
2
+
3
+ class EntriesController < ApplicationController
4
+ def index
5
+ list
6
+ render :action => 'list'
7
+ end
8
+
9
+ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
10
+ verify :method => :post, :only => [ :destroy, :create, :update ],
11
+ :redirect_to => { :action => :list }
12
+
13
+ def list
14
+ @query = UserQuery::Parameters.new(params[:query] ||= { })
15
+
16
+ @q_sql = UserQuery::Schema.
17
+ new(:table => Entry,
18
+ :field => [
19
+ [ :amount, :money ] # override AR::B introspection
20
+ ]
21
+ ).sql(@query)
22
+
23
+ # $stderr.puts "q_sql = #{@q_sql.inspect}"
24
+ @entry_pages, @entries =
25
+ paginate :entries,
26
+ :per_page => 10, # Malformed format string
27
+ :conditions => [ @q_sql ? @q_sql.gsub(/%/, '%%') : '1' ],
28
+ :order => 'id'
29
+
30
+ end
31
+
32
+ def show
33
+ @entry = Entry.find(params[:id])
34
+ end
35
+
36
+ def new
37
+ @entry = Entry.new
38
+ end
39
+
40
+ def create
41
+ @entry = Entry.new(params[:entry])
42
+ if @entry.save
43
+ flash[:notice] = 'Entry was successfully created.'
44
+ redirect_to :action => 'list'
45
+ else
46
+ render :action => 'new'
47
+ end
48
+ end
49
+
50
+ def edit
51
+ @entry = Entry.find(params[:id])
52
+ end
53
+
54
+ def update
55
+ @entry = Entry.find(params[:id])
56
+ if @entry.update_attributes(params[:entry])
57
+ flash[:notice] = 'Entry was successfully updated.'
58
+ redirect_to :action => 'show', :id => @entry
59
+ else
60
+ render :action => 'edit'
61
+ end
62
+ end
63
+
64
+ def destroy
65
+ Entry.find(params[:id]).destroy
66
+ redirect_to :action => 'list'
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module EntriesHelper
2
+ end
@@ -0,0 +1,8 @@
1
+ require 'currency'
2
+ require 'currency/active_record'
3
+
4
+ class Entry < ActiveRecord::Base
5
+ money :amount
6
+ end
7
+
8
+
@@ -0,0 +1,20 @@
1
+ <%= error_messages_for 'entry' %>
2
+
3
+ <!--[form:entry]-->
4
+ <p><label for="entry_name">Name</label><br/>
5
+ <%= text_field 'entry', 'name' %></p>
6
+
7
+ <p><label for="entry_date">Date</label><br/>
8
+ <%= datetime_select 'entry', 'date' %></p>
9
+
10
+ <p><label for="entry_memo">Memo</label><br/>
11
+ <%= text_area 'entry', 'memo' %></p>
12
+
13
+ <p><label for="entry_amount">Amount</label><br/>
14
+ <%= text_field 'entry', 'amount' %></p>
15
+
16
+ <p><label for="entry_approved">Approved</label><br/>
17
+ <%= check_box 'entry', 'approved' %></p>
18
+
19
+ <!--[eoform:entry]-->
20
+
@@ -0,0 +1,9 @@
1
+ <h1>Editing entry</h1>
2
+
3
+ <%= start_form_tag :action => 'update', :id => @entry %>
4
+ <%= render :partial => 'form' %>
5
+ <%= submit_tag 'Edit' %>
6
+ <%= end_form_tag %>
7
+
8
+ <%= link_to 'Show', :action => 'show', :id => @entry %> |
9
+ <%= link_to 'Back', :action => 'list' %>
@@ -0,0 +1,75 @@
1
+ <h1>Listing entries</h1>
2
+
3
+ <%= start_form_tag :action => 'list' %>
4
+
5
+ <%= error_messages_for 'query' %>
6
+
7
+ <table>
8
+ <tr>
9
+ <td colspan="9">
10
+ <%= pagination_links(@entry_pages) %>
11
+ </td>
12
+ </tr>
13
+
14
+ <tr>
15
+ <th>ID</th>
16
+ <% for column in Entry.content_columns %>
17
+ <th><%= column.human_name %></th>
18
+ <% end %>
19
+ </tr>
20
+
21
+ <tr>
22
+ <td align="right"><%= text_field 'query', 'id', :size => 4 %></td>
23
+ <td align="left"><%= text_field 'query', 'name', :size => 10 %></td>
24
+ <td align="left"><%= text_field 'query', 'date', :size => 20 %></td>
25
+ <td align="left"><%= text_field 'query', 'memo', :size => 20 %></td>
26
+ <td align="right"><%= text_field 'query', 'amount', :size => 10 %></td>
27
+ <td align="right"><%=
28
+ q_bool = @query.approved
29
+ if q_bool.nil? || q_bool.to_s.empty?
30
+ q_bool = ''
31
+ elsif q_bool.to_s.upcase == 'TRUE'
32
+ q_bool = 'TRUE'
33
+ elsif q_bool.to_s.upcase == 'FALSE'
34
+ q_bool = 'FALSE'
35
+ end
36
+
37
+ select_tag 'query[approved]', [ '', 'TRUE', 'FALSE' ].
38
+ map{|x|
39
+ '<option' +
40
+ (q_bool == x ? ' SELECTED="1"' : '') +
41
+ '>' +
42
+ x.to_s.upcase +
43
+ '</option>'}.join('')
44
+ %></td>
45
+ <td align="left" colspan="3"><%= submit_tag 'Search' %></td>
46
+ </tr>
47
+
48
+ <% for entry in @entries %>
49
+ <tr>
50
+ <td align="right"><%=h entry.id %></td>
51
+ <td><%=h entry.name %></td>
52
+ <td><%=h entry.date.strftime('%Y/%m/%d-%H:%M:%S') %></td>
53
+ <td><%=h entry.memo %></td>
54
+ <td align="right"><%=h entry.amount %></td>
55
+ <td align="right"><%= check_box_tag '_dummy', '', entry.approved, :disabled => true %>|</td>
56
+ <td><%= link_to 'Show', :action => 'show', :id => entry %></td>
57
+ <td><%= link_to 'Edit', :action => 'edit', :id => entry %></td>
58
+ <td><%= link_to 'Destroy', { :action => 'destroy', :id => entry }, :confirm => 'Are you sure?', :post => true %></td>
59
+ </tr>
60
+ <% end %>
61
+ </table>
62
+
63
+ <%= link_to 'Previous page', { :page => @entry_pages.current.previous } if @entry_pages.current.previous %>
64
+ <%= link_to 'Next page', { :page => @entry_pages.current.next } if @entry_pages.current.next %>
65
+
66
+ <br />
67
+
68
+ <%= link_to 'New entry', :action => 'new' %>
69
+
70
+ <h2>UserQuery SQL</h2>
71
+ <pre>
72
+ <%=h @q_sql %>
73
+ </pre>
74
+
75
+ <%= end_form_tag %>
@@ -0,0 +1,8 @@
1
+ <h1>New entry</h1>
2
+
3
+ <%= start_form_tag :action => 'create' %>
4
+ <%= render :partial => 'form' %>
5
+ <%= submit_tag "Create" %>
6
+ <%= end_form_tag %>
7
+
8
+ <%= link_to 'Back', :action => 'list' %>
@@ -0,0 +1,8 @@
1
+ <% for column in Entry.content_columns %>
2
+ <p>
3
+ <b><%= column.human_name %>:</b> <%=h @entry.send(column.name) %>
4
+ </p>
5
+ <% end %>
6
+
7
+ <%= link_to 'Edit', :action => 'edit', :id => @entry %> |
8
+ <%= link_to 'Back', :action => 'list' %>
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <title>Entries: <%= controller.action_name %></title>
4
+ <%= stylesheet_link_tag 'scaffold' %>
5
+ </head>
6
+ <body>
7
+
8
+ <p style="color: green"><%= flash[:notice] %></p>
9
+
10
+ <%= yield %>
11
+
12
+ </body>
13
+ </html>
@@ -0,0 +1,44 @@
1
+ # Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
2
+
3
+ unless defined?(RAILS_ROOT)
4
+ root_path = File.join(File.dirname(__FILE__), '..')
5
+
6
+ unless RUBY_PLATFORM =~ /mswin32/
7
+ require 'pathname'
8
+ root_path = Pathname.new(root_path).cleanpath(true).to_s
9
+ end
10
+
11
+ RAILS_ROOT = root_path
12
+ end
13
+
14
+ unless defined?(Rails::Initializer)
15
+ if File.directory?("#{RAILS_ROOT}/vendor/rails")
16
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
17
+ else
18
+ require 'rubygems'
19
+
20
+ environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
21
+ environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
22
+ rails_gem_version = $1
23
+
24
+ if version = defined?(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : rails_gem_version
25
+ rails_gem = Gem.cache.search('rails', "=#{version}").first
26
+
27
+ if rails_gem
28
+ require_gem "rails", "=#{version}"
29
+ require rails_gem.full_gem_path + '/lib/initializer'
30
+ else
31
+ STDERR.puts %(Cannot find gem for Rails =#{version}:
32
+ Install the missing gem with 'gem install -v=#{version} rails', or
33
+ change environment.rb to define RAILS_GEM_VERSION with your desired version.
34
+ )
35
+ exit 1
36
+ end
37
+ else
38
+ require_gem "rails"
39
+ require 'initializer'
40
+ end
41
+ end
42
+
43
+ Rails::Initializer.run(:set_load_path)
44
+ end
@@ -0,0 +1,36 @@
1
+ # $Id$
2
+ # MySQL (default setup). Versions 4.1 and 5.0 are recommended.
3
+ #
4
+ # Install the MySQL driver:
5
+ # gem install mysql
6
+ # On MacOS X:
7
+ # gem install mysql -- --include=/usr/local/lib
8
+ # On Windows:
9
+ # There is no gem for Windows. Install mysql.so from RubyForApache.
10
+ # http://rubyforge.org/projects/rubyforapache
11
+ #
12
+ # And be sure to use new-style password hashing:
13
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
14
+ development:
15
+ adapter: mysql
16
+ database: userqueryex_development
17
+ username: test
18
+ password: test
19
+ host: localhost
20
+
21
+ # Warning: The database defined as 'test' will be erased and
22
+ # re-generated from your development database when you run 'rake'.
23
+ # Do not set this db to the same as development or production.
24
+ test:
25
+ adapter: mysql
26
+ database: userqueryex_test
27
+ username: test
28
+ password: test
29
+ host: localhost
30
+
31
+ production:
32
+ adapter: mysql
33
+ database: userqueryex_production
34
+ username: test
35
+ password: test
36
+ host: localhost
@@ -0,0 +1,54 @@
1
+ # Be sure to restart your web server when you modify this file.
2
+
3
+ # Uncomment below to force Rails into production mode when
4
+ # you don't control web/app server and can't set it the proper way
5
+ # ENV['RAILS_ENV'] ||= 'production'
6
+
7
+ # Specifies gem version of Rails to use when vendor/rails is not present
8
+ RAILS_GEM_VERSION = '1.1.6'
9
+
10
+ # Bootstrap the Rails environment, frameworks, and default configuration
11
+ require File.join(File.dirname(__FILE__), 'boot')
12
+
13
+ Rails::Initializer.run do |config|
14
+ # Settings in config/environments/* take precedence those specified here
15
+
16
+ # Skip frameworks you're not going to use (only works if using vendor/rails)
17
+ # config.frameworks -= [ :action_web_service, :action_mailer ]
18
+
19
+ # Add additional load paths for your own custom dirs
20
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
21
+ config.load_paths += %W( #{RAILS_ROOT}/../../lib )
22
+
23
+ # Force all environments to use the same logger level
24
+ # (by default production uses :info, the others :debug)
25
+ # config.log_level = :debug
26
+
27
+ # Use the database for sessions instead of the file system
28
+ # (create the session table with 'rake db:sessions:create')
29
+ # config.action_controller.session_store = :active_record_store
30
+
31
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
32
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
33
+ # like if you have constraints or database-specific column types
34
+ # config.active_record.schema_format = :sql
35
+
36
+ # Activate observers that should always be running
37
+ # config.active_record.observers = :cacher, :garbage_collector
38
+
39
+ # Make Active Record use UTC-base instead of local time
40
+ # config.active_record.default_timezone = :utc
41
+
42
+ # See Rails::Configuration for more options
43
+ end
44
+
45
+ # Add new inflection rules using the following format
46
+ # (all these examples are active by default):
47
+ # Inflector.inflections do |inflect|
48
+ # inflect.plural /^(ox)$/i, '\1en'
49
+ # inflect.singular /^(ox)en/i, '\1'
50
+ # inflect.irregular 'person', 'people'
51
+ # inflect.uncountable %w( fish sheep )
52
+ # end
53
+
54
+ # Include your application configuration below
@@ -0,0 +1,21 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Enable the breakpoint server that script/breakpointer connects to
12
+ config.breakpoint_server = true
13
+
14
+ # Show full error reports and disable caching
15
+ config.action_controller.consider_all_requests_local = true
16
+ config.action_controller.perform_caching = false
17
+ config.action_view.cache_template_extensions = false
18
+ config.action_view.debug_rjs = true
19
+
20
+ # Don't care if the mailer can't send
21
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,18 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Use a different logger for distributed setups
8
+ # config.logger = SyslogLogger.new
9
+
10
+ # Full error reports are disabled and caching is turned on
11
+ config.action_controller.consider_all_requests_local = false
12
+ config.action_controller.perform_caching = true
13
+
14
+ # Enable serving of images, stylesheets, and javascripts from an asset server
15
+ # config.action_controller.asset_host = "http://assets.example.com"
16
+
17
+ # Disable delivery errors if you bad email addresses should just be ignored
18
+ # config.action_mailer.raise_delivery_errors = false