clevic 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +17 -2
- data/README.txt +5 -2
- data/Rakefile +5 -13
- data/accounts_models.rb +6 -31
- data/bin/clevic +1 -10
- data/bin/import-times +128 -0
- data/config/hoe.rb +76 -0
- data/{template → config}/jamis.rb +0 -0
- data/config/requirements.rb +15 -0
- data/env.sh +1 -0
- data/lib/clevic.rb +1 -0
- data/lib/clevic/cache_table.rb +2 -0
- data/lib/clevic/db_options.rb +81 -11
- data/lib/clevic/ui/browser_ui.rb +74 -73
- data/lib/clevic/ui/search_dialog_ui.rb +51 -50
- data/lib/clevic/version.rb +9 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/tasks/website.rake +25 -0
- data/times_models.rb +5 -6
- data/values_models.rb +32 -0
- data/website/index.html +147 -0
- data/website/index.txt +10 -0
- data/website/screenshot.png +0 -0
- data/website/stylesheets/screen.css +131 -0
- data/website/template.html.erb +40 -0
- metadata +28 -22
- data/INSTALL +0 -10
data/Manifest.txt
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
History.txt
|
2
|
-
INSTALL
|
3
2
|
Manifest.txt
|
4
3
|
README.txt
|
5
4
|
Rakefile
|
6
5
|
TODO
|
7
6
|
accounts_models.rb
|
8
7
|
bin/clevic
|
8
|
+
bin/import-times
|
9
|
+
config/hoe.rb
|
10
|
+
config/jamis.rb
|
11
|
+
config/requirements.rb
|
12
|
+
env.sh
|
9
13
|
lib/active_record/dirty.rb
|
10
14
|
lib/clevic.rb
|
11
15
|
lib/clevic/browser.rb
|
@@ -25,7 +29,18 @@ lib/clevic/ui/browser_ui.rb
|
|
25
29
|
lib/clevic/ui/icon.png
|
26
30
|
lib/clevic/ui/search_dialog.ui
|
27
31
|
lib/clevic/ui/search_dialog_ui.rb
|
32
|
+
lib/clevic/version.rb
|
33
|
+
script/console
|
34
|
+
script/destroy
|
35
|
+
script/generate
|
36
|
+
script/txt2html
|
28
37
|
sql/accounts.sql
|
29
38
|
sql/times.sql
|
30
|
-
|
39
|
+
tasks/website.rake
|
31
40
|
times_models.rb
|
41
|
+
values_models.rb
|
42
|
+
website/index.html
|
43
|
+
website/index.txt
|
44
|
+
website/screenshot.png
|
45
|
+
website/stylesheets/screen.css
|
46
|
+
website/template.html.erb
|
data/README.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= clevic
|
2
2
|
|
3
|
-
http://
|
3
|
+
http://clevic.rubyforge.org/
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -14,6 +14,8 @@ nice keyboard shortcuts for all sorts of things. Model (table) objects
|
|
14
14
|
are extensible to allow for model (table) specific cleverness, like
|
15
15
|
auto-filling-in of fields.
|
16
16
|
|
17
|
+
Start with Clevic::Browser
|
18
|
+
|
17
19
|
== FEATURES:
|
18
20
|
|
19
21
|
* Filter by current field.
|
@@ -60,7 +62,8 @@ See TODO file.
|
|
60
62
|
=== Gems
|
61
63
|
* fastercsv
|
62
64
|
* ruby-qt4
|
63
|
-
*
|
65
|
+
* qtext (not available on rubyforge yet. Download from http://www.semiosix.com/qtext-0.2.0.gem)
|
66
|
+
* ActiveRecord
|
64
67
|
|
65
68
|
=== Other
|
66
69
|
|
data/Rakefile
CHANGED
@@ -1,20 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'hoe'
|
4
|
-
require 'lib/clevic/version.rb'
|
5
4
|
require 'pathname'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
s.extra_deps = [
|
12
|
-
['qtext', '>=0.2.0'],
|
13
|
-
['activerecord', '>=2.0.2']
|
14
|
-
# This isn't always installed from gems
|
15
|
-
#~ ['qtruby4', '>=1.4.9']
|
16
|
-
]
|
17
|
-
end
|
6
|
+
require 'config/requirements'
|
7
|
+
require 'config/hoe' # setup Hoe + all gem configuration
|
8
|
+
|
9
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
18
10
|
|
19
11
|
# generate a _ui.rb filename from a .ui filename
|
20
12
|
def ui_rb_file( ui_file )
|
@@ -112,7 +104,7 @@ Rake::RDocTask.new(:docs) do |rd|
|
|
112
104
|
rd.main = "README.txt"
|
113
105
|
rd.options << '-d' if RUBY_PLATFORM !~ /win32/ and `which dot` =~ /\/dot/ and not ENV['NODOT']
|
114
106
|
rd.rdoc_dir = 'doc'
|
115
|
-
rd.template = '
|
107
|
+
rd.template = 'config/jamis.rb'
|
116
108
|
files = $hoe.spec.files.grep($hoe.rdoc_pattern)
|
117
109
|
files -= ['Manifest.txt']
|
118
110
|
rd.rdoc_files.push(*files)
|
data/accounts_models.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'clevic.rb'
|
2
2
|
|
3
|
-
# db connection
|
4
|
-
$options
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
$options[:password] ||= ''
|
3
|
+
# db connection
|
4
|
+
Clevic::DbOptions.connect( $options ) do
|
5
|
+
database( debug? ? :accounts_test : :accounts )
|
6
|
+
adapter :postgresql
|
7
|
+
username 'panic'
|
8
|
+
end
|
10
9
|
|
11
10
|
class Entry < ActiveRecord::Base
|
12
11
|
include ActiveRecord::Dirty
|
@@ -96,27 +95,3 @@ end
|
|
96
95
|
|
97
96
|
# order of tab display
|
98
97
|
$options[:models] = [ Entry, Account ]
|
99
|
-
|
100
|
-
# This is a read-only view, which is currently not implemented
|
101
|
-
#~ class Values < ActiveRecord::Base
|
102
|
-
#~ include ActiveRecord::Dirty
|
103
|
-
#~ set_table_name 'values'
|
104
|
-
#~ has_many :debits, :class_name => 'Entry', :foreign_key => 'debit_id'
|
105
|
-
#~ has_many :credits, :class_name => 'Entry', :foreign_key => 'credit_id'
|
106
|
-
#~ def self.ui( parent )
|
107
|
-
#~ Clevic::TableView.new( self, parent ).create_model do
|
108
|
-
#~ readonly
|
109
|
-
#~ plain :date
|
110
|
-
#~ plain :description
|
111
|
-
#~ plain :debit
|
112
|
-
#~ plain :credit
|
113
|
-
#~ plain :pre_vat_amount
|
114
|
-
#~ plain :cheque_number
|
115
|
-
#~ plain :vat, :label => 'VAT'
|
116
|
-
#~ plain :financial_year
|
117
|
-
#~ plain :month
|
118
|
-
|
119
|
-
#~ records :order => 'date'
|
120
|
-
#~ end
|
121
|
-
#~ end
|
122
|
-
#~ end
|
data/bin/clevic
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
|
3
3
|
require 'clevic/browser.rb'
|
4
|
-
require 'ruby-debug'
|
5
|
-
|
6
4
|
require 'optparse'
|
7
5
|
|
8
6
|
# find and require variations on file_path
|
@@ -30,7 +28,7 @@ oparser.on( '-D', '--debug' ) { |o| $options[:debug] = true }
|
|
30
28
|
oparser.on( '-v', '--verbose' ) { |o| $options[:verbose] = true }
|
31
29
|
oparser.on( '-h', '-?', '--help' ) do |o|
|
32
30
|
puts oparser.to_s
|
33
|
-
exit(
|
31
|
+
exit( 1 )
|
34
32
|
end
|
35
33
|
|
36
34
|
args = oparser.parse( ARGV )
|
@@ -45,13 +43,6 @@ end
|
|
45
43
|
|
46
44
|
app = Qt::Application.new( args )
|
47
45
|
|
48
|
-
unless $options.has_key? :database
|
49
|
-
raise "Please define $options[:database]"
|
50
|
-
end
|
51
|
-
|
52
|
-
# connect to db
|
53
|
-
require 'clevic/db_options.rb'
|
54
|
-
|
55
46
|
# show UI
|
56
47
|
main_window = Qt::MainWindow.new
|
57
48
|
browser = Clevic::Browser.new( main_window )
|
data/bin/import-times
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'times_models.rb'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
$options = {}
|
8
|
+
oparser = OptionParser.new
|
9
|
+
oparser.on( '-H', '--host HOST', 'RDBMS host', String ) { |o| $options[:host] = o }
|
10
|
+
oparser.on( '-u', '--user USERNAME', String ) { |o| $options[:user] = o }
|
11
|
+
oparser.on( '-p', '--pass PASSWORD', String ) { |o| $options[:password] = o }
|
12
|
+
oparser.on( '-t', '--table TABLE', 'Table to display', String ) { |o| $options[:table] = o }
|
13
|
+
oparser.on( '-d', '--database DATABASE', 'Database name', String ) { |o| $options[:database] = o }
|
14
|
+
oparser.on( '-D', '-v', '--debug' ) { |o| $options[:debug] = true }
|
15
|
+
oparser.on( '-h', '-?', '--help' ) do |o|
|
16
|
+
puts oparser.to_s
|
17
|
+
exit( 0 )
|
18
|
+
end
|
19
|
+
|
20
|
+
oparser.parse!( ARGV )
|
21
|
+
|
22
|
+
require 'clevic/db_options.rb'
|
23
|
+
puts "using database #{ActiveRecord::Base.connection.raw_connection.db}" if $options[:debug]
|
24
|
+
|
25
|
+
st =
|
26
|
+
if ARGV[0].nil?
|
27
|
+
raise ( "provide a yml file that looks like this: " + <<EOF )
|
28
|
+
#~ dd-mmm-yyyy:
|
29
|
+
#~ project:
|
30
|
+
#~ - [08h00, 17h00, whatever, <yes|no (charge)>|<activity>]
|
31
|
+
|
32
|
+
28-apr-2008:
|
33
|
+
stackpro:
|
34
|
+
- [20h01, 23h03, Research on using Matrices for stackpro]
|
35
|
+
|
36
|
+
29-apr-2008:
|
37
|
+
stackpro:
|
38
|
+
- [20h01, 22h43, Working on Stackpro]
|
39
|
+
- [23h02, 23h30, More on test cases]
|
40
|
+
clevic:
|
41
|
+
- [22h43, 23h02, yaml for times]
|
42
|
+
|
43
|
+
30-apr-2008:
|
44
|
+
stackpro:
|
45
|
+
- [19h45, 21h10, Trying both directions]
|
46
|
+
- [21h10, 21h59, Has to be a pull pipeline]
|
47
|
+
- [21h59, 23h00, get 3 ops working]
|
48
|
+
- [23h00, 23h55, do stack algorithm]
|
49
|
+
|
50
|
+
01-may-2008:
|
51
|
+
stackpro:
|
52
|
+
- [18h54, 20H34, fighting with eof]
|
53
|
+
|
54
|
+
02-may-2008:
|
55
|
+
stackpro:
|
56
|
+
- [07h50, 08h32, fighting with eof]
|
57
|
+
- [19h23, 20h09, simplify testing]
|
58
|
+
- [21h03, 22h30, do stackpro bin]
|
59
|
+
|
60
|
+
03-may-2008:
|
61
|
+
stackpro:
|
62
|
+
- [07h50, 08h32, fighting with eof]
|
63
|
+
unwreck:
|
64
|
+
- [12h50, 15h05, start project. Do some initial coding and testing.]
|
65
|
+
|
66
|
+
04-may-2008:
|
67
|
+
unwreck:
|
68
|
+
- [19h11, 19h31, find a way to store the jobs]
|
69
|
+
- [21h15, 21h34, find a way to store the jobs]
|
70
|
+
- [21h34, 23h01, Do DirectoryStorage. Improve sampling.]
|
71
|
+
- [23h01, 23h18, Ask for force for pre-existing job.]
|
72
|
+
|
73
|
+
05-may-2008:
|
74
|
+
unwreck:
|
75
|
+
- [13h32, 14h15, build index]
|
76
|
+
- [20h30, 22h05, fetch using index and compare]
|
77
|
+
- [22h05, 22h53, doing file cleanups and serialisation]
|
78
|
+
|
79
|
+
19-may-2008:
|
80
|
+
unwreck:
|
81
|
+
- [12h30, 12h50, Travel to CIM (because Warren missed the meeting)]
|
82
|
+
- [12h50, 13h20, Chat to Gavin, no]
|
83
|
+
- [13h20, 15h40, Work on stackpro and unwreck]
|
84
|
+
- [15h40, 16h05, Travel home]
|
85
|
+
- [22h03, 22h42, Work on stackpro]
|
86
|
+
|
87
|
+
21-may-2008:
|
88
|
+
unwreck:
|
89
|
+
- [6h30, 7h21, start on header line]
|
90
|
+
- [8h55, 10h36, finish header line]
|
91
|
+
EOF
|
92
|
+
else
|
93
|
+
File.read( ARGV[0] )
|
94
|
+
end
|
95
|
+
|
96
|
+
def process( data_structure )
|
97
|
+
Entry.transaction do
|
98
|
+
coding = Activity.find_by_activity 'Coding'
|
99
|
+
data_structure.keys.each do |key|
|
100
|
+
date = Date.parse( key )
|
101
|
+
day = data_structure[key]
|
102
|
+
day.keys.each do |project_key|
|
103
|
+
project = Project.find_by_project project_key
|
104
|
+
raise "project #{project_key} not in database" if project.nil?
|
105
|
+
invoice = project.latest_invoice
|
106
|
+
|
107
|
+
times = day[project_key]
|
108
|
+
times.each do |entry_arr|
|
109
|
+
entry = Entry.new( :project => project, :invoice => invoice, :date => date, :rate => project.rate )
|
110
|
+
entry.start = entry_arr[0]
|
111
|
+
entry.end = entry_arr[1]
|
112
|
+
entry.description = entry_arr[2]
|
113
|
+
|
114
|
+
if entry_arr[3] == true || entry_arr[3] == false
|
115
|
+
entry.charge = entry_arr[3]
|
116
|
+
else
|
117
|
+
entry.activity = entry_arr[3] || coding
|
118
|
+
end
|
119
|
+
|
120
|
+
entry.save
|
121
|
+
puts "entry: #{entry.inspect}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
process( YAML.load( st ) )
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'clevic/version'
|
2
|
+
|
3
|
+
AUTHOR = 'John Anderson' # can also be an array of Authors
|
4
|
+
EMAIL = "panic@semiosix.com"
|
5
|
+
DESCRIPTION = "SQL table GUI with Qt"
|
6
|
+
GEM_NAME = 'clevic' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'clevic' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
['qtext', '>=0.2.0'],
|
12
|
+
['activerecord', '>=2.0.2']
|
13
|
+
# This isn't always installed from gems
|
14
|
+
#~ ['qtruby4', '>=1.4.9']
|
15
|
+
] # An array of rubygem dependencies [name, version]
|
16
|
+
|
17
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
18
|
+
@config = nil
|
19
|
+
RUBYFORGE_USERNAME = "panic"
|
20
|
+
def rubyforge_username
|
21
|
+
unless @config
|
22
|
+
begin
|
23
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
24
|
+
rescue
|
25
|
+
puts <<-EOS
|
26
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
27
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
28
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
29
|
+
EOS
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
REV = nil
|
38
|
+
# UNCOMMENT IF REQUIRED:
|
39
|
+
# REV = YAML.load(`svn info`)['Revision']
|
40
|
+
VERS = Clevic::VERSION::STRING + (REV ? ".#{REV}" : "")
|
41
|
+
RDOC_OPTS = ['--quiet', '--title', 'clevic documentation',
|
42
|
+
"--opname", "index.html",
|
43
|
+
"--line-numbers",
|
44
|
+
"--main", "README",
|
45
|
+
"--inline-source"]
|
46
|
+
|
47
|
+
class Hoe
|
48
|
+
def extra_deps
|
49
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
50
|
+
@extra_deps
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Generate all the Rake tasks
|
55
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
56
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
57
|
+
p.developer(AUTHOR, EMAIL)
|
58
|
+
p.description = DESCRIPTION
|
59
|
+
p.summary = DESCRIPTION
|
60
|
+
p.url = HOMEPATH
|
61
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
62
|
+
p.test_globs = ["test/**/test_*.rb"]
|
63
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
64
|
+
|
65
|
+
# == Optional
|
66
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
67
|
+
p.extra_deps = EXTRA_DEPENDENCIES
|
68
|
+
|
69
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
70
|
+
end
|
71
|
+
|
72
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
73
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
74
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
75
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
76
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/env.sh
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export RUBYLIB=$RUBYLIB:`pwd`/lib
|
data/lib/clevic.rb
CHANGED
data/lib/clevic/cache_table.rb
CHANGED
@@ -62,7 +62,9 @@ known entity in the set requires a defined ordering, so if no ordering
|
|
62
62
|
is specified, the primary key of the entity will be used.
|
63
63
|
|
64
64
|
It hasn't been tested with compound primary keys.
|
65
|
+
|
65
66
|
--
|
67
|
+
|
66
68
|
TODO drop rows when they haven't been accessed for a while
|
67
69
|
|
68
70
|
TODO how to handle a quickly-changing underlying table? invalidate cache
|
data/lib/clevic/db_options.rb
CHANGED
@@ -1,18 +1,88 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
$options[:host] ||= 'localhost'
|
8
|
-
$options[:username] ||= ''
|
9
|
-
$options[:password] ||= ''
|
3
|
+
module Clevic
|
4
|
+
=begin rdoc
|
5
|
+
This class is intended to set up db options for a ActiveRecord
|
6
|
+
connection to a particular database. Like this:
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
Clevic::DbOptions.connect( $options ) do
|
9
|
+
database :accounts
|
10
|
+
adapter :postgresql
|
11
|
+
username 'panic'
|
12
|
+
end
|
13
|
+
|
14
|
+
When the block ends, a check is done to see that the :database key
|
15
|
+
exists. If not and exception is thrown. Finally the relevant calls to
|
16
|
+
ActiveRecord are performed.
|
14
17
|
|
15
|
-
|
18
|
+
Method calls are translated to insertions into a hash with the same
|
19
|
+
key as the method being called. The hash is initialised
|
20
|
+
with the options value passed in (in this case $options).
|
21
|
+
Values have to_s called on them so they can be symbols or strings.
|
22
|
+
=end
|
23
|
+
class DbOptions
|
24
|
+
def initialize( options )
|
25
|
+
@options = options || {}
|
26
|
+
# make sure the relevant entries exist, so method_missing works
|
27
|
+
@options[:adapter] ||= ''
|
28
|
+
@options[:host] ||= ''
|
29
|
+
@options[:username] ||= ''
|
30
|
+
@options[:password] ||= ''
|
31
|
+
@options[:database] ||= ''
|
32
|
+
end
|
33
|
+
|
34
|
+
def connect( *args, &block )
|
35
|
+
# using the Rails implementation, included in Qt
|
36
|
+
block.bind( self )[*args]
|
37
|
+
do_connection
|
38
|
+
end
|
39
|
+
|
40
|
+
# do error checking and make the ActiveRecord connection calls.
|
41
|
+
def do_connection
|
42
|
+
unless @options[:database]
|
43
|
+
raise "Please define database using DbOptions"
|
44
|
+
end
|
45
|
+
|
46
|
+
# connect to db
|
47
|
+
ActiveRecord::Base.establish_connection( @options )
|
48
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT) if @options[:verbose]
|
49
|
+
#~ ActiveRecord.colorize_logging = @options[:verbose]
|
50
|
+
puts "using database #{ActiveRecord::Base.connection.raw_connection.db}" if $options[:debug]
|
51
|
+
end
|
52
|
+
|
53
|
+
# convenience method so we can do things like
|
54
|
+
# Clevic::DbOptions.connect( $options ) do
|
55
|
+
# database :accounts
|
56
|
+
# adapter :postgresql
|
57
|
+
# username 'panic'
|
58
|
+
# end
|
59
|
+
# the block is evaluated in the context of the a new DbOptions
|
60
|
+
# object.
|
61
|
+
def self.connect( args, &block )
|
62
|
+
inst = self.new( args )
|
63
|
+
# using the Rails implementation, included in Qt
|
64
|
+
block.bind( inst )[*args]
|
65
|
+
inst.do_connection
|
66
|
+
end
|
67
|
+
|
68
|
+
# translate method calls in the context of an instance
|
69
|
+
# of this object to setting values in the @options
|
70
|
+
# variable
|
71
|
+
def method_missing(meth, *args, &block)
|
72
|
+
if @options.has_key? meth.to_sym
|
73
|
+
@options[meth.to_sym] = args[0].to_s
|
74
|
+
else
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# convenience to find out if we're in debug mode
|
80
|
+
def debug?
|
81
|
+
@options[:debug] == true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
16
86
|
|
17
87
|
# workaround for the date freeze issue
|
18
88
|
class Date
|