active-record-binder 1.1.0 → 1.2.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/README.md +217 -0
- data/bin/arb +13 -0
- data/doc/Binder.html +150 -0
- data/doc/Binder/AR.html +1880 -0
- data/doc/Binder/Command.html +252 -0
- data/doc/Binder/Help.html +374 -0
- data/doc/Binder/Migrate.html +682 -0
- data/doc/Binder/Strategy.html +550 -0
- data/doc/Binder/Version.html +285 -0
- data/doc/Class.html +220 -0
- data/doc/CommandParser.html +268 -0
- data/doc/CommandParser/ParseError.html +123 -0
- data/doc/DeferedDelegator.html +414 -0
- data/doc/MigrationProcessError.html +123 -0
- data/doc/MigrationVersionError.html +123 -0
- data/doc/String.html +245 -0
- data/doc/_index.html +256 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +300 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +300 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +348 -0
- data/doc/top-level-namespace.html +114 -0
- data/extras/cli_help.png +0 -0
- data/lib/active_record_binder.rb +21 -37
- data/lib/cli/command.rb +101 -0
- data/lib/cli/command_parser.rb +29 -0
- data/lib/cli/commands/commands.rb +4 -0
- data/lib/cli/commands/help.rb +35 -0
- data/lib/cli/commands/migrate.rb +77 -0
- data/lib/cli/commands/version.rb +16 -0
- data/lib/cli/core_ext.rb +21 -0
- data/lib/defered_delegator.rb +69 -0
- data/lib/version.rb +3 -0
- data/test/active_record_binder_test.rb +262 -0
- data/test/foo.sqlite3 +0 -0
- data/test/migrations.rb +29 -0
- data/test/minitest_helper.rb +15 -0
- data/test/mocks.rb +24 -0
- metadata +62 -5
data/README.md
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
[ActiveRecordBinder](https://rubygems.org/gems/active-record-binder)
|
2
|
+
============
|
3
|
+
```
|
4
|
+
arb -v
|
5
|
+
# => 1.2.0
|
6
|
+
|
7
|
+
arb --changelog
|
8
|
+
# V 1.2.0 : Bug fixes, refactoring and introduction of the new command-line-tool : `arb`
|
9
|
+
# V 1.1.0 : Introducing delegation for ActiveRecord::Base relation methods.
|
10
|
+
# V 1.0.1 : Minor fixes and Documentation creation.
|
11
|
+
# V 1.0.0 : Release
|
12
|
+
#
|
13
|
+
```
|
14
|
+
A Ruby library for an easier interfacing with ActiveRecord. And an easier way to create elegant migrations.
|
15
|
+
|
16
|
+
# Installation
|
17
|
+
`gem install active-record-binder`
|
18
|
+
|
19
|
+
# Why Binder ? What the frak is this ?
|
20
|
+
I needed a tool to ease the creation of little Plugs and Adapters for ActiveRecord.
|
21
|
+
|
22
|
+
The idea is that you Bind a class to ActiveRecord by subclassing it with Binder::AR.
|
23
|
+
You can specify your own methods and delegate to ActiveRecord whenever you need.
|
24
|
+
|
25
|
+
It's kind of a Proxy on steroids, that will do a lot for you.
|
26
|
+
|
27
|
+
## Show me !
|
28
|
+
You want to create a Plug for your sqlite database :
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
class SqlitePlug < Binder::AR
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Those lines will create a new `MySqlPlug`, and it will connect to the database specified by your `ENV['APP_DB']`.
|
36
|
+
Also, the database adapter defaults to `:sqlite3`.
|
37
|
+
|
38
|
+
Now. All this is fine. But you want more :
|
39
|
+
* You want to select a precise database without using `ENV['APP_DB']`;
|
40
|
+
* Your application uses MySQL.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class MySqlPlug < Binder::AR
|
44
|
+
database :db
|
45
|
+
adapter :mysql
|
46
|
+
connect_with user: 'Foo', password: 'Bar', host: 'localhost'
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
As you can see : you can specify a database or an adapter by passing a `Symbol` or a `String` to both the
|
51
|
+
* `database()` and the
|
52
|
+
* `adapter()` methods.
|
53
|
+
|
54
|
+
The `connect_with()` method can be used to pass a `Hash` of options to the `ActiveRecord::Base.establish_connexion()` call.
|
55
|
+
|
56
|
+
_Please notice that all your instances of MySqlPlug will use those values once defined this way._
|
57
|
+
|
58
|
+
## How do we use this ?
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class MySqlPlug < Binder::AR
|
62
|
+
database :db
|
63
|
+
adapter :mysql
|
64
|
+
connect_with user: 'Foo', password: 'Bar', host: 'localhost'
|
65
|
+
|
66
|
+
def find args
|
67
|
+
# But you could use a delegator
|
68
|
+
table.find args
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# A Model
|
73
|
+
class Foo
|
74
|
+
def initialize
|
75
|
+
# Will bind this instance of the MySqlPlug to the `foos` table
|
76
|
+
@plug = MySqlPlug.new :foo
|
77
|
+
end
|
78
|
+
|
79
|
+
def find
|
80
|
+
# But you could use a delegator
|
81
|
+
@plug.find
|
82
|
+
end
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
**Note :** You can use the `table` method on any instance of your Plug to get the table class (An ActiveRecord Class Object).
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
@plug = MySqlPlug.new :foo
|
90
|
+
table = @plug.table
|
91
|
+
# => MySqlPlug::Foo
|
92
|
+
table.find # ActiveRecord method call.
|
93
|
+
# => [<FooObject#1>, <FooObject#2, ...]
|
94
|
+
```
|
95
|
+
|
96
|
+
Notice how neatly namespaced is the ActiveRecord table class. This way we won't step over our `Foo` model.
|
97
|
+
|
98
|
+
# Relations
|
99
|
+
If it pleases you, you can create your relations directly in the Binder class. Those methods call are delegated to the underlying table model when initiated.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
class FooBinder < Binder::AR
|
103
|
+
has_one :bar
|
104
|
+
end
|
105
|
+
class BarBinder < Binder::AR
|
106
|
+
belongs_to :foo
|
107
|
+
end
|
108
|
+
|
109
|
+
# And (if the table are accordingly populated, see "The Migration System", below) :
|
110
|
+
foo = FooBinder.new(:foo).table
|
111
|
+
foo.first.bar # => <BarObject>
|
112
|
+
```
|
113
|
+
|
114
|
+
Delegated methods are the following : `has_many`, `has_one`, `has_and_belongs_to_many`, `belongs_to`.
|
115
|
+
|
116
|
+
# The Migration System
|
117
|
+
|
118
|
+
I've always found the ActiveRecord::Migration system a bit of a pain to use.
|
119
|
+
|
120
|
+
Therefore, I took the liberty of using pieces of [`_Why's Camping Web Framework's`](https://github.com/camping/camping/) migration system.
|
121
|
+
You can now create your migrations this way :
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
class CreateFooTable < MySqlPlug::Version 1.0
|
125
|
+
def self.up
|
126
|
+
create_table :foos do |t|
|
127
|
+
t.string :name
|
128
|
+
t.timestamps
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.down
|
133
|
+
drop_table :foos
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class CreateBarTable < MySqlPlug::Version 1.1
|
138
|
+
def self.up
|
139
|
+
create_table :bars do |t|
|
140
|
+
t.string :title
|
141
|
+
t.timestamps
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.down
|
146
|
+
drop_table :bars
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# You can get the migration version for a pecular migration class.
|
151
|
+
CreateFooTable.version # => 1.0
|
152
|
+
CreateBarTable.version # => 1.1
|
153
|
+
```
|
154
|
+
|
155
|
+
Isn't it neat ?.
|
156
|
+
|
157
|
+
Now, boy : just use the `migrate` method to execute your migrations.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
MySqlPlug.migrate
|
161
|
+
# => 1.1
|
162
|
+
```
|
163
|
+
This executes everything up to the latest migration.
|
164
|
+
But `migrate()` can also take a version number as an argument.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
MySqlPlug.migrate 0
|
168
|
+
# => 0.0
|
169
|
+
```
|
170
|
+
This, will migrate everything down, reverting the changes as specified in each reverted migration `self.down` method.
|
171
|
+
```ruby
|
172
|
+
MySqlPlug.migrate 1.0
|
173
|
+
# => 1.0
|
174
|
+
```
|
175
|
+
And finally, this will migrate up until it hits 1.0.
|
176
|
+
|
177
|
+
# The Command Line Tool
|
178
|
+
Active Record Binder ships with a neat little CLI : `arb`
|
179
|
+
|
180
|
+
ARB is a small easily extandable Command Line Interface. And it's pretty. Beautiful colors everywhere. Awesome. Seriously.
|
181
|
+
To use it :
|
182
|
+
```
|
183
|
+
$ arb version
|
184
|
+
# => Binder::AR::Version => 1.2.0
|
185
|
+
```
|
186
|
+
|
187
|
+
You can display the help using `arb help` or `arb -h`
|
188
|
+
|
189
|
+
But, the most intersting part of this CLI is the migrate command. You can easily run your migrations for a specific plug :
|
190
|
+
```
|
191
|
+
$ arb migrate --version 1.1 --directory migrations/ --adapter MySqlitePlug
|
192
|
+
```
|
193
|
+
Will migrate to 1.1, using the migrations found in the `migrations/` directory and calling `MySqlitePlug.migrate`.
|
194
|
+
|
195
|
+
You can specify multiples options, and there is an alternative syntax :
|
196
|
+
```
|
197
|
+
# => You can specify multiple directories through `--directory` or `--d`
|
198
|
+
$ arb migrate -v 0 -d migrations/foo/ migrations/bar -a MySqlitePlug
|
199
|
+
|
200
|
+
# => You can load directories recursively with `-r` or `--recursive`
|
201
|
+
$ arb migrate -v 0 --recursive migrations/ --plug MySqlitePlug
|
202
|
+
|
203
|
+
# => You can can also load files using `-f` or `--file`
|
204
|
+
$ arb migrate -v 1.0 -f migrations/foo/create_foo_table.rb --adapter MySqlitePlug
|
205
|
+
```
|
206
|
+
|
207
|
+
<img src="https://raw.github.com/gabriel-dehan/ActiveRecordBinder/master/extras/cli_help.png" alt="Command Line Interface screenshot"/>
|
208
|
+
|
209
|
+
# Want to know more ?
|
210
|
+
[Checkout the documentation !](http://rubydoc.info/gems/active-record-binder/1.0.1/frames)
|
211
|
+
Or dive in, the code is pretty straightforward and well documented. And there is a lot of tests.
|
212
|
+
|
213
|
+
# Want to contribute ?
|
214
|
+
Please, do fork and pull request !
|
215
|
+
|
216
|
+
## Road map:
|
217
|
+
* Maybe create other Binder, like MongoDB, Datamapper, like `Binder::Mongo`, `Binder::DataMapper`. But the gem's name would have to change.
|
data/bin/arb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
4
|
+
|
5
|
+
require 'cli/commands/commands'
|
6
|
+
|
7
|
+
begin
|
8
|
+
Binder::Command.new ARGV
|
9
|
+
rescue CommandParser::ParseError => ex
|
10
|
+
STDERR.puts "/!\\ #{ex.message}".colorize(:red)
|
11
|
+
puts ">> use " + "`#{File.basename($0)} --help` ".colorize(:green) + "for more details."
|
12
|
+
exit 1
|
13
|
+
end
|
data/doc/Binder.html
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Binder
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.4.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (B)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">Binder</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Module: Binder
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<dt class="r1 last">Defined in:</dt>
|
82
|
+
<dd class="r1 last">lib/active_record_binder.rb<span class="defines">,<br />
|
83
|
+
lib/cli/command.rb,<br /> lib/cli/commands/help.rb,<br /> lib/cli/commands/migrate.rb,<br /> lib/cli/commands/version.rb,<br /> lib/version.rb</span>
|
84
|
+
</dd>
|
85
|
+
|
86
|
+
</dl>
|
87
|
+
<div class="clear"></div>
|
88
|
+
|
89
|
+
<h2>Overview</h2><div class="docstring">
|
90
|
+
<div class="discussion">
|
91
|
+
|
92
|
+
<p>Namespace containing classes to create binder to. A binder is simply a tool
|
93
|
+
to use for Databases plugs or adaptors building.</p>
|
94
|
+
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
<div class="tags">
|
99
|
+
|
100
|
+
|
101
|
+
</div><h2>Defined Under Namespace</h2>
|
102
|
+
<p class="children">
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Binder/AR.html" title="Binder::AR (class)">AR</a></span>, <span class='object_link'><a href="Binder/Command.html" title="Binder::Command (class)">Command</a></span>, <span class='object_link'><a href="Binder/Help.html" title="Binder::Help (class)">Help</a></span>, <span class='object_link'><a href="Binder/Migrate.html" title="Binder::Migrate (class)">Migrate</a></span>, <span class='object_link'><a href="Binder/Strategy.html" title="Binder::Strategy (class)">Strategy</a></span>, <span class='object_link'><a href="Binder/Version.html" title="Binder::Version (class)">Version</a></span>
|
108
|
+
|
109
|
+
|
110
|
+
</p>
|
111
|
+
|
112
|
+
<h2>Constant Summary</h2>
|
113
|
+
|
114
|
+
<dl class="constants">
|
115
|
+
|
116
|
+
<dt id="VERSION-constant" class="">VERSION =
|
117
|
+
<div class="docstring">
|
118
|
+
<div class="discussion">
|
119
|
+
|
120
|
+
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
<div class="tags">
|
124
|
+
|
125
|
+
|
126
|
+
</div>
|
127
|
+
</dt>
|
128
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>1.2.0</span><span class='tstring_end'>"</span></span></pre></dd>
|
129
|
+
|
130
|
+
</dl>
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
</div>
|
142
|
+
|
143
|
+
<div id="footer">
|
144
|
+
Generated on Thu Feb 21 02:06:16 2013 by
|
145
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
146
|
+
0.8.4.1 (ruby-1.9.3).
|
147
|
+
</div>
|
148
|
+
|
149
|
+
</body>
|
150
|
+
</html>
|
data/doc/Binder/AR.html
ADDED
@@ -0,0 +1,1880 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Class: Binder::AR
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.4.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '../';
|
20
|
+
framesUrl = "../frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="../_index.html">Index (A)</a> »
|
35
|
+
<span class='title'><span class='object_link'><a href="../Binder.html" title="Binder (module)">Binder</a></span></span>
|
36
|
+
»
|
37
|
+
<span class="title">AR</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="../class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="../method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="../file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Class: Binder::AR
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
<dt class="r1">Inherits:</dt>
|
75
|
+
<dd class="r1">
|
76
|
+
<span class="inheritName">Object</span>
|
77
|
+
|
78
|
+
<ul class="fullTree">
|
79
|
+
<li>Object</li>
|
80
|
+
|
81
|
+
<li class="next">Binder::AR</li>
|
82
|
+
|
83
|
+
</ul>
|
84
|
+
<a href="#" class="inheritanceTree">show all</a>
|
85
|
+
|
86
|
+
</dd>
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
<dt class="r2">Extended by:</dt>
|
92
|
+
<dd class="r2"><span class='object_link'><a href="../DeferedDelegator.html" title="DeferedDelegator (module)">DeferedDelegator</a></span></dd>
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
<dt class="r1 last">Defined in:</dt>
|
101
|
+
<dd class="r1 last">lib/active_record_binder.rb</dd>
|
102
|
+
|
103
|
+
</dl>
|
104
|
+
<div class="clear"></div>
|
105
|
+
|
106
|
+
<h2>Overview</h2><div class="docstring">
|
107
|
+
<div class="discussion">
|
108
|
+
|
109
|
+
<p>Active Record Binder class. You need to inherit from it to create your Plug
|
110
|
+
or Adaptor.</p>
|
111
|
+
|
112
|
+
|
113
|
+
</div>
|
114
|
+
</div>
|
115
|
+
<div class="tags">
|
116
|
+
|
117
|
+
<div class="examples">
|
118
|
+
<p class="tag_title">Examples:</p>
|
119
|
+
|
120
|
+
|
121
|
+
<pre class="example code"><code>class ARSqlitePlug < Binder::AR
|
122
|
+
database 'db.sqlite3'
|
123
|
+
adapter :sqlite3</code></pre>
|
124
|
+
|
125
|
+
|
126
|
+
<pre class="example code"><code># Your methods
|
127
|
+
end
|
128
|
+
#
|
129
|
+
# Or
|
130
|
+
class ARMySqlPlug < Binder::AR
|
131
|
+
database 'db'
|
132
|
+
adapter :mysql
|
133
|
+
connect_with user: 'Foo', password: 'Bar', host: 'localhost'</code></pre>
|
134
|
+
|
135
|
+
|
136
|
+
<pre class="example code"><code># Your methods
|
137
|
+
end</code></pre>
|
138
|
+
|
139
|
+
|
140
|
+
<pre class="example code"><code><span class='comment'># You need to initialize the plug by passing it a table to handle
|
141
|
+
</span><span class='id identifier rubyid_plug'>plug</span> <span class='op'>=</span> <span class='const'>ARSqlitePlug</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:table_for_foo</span>
|
142
|
+
<span class='id identifier rubyid_foo'>foo</span> <span class='op'>=</span> <span class='id identifier rubyid_plug'>plug</span><span class='period'>.</span><span class='id identifier rubyid_table'>table</span> <span class='comment'># => the TableForFoo class, which inherit from ActiveRecord::Base.
|
143
|
+
</span><span class='comment'># Foo is an active record object linked to a table, you can use it as you would usually.
|
144
|
+
</span><span class='id identifier rubyid_foo'>foo</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span></code></pre>
|
145
|
+
|
146
|
+
|
147
|
+
<pre class="example code"><code><span class='comment'># Furthermore, the Binder::AR class, has some interesting class methods :
|
148
|
+
</span><span class='comment'>#
|
149
|
+
</span><span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='op'>::</span><span class='id identifier rubyid_default_database'>default_database</span> <span class='comment'># => ENV['APP_DB'] # This value would be used if no database had been set during the plus creation.
|
150
|
+
</span><span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='op'>::</span><span class='id identifier rubyid_database'>database</span> <span class='comment'># => Returns the current database used by the Binder in general (Would default to ENV['APP_DB'] if not specified)
|
151
|
+
</span><span class='const'>ARSqlitePlug</span><span class='op'>::</span><span class='id identifier rubyid_database'>database</span> <span class='comment'># => :db (Works the same and returns this Plug Class's database parameters)
|
152
|
+
</span><span class='comment'>#
|
153
|
+
</span><span class='comment'># The same goes for the adapters :
|
154
|
+
</span><span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='op'>::</span><span class='id identifier rubyid_default_adapter'>default_adapter</span> <span class='comment'># => :sqlite3
|
155
|
+
</span><span class='const'>ARMySqlPlug</span><span class='op'>::</span><span class='id identifier rubyid_adapter'>adapter</span> <span class='comment'># => :mysql
|
156
|
+
</span><span class='comment'>#
|
157
|
+
</span><span class='comment'># And connection parameters
|
158
|
+
</span><span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='op'>::</span><span class='id identifier rubyid_connection'>connection</span> <span class='comment'># => {}
|
159
|
+
</span><span class='const'>ARMySqlPlug</span><span class='op'>::</span><span class='id identifier rubyid_connection'>connection</span> <span class='comment'># => { :user => 'Foo', :password => 'Bar', :host => 'localhost' }</span></code></pre>
|
160
|
+
|
161
|
+
</div>
|
162
|
+
|
163
|
+
|
164
|
+
</div>
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
|
169
|
+
<ul class="summary">
|
170
|
+
|
171
|
+
<li class="public ">
|
172
|
+
<span class="summary_signature">
|
173
|
+
|
174
|
+
<a href="#table-instance_method" title="#table (instance method)">- (Object) <strong>table</strong> </a>
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
</span>
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
<span class="note title readonly">readonly</span>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
194
|
+
|
195
|
+
</li>
|
196
|
+
|
197
|
+
|
198
|
+
<li class="public ">
|
199
|
+
<span class="summary_signature">
|
200
|
+
|
201
|
+
<a href="#table_name-instance_method" title="#table_name (instance method)">- (Object) <strong>table_name</strong> </a>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
</span>
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
<span class="note title readonly">readonly</span>
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
221
|
+
|
222
|
+
</li>
|
223
|
+
|
224
|
+
|
225
|
+
</ul>
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
<h2>
|
232
|
+
Class Method Summary
|
233
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
234
|
+
</h2>
|
235
|
+
|
236
|
+
<ul class="summary">
|
237
|
+
|
238
|
+
<li class="public ">
|
239
|
+
<span class="summary_signature">
|
240
|
+
|
241
|
+
<a href="#__check_migration_version-class_method" title="__check_migration_version (class method)">+ (Object) <strong>__check_migration_version</strong>(version) </a>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
</span>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
<span class="summary_desc"><div class='inline'>
|
256
|
+
<p>Private : checks the migration version number.</p>
|
257
|
+
</div></span>
|
258
|
+
|
259
|
+
</li>
|
260
|
+
|
261
|
+
|
262
|
+
<li class="public ">
|
263
|
+
<span class="summary_signature">
|
264
|
+
|
265
|
+
<a href="#__create_meta_data_table_for-class_method" title="__create_meta_data_table_for (class method)">+ (Object) <strong>__create_meta_data_table_for</strong>(schema) </a>
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
</span>
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
<span class="summary_desc"><div class='inline'>
|
280
|
+
<p>Private : Create a table for the current meta schema.</p>
|
281
|
+
</div></span>
|
282
|
+
|
283
|
+
</li>
|
284
|
+
|
285
|
+
|
286
|
+
<li class="public ">
|
287
|
+
<span class="summary_signature">
|
288
|
+
|
289
|
+
<a href="#__create_meta_schema_class-class_method" title="__create_meta_schema_class (class method)">+ (Object) <strong>__create_meta_schema_class</strong>(klass) </a>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
</span>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<span class="summary_desc"><div class='inline'>
|
304
|
+
<p>Private: Creates the meta schema class, and binds it to the current
|
305
|
+
Namespace.</p>
|
306
|
+
</div></span>
|
307
|
+
|
308
|
+
</li>
|
309
|
+
|
310
|
+
|
311
|
+
<li class="public ">
|
312
|
+
<span class="summary_signature">
|
313
|
+
|
314
|
+
<a href="#adapter-class_method" title="adapter (class method)">+ (Object) <strong>adapter</strong>(adpt = default_adapter) </a>
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
(also: adaptor)
|
319
|
+
|
320
|
+
</span>
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
<span class="summary_desc"><div class='inline'>
|
331
|
+
<p>Set the current adapter.</p>
|
332
|
+
</div></span>
|
333
|
+
|
334
|
+
</li>
|
335
|
+
|
336
|
+
|
337
|
+
<li class="public ">
|
338
|
+
<span class="summary_signature">
|
339
|
+
|
340
|
+
<a href="#connection-class_method" title="connection (class method)">+ (Object) <strong>connection</strong>(opts = {}) </a>
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
(also: connect_with)
|
345
|
+
|
346
|
+
</span>
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
<span class="summary_desc"><div class='inline'>
|
357
|
+
<p>Set the current connection parameters.</p>
|
358
|
+
</div></span>
|
359
|
+
|
360
|
+
</li>
|
361
|
+
|
362
|
+
|
363
|
+
<li class="public ">
|
364
|
+
<span class="summary_signature">
|
365
|
+
|
366
|
+
<a href="#connection_data-class_method" title="connection_data (class method)">+ (Object) <strong>connection_data</strong> </a>
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
</span>
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
<span class="summary_desc"><div class='inline'>
|
381
|
+
<p>Retrieves a clean set of connection data to establish a connection.</p>
|
382
|
+
</div></span>
|
383
|
+
|
384
|
+
</li>
|
385
|
+
|
386
|
+
|
387
|
+
<li class="public ">
|
388
|
+
<span class="summary_signature">
|
389
|
+
|
390
|
+
<a href="#database-class_method" title="database (class method)">+ (Object) <strong>database</strong>(db = default_database) </a>
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
</span>
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
<span class="summary_desc"><div class='inline'>
|
405
|
+
<p>Set the current database.</p>
|
406
|
+
</div></span>
|
407
|
+
|
408
|
+
</li>
|
409
|
+
|
410
|
+
|
411
|
+
<li class="public ">
|
412
|
+
<span class="summary_signature">
|
413
|
+
|
414
|
+
<a href="#default_adapter-class_method" title="default_adapter (class method)">+ (Object) <strong>default_adapter</strong> </a>
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
</span>
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
<span class="summary_desc"><div class='inline'>
|
429
|
+
<p>Retrieves de default database.</p>
|
430
|
+
</div></span>
|
431
|
+
|
432
|
+
</li>
|
433
|
+
|
434
|
+
|
435
|
+
<li class="public ">
|
436
|
+
<span class="summary_signature">
|
437
|
+
|
438
|
+
<a href="#default_database-class_method" title="default_database (class method)">+ ('APP_DB'\) <strong>default_database</strong> </a>
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
</span>
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
<span class="summary_desc"><div class='inline'>
|
453
|
+
<p>Retrieves de default database.</p>
|
454
|
+
</div></span>
|
455
|
+
|
456
|
+
</li>
|
457
|
+
|
458
|
+
|
459
|
+
<li class="public ">
|
460
|
+
<span class="summary_signature">
|
461
|
+
|
462
|
+
<a href="#meta_schema-class_method" title="meta_schema (class method)">+ (Object) <strong>meta_schema</strong> </a>
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
</span>
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
|
476
|
+
<span class="summary_desc"><div class='inline'>
|
477
|
+
<p>Private: Get the Class holding the current migration metadatas.</p>
|
478
|
+
</div></span>
|
479
|
+
|
480
|
+
</li>
|
481
|
+
|
482
|
+
|
483
|
+
<li class="public ">
|
484
|
+
<span class="summary_signature">
|
485
|
+
|
486
|
+
<a href="#migrate-class_method" title="migrate (class method)">+ (Object) <strong>migrate</strong>(version = nil) </a>
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
</span>
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
|
500
|
+
<span class="summary_desc"><div class='inline'>
|
501
|
+
<p>Executes a migration.</p>
|
502
|
+
</div></span>
|
503
|
+
|
504
|
+
</li>
|
505
|
+
|
506
|
+
|
507
|
+
<li class="public ">
|
508
|
+
<span class="summary_signature">
|
509
|
+
|
510
|
+
<a href="#Version-class_method" title="Version (class method)">+ (Object) <strong>Version</strong>(n) </a>
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
</span>
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
<span class="summary_desc"><div class='inline'>
|
525
|
+
<p>Creates a new migration version through subclassing.</p>
|
526
|
+
</div></span>
|
527
|
+
|
528
|
+
</li>
|
529
|
+
|
530
|
+
|
531
|
+
</ul>
|
532
|
+
|
533
|
+
<h2>
|
534
|
+
Instance Method Summary
|
535
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
536
|
+
</h2>
|
537
|
+
|
538
|
+
<ul class="summary">
|
539
|
+
|
540
|
+
<li class="public ">
|
541
|
+
<span class="summary_signature">
|
542
|
+
|
543
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (Object) <strong>initialize</strong>(table_name) </a>
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
</span>
|
548
|
+
|
549
|
+
|
550
|
+
<span class="note title constructor">constructor</span>
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
<span class="summary_desc"><div class='inline'>
|
560
|
+
<p>Returns a new instance of the binder's class.</p>
|
561
|
+
</div></span>
|
562
|
+
|
563
|
+
</li>
|
564
|
+
|
565
|
+
|
566
|
+
</ul>
|
567
|
+
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="../DeferedDelegator.html" title="DeferedDelegator (module)">DeferedDelegator</a></span></h3>
|
579
|
+
<p class="inherited"><span class='object_link'><a href="../DeferedDelegator.html#delegate_to-instance_method" title="DeferedDelegator#delegate_to (method)">delegate_to</a></span>, <span class='object_link'><a href="../DeferedDelegator.html#register_delegators-instance_method" title="DeferedDelegator#register_delegators (method)">register_delegators</a></span></p>
|
580
|
+
<div id="constructor_details" class="method_details_list">
|
581
|
+
<h2>Constructor Details</h2>
|
582
|
+
|
583
|
+
<div class="method_details first">
|
584
|
+
<h3 class="signature first" id="initialize-instance_method">
|
585
|
+
|
586
|
+
- (<tt>Object</tt>) <strong>initialize</strong>(table_name)
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
|
592
|
+
</h3><div class="docstring">
|
593
|
+
<div class="discussion">
|
594
|
+
|
595
|
+
<p>Returns a new instance of the binder's class. It also automaticaly
|
596
|
+
establish a connection with the database throught the specified adapter,
|
597
|
+
but prevents trying to reconnect if the connection is already established.</p>
|
598
|
+
|
599
|
+
|
600
|
+
</div>
|
601
|
+
</div>
|
602
|
+
<div class="tags">
|
603
|
+
|
604
|
+
<div class="examples">
|
605
|
+
<p class="tag_title">Examples:</p>
|
606
|
+
|
607
|
+
|
608
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Plug</span> <span class='op'><</span> <span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
609
|
+
<span class='id identifier rubyid_plug'>plug</span> <span class='op'>=</span> <span class='const'>Plug</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:articles</span>
|
610
|
+
<span class='id identifier rubyid_plug'>plug</span><span class='period'>.</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span> <span class='comment'># [<Article#1>, <Article#2>] # Works, the connection has been established.</span></code></pre>
|
611
|
+
|
612
|
+
</div>
|
613
|
+
<p class="tag_title">Parameters:</p>
|
614
|
+
<ul class="param">
|
615
|
+
|
616
|
+
<li>
|
617
|
+
|
618
|
+
<span class='name'>table_name</span>
|
619
|
+
|
620
|
+
|
621
|
+
<span class='type'></span>
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
—
|
626
|
+
<div class='inline'>
|
627
|
+
<p>A String or Symbol representing the table to which we want to be bound.</p>
|
628
|
+
</div>
|
629
|
+
|
630
|
+
</li>
|
631
|
+
|
632
|
+
</ul>
|
633
|
+
|
634
|
+
|
635
|
+
</div><table class="source_code">
|
636
|
+
<tr>
|
637
|
+
<td>
|
638
|
+
<pre class="lines">
|
639
|
+
|
640
|
+
|
641
|
+
70
|
642
|
+
71
|
643
|
+
72
|
644
|
+
73
|
645
|
+
74
|
646
|
+
75
|
647
|
+
76
|
648
|
+
77
|
649
|
+
78
|
650
|
+
79
|
651
|
+
80
|
652
|
+
81</pre>
|
653
|
+
</td>
|
654
|
+
<td>
|
655
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 70</span>
|
656
|
+
|
657
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span> <span class='id identifier rubyid_table_name'>table_name</span>
|
658
|
+
<span class='ivar'>@table_name</span> <span class='op'>=</span> <span class='id identifier rubyid_table_name'>table_name</span>
|
659
|
+
|
660
|
+
<span class='comment'># Retrieves or Create the ActiveRecord::Base subclass that will match the table.
|
661
|
+
</span> <span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='id identifier rubyid_meta_def_ar_class'>meta_def_ar_class</span>
|
662
|
+
|
663
|
+
<span class='comment'># Handle ActiveRecord::Base delegation, to ensure painless associations
|
664
|
+
</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_delegate_to'>delegate_to</span> <span class='id identifier rubyid_table'>table</span>
|
665
|
+
|
666
|
+
<span class='comment'># Establishes a connection to the database
|
667
|
+
</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_connect'>connect</span> <span class='kw'>unless</span> <span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_connected?'>connected?</span>
|
668
|
+
<span class='kw'>end</span></pre>
|
669
|
+
</td>
|
670
|
+
</tr>
|
671
|
+
</table>
|
672
|
+
</div>
|
673
|
+
|
674
|
+
</div>
|
675
|
+
|
676
|
+
<div id="instance_attr_details" class="attr_details">
|
677
|
+
<h2>Instance Attribute Details</h2>
|
678
|
+
|
679
|
+
|
680
|
+
<span id=""></span>
|
681
|
+
<div class="method_details first">
|
682
|
+
<h3 class="signature first" id="table-instance_method">
|
683
|
+
|
684
|
+
- (<tt>Object</tt>) <strong>table</strong> <span class="extras">(readonly)</span>
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
|
690
|
+
</h3><div class="docstring">
|
691
|
+
<div class="discussion">
|
692
|
+
|
693
|
+
|
694
|
+
</div>
|
695
|
+
</div>
|
696
|
+
<div class="tags">
|
697
|
+
|
698
|
+
|
699
|
+
</div><table class="source_code">
|
700
|
+
<tr>
|
701
|
+
<td>
|
702
|
+
<pre class="lines">
|
703
|
+
|
704
|
+
|
705
|
+
54
|
706
|
+
55
|
707
|
+
56</pre>
|
708
|
+
</td>
|
709
|
+
<td>
|
710
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 54</span>
|
711
|
+
|
712
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_table'>table</span>
|
713
|
+
<span class='ivar'>@table</span>
|
714
|
+
<span class='kw'>end</span></pre>
|
715
|
+
</td>
|
716
|
+
</tr>
|
717
|
+
</table>
|
718
|
+
</div>
|
719
|
+
|
720
|
+
|
721
|
+
<span id=""></span>
|
722
|
+
<div class="method_details ">
|
723
|
+
<h3 class="signature " id="table_name-instance_method">
|
724
|
+
|
725
|
+
- (<tt>Object</tt>) <strong>table_name</strong> <span class="extras">(readonly)</span>
|
726
|
+
|
727
|
+
|
728
|
+
|
729
|
+
|
730
|
+
|
731
|
+
</h3><div class="docstring">
|
732
|
+
<div class="discussion">
|
733
|
+
|
734
|
+
|
735
|
+
</div>
|
736
|
+
</div>
|
737
|
+
<div class="tags">
|
738
|
+
|
739
|
+
|
740
|
+
</div><table class="source_code">
|
741
|
+
<tr>
|
742
|
+
<td>
|
743
|
+
<pre class="lines">
|
744
|
+
|
745
|
+
|
746
|
+
54
|
747
|
+
55
|
748
|
+
56</pre>
|
749
|
+
</td>
|
750
|
+
<td>
|
751
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 54</span>
|
752
|
+
|
753
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_table_name'>table_name</span>
|
754
|
+
<span class='ivar'>@table_name</span>
|
755
|
+
<span class='kw'>end</span></pre>
|
756
|
+
</td>
|
757
|
+
</tr>
|
758
|
+
</table>
|
759
|
+
</div>
|
760
|
+
|
761
|
+
</div>
|
762
|
+
|
763
|
+
|
764
|
+
<div id="class_method_details" class="method_details_list">
|
765
|
+
<h2>Class Method Details</h2>
|
766
|
+
|
767
|
+
|
768
|
+
<div class="method_details first">
|
769
|
+
<h3 class="signature first" id="__check_migration_version-class_method">
|
770
|
+
|
771
|
+
+ (<tt>Object</tt>) <strong>__check_migration_version</strong>(version)
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
|
776
|
+
|
777
|
+
</h3><div class="docstring">
|
778
|
+
<div class="discussion">
|
779
|
+
|
780
|
+
<p>Private : checks the migration version number</p>
|
781
|
+
|
782
|
+
|
783
|
+
</div>
|
784
|
+
</div>
|
785
|
+
<div class="tags">
|
786
|
+
|
787
|
+
<p class="tag_title">Returns:</p>
|
788
|
+
<ul class="return">
|
789
|
+
|
790
|
+
<li>
|
791
|
+
|
792
|
+
|
793
|
+
<span class='type'></span>
|
794
|
+
|
795
|
+
|
796
|
+
|
797
|
+
|
798
|
+
<div class='inline'>
|
799
|
+
<p>the version as a Float.</p>
|
800
|
+
</div>
|
801
|
+
|
802
|
+
</li>
|
803
|
+
|
804
|
+
</ul>
|
805
|
+
<p class="tag_title">Raises:</p>
|
806
|
+
<ul class="raise">
|
807
|
+
|
808
|
+
<li>
|
809
|
+
|
810
|
+
|
811
|
+
<span class='type'></span>
|
812
|
+
|
813
|
+
|
814
|
+
|
815
|
+
|
816
|
+
<div class='inline'>
|
817
|
+
<p>MigrationVersionError if the required version does not exist.</p>
|
818
|
+
</div>
|
819
|
+
|
820
|
+
</li>
|
821
|
+
|
822
|
+
</ul>
|
823
|
+
|
824
|
+
</div><table class="source_code">
|
825
|
+
<tr>
|
826
|
+
<td>
|
827
|
+
<pre class="lines">
|
828
|
+
|
829
|
+
|
830
|
+
328
|
831
|
+
329
|
832
|
+
330
|
833
|
+
331</pre>
|
834
|
+
</td>
|
835
|
+
<td>
|
836
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 328</span>
|
837
|
+
|
838
|
+
<span class='kw'>def</span> <span class='id identifier rubyid___check_migration_version'>__check_migration_version</span> <span class='id identifier rubyid_version'>version</span>
|
839
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>MigrationVersionError</span> <span class='kw'>if</span> <span class='kw'>not</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='kw'>and</span> <span class='ivar'>@last_version</span> <span class='op'><</span> <span class='id identifier rubyid_version'>version</span>
|
840
|
+
<span class='id identifier rubyid_version'>version</span> <span class='op'>||=</span> <span class='ivar'>@last_version</span>
|
841
|
+
<span class='kw'>end</span></pre>
|
842
|
+
</td>
|
843
|
+
</tr>
|
844
|
+
</table>
|
845
|
+
</div>
|
846
|
+
|
847
|
+
<div class="method_details ">
|
848
|
+
<h3 class="signature " id="__create_meta_data_table_for-class_method">
|
849
|
+
|
850
|
+
+ (<tt>Object</tt>) <strong>__create_meta_data_table_for</strong>(schema)
|
851
|
+
|
852
|
+
|
853
|
+
|
854
|
+
|
855
|
+
|
856
|
+
</h3><div class="docstring">
|
857
|
+
<div class="discussion">
|
858
|
+
|
859
|
+
<p>Private : Create a table for the current meta schema.</p>
|
860
|
+
|
861
|
+
|
862
|
+
</div>
|
863
|
+
</div>
|
864
|
+
<div class="tags">
|
865
|
+
|
866
|
+
<div class="examples">
|
867
|
+
<p class="tag_title">Examples:</p>
|
868
|
+
|
869
|
+
|
870
|
+
<pre class="example code"><code><span class='id identifier rubyid___create_meta_data_table_for'>__create_meta_data_table_for</span> <span class='const'>MyPlug</span> <span class='comment'># Will create a my_plug_meta_schemas table.</span></code></pre>
|
871
|
+
|
872
|
+
</div>
|
873
|
+
<p class="tag_title">Parameters:</p>
|
874
|
+
<ul class="param">
|
875
|
+
|
876
|
+
<li>
|
877
|
+
|
878
|
+
<span class='name'>schema</span>
|
879
|
+
|
880
|
+
|
881
|
+
<span class='type'></span>
|
882
|
+
|
883
|
+
|
884
|
+
|
885
|
+
—
|
886
|
+
<div class='inline'>
|
887
|
+
<p>The schema Class for which we want to create the table.</p>
|
888
|
+
</div>
|
889
|
+
|
890
|
+
</li>
|
891
|
+
|
892
|
+
</ul>
|
893
|
+
|
894
|
+
<p class="tag_title">Returns:</p>
|
895
|
+
<ul class="return">
|
896
|
+
|
897
|
+
<li>
|
898
|
+
|
899
|
+
|
900
|
+
<span class='type'></span>
|
901
|
+
|
902
|
+
|
903
|
+
|
904
|
+
|
905
|
+
<div class='inline'>
|
906
|
+
<p>Nothing.</p>
|
907
|
+
</div>
|
908
|
+
|
909
|
+
</li>
|
910
|
+
|
911
|
+
</ul>
|
912
|
+
|
913
|
+
</div><table class="source_code">
|
914
|
+
<tr>
|
915
|
+
<td>
|
916
|
+
<pre class="lines">
|
917
|
+
|
918
|
+
|
919
|
+
308
|
920
|
+
309
|
921
|
+
310
|
922
|
+
311
|
923
|
+
312
|
924
|
+
313
|
925
|
+
314
|
926
|
+
315
|
927
|
+
316
|
928
|
+
317
|
929
|
+
318
|
930
|
+
319
|
931
|
+
320
|
932
|
+
321</pre>
|
933
|
+
</td>
|
934
|
+
<td>
|
935
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 308</span>
|
936
|
+
|
937
|
+
<span class='kw'>def</span> <span class='id identifier rubyid___create_meta_data_table_for'>__create_meta_data_table_for</span> <span class='id identifier rubyid_schema'>schema</span>
|
938
|
+
<span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Base</span><span class='period'>.</span><span class='id identifier rubyid_establish_connection'>establish_connection</span><span class='lparen'>(</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_connection_data'>connection_data</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_schema'>schema</span><span class='period'>.</span><span class='id identifier rubyid_connected?'>connected?</span>
|
939
|
+
|
940
|
+
<span class='comment'># Clears the table cache for the schema (remove TableDoesNotExists if a table actually exists)
|
941
|
+
</span> <span class='id identifier rubyid_schema'>schema</span><span class='period'>.</span><span class='id identifier rubyid_clear_cache!'>clear_cache!</span>
|
942
|
+
|
943
|
+
<span class='kw'>unless</span> <span class='id identifier rubyid_schema'>schema</span><span class='period'>.</span><span class='id identifier rubyid_table_exists?'>table_exists?</span>
|
944
|
+
<span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_define'>define</span> <span class='kw'>do</span>
|
945
|
+
<span class='id identifier rubyid_create_table'>create_table</span> <span class='id identifier rubyid_schema'>schema</span><span class='period'>.</span><span class='id identifier rubyid_table_name'>table_name</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_t'>t</span><span class='op'>|</span>
|
946
|
+
<span class='id identifier rubyid_t'>t</span><span class='period'>.</span><span class='id identifier rubyid_column'>column</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='symbol'>:float</span>
|
947
|
+
<span class='kw'>end</span>
|
948
|
+
<span class='kw'>end</span>
|
949
|
+
<span class='kw'>end</span>
|
950
|
+
<span class='kw'>end</span></pre>
|
951
|
+
</td>
|
952
|
+
</tr>
|
953
|
+
</table>
|
954
|
+
</div>
|
955
|
+
|
956
|
+
<div class="method_details ">
|
957
|
+
<h3 class="signature " id="__create_meta_schema_class-class_method">
|
958
|
+
|
959
|
+
+ (<tt>Object</tt>) <strong>__create_meta_schema_class</strong>(klass)
|
960
|
+
|
961
|
+
|
962
|
+
|
963
|
+
|
964
|
+
|
965
|
+
</h3><div class="docstring">
|
966
|
+
<div class="discussion">
|
967
|
+
|
968
|
+
<p>Private: Creates the meta schema class, and binds it to the current
|
969
|
+
Namespace.</p>
|
970
|
+
|
971
|
+
|
972
|
+
</div>
|
973
|
+
</div>
|
974
|
+
<div class="tags">
|
975
|
+
|
976
|
+
<div class="examples">
|
977
|
+
<p class="tag_title">Examples:</p>
|
978
|
+
|
979
|
+
|
980
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Plug</span> <span class='op'><</span> <span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
981
|
+
<span class='id identifier rubyid___create_meta_schema_class'>__create_meta_schema_class</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>MetaSchema</span><span class='tstring_end'>"</span></span>
|
982
|
+
<span class='comment'># => Plug::MetaSchema</span></code></pre>
|
983
|
+
|
984
|
+
</div>
|
985
|
+
|
986
|
+
<p class="tag_title">Returns:</p>
|
987
|
+
<ul class="return">
|
988
|
+
|
989
|
+
<li>
|
990
|
+
|
991
|
+
|
992
|
+
<span class='type'></span>
|
993
|
+
|
994
|
+
|
995
|
+
|
996
|
+
|
997
|
+
<div class='inline'>
|
998
|
+
<p>a new Class inheriting from ActiveRecord::Base.</p>
|
999
|
+
</div>
|
1000
|
+
|
1001
|
+
</li>
|
1002
|
+
|
1003
|
+
</ul>
|
1004
|
+
|
1005
|
+
</div><table class="source_code">
|
1006
|
+
<tr>
|
1007
|
+
<td>
|
1008
|
+
<pre class="lines">
|
1009
|
+
|
1010
|
+
|
1011
|
+
342
|
1012
|
+
343
|
1013
|
+
344
|
1014
|
+
345
|
1015
|
+
346
|
1016
|
+
347
|
1017
|
+
348
|
1018
|
+
349
|
1019
|
+
350</pre>
|
1020
|
+
</td>
|
1021
|
+
<td>
|
1022
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 342</span>
|
1023
|
+
|
1024
|
+
<span class='kw'>def</span> <span class='id identifier rubyid___create_meta_schema_class'>__create_meta_schema_class</span> <span class='id identifier rubyid_klass'>klass</span>
|
1025
|
+
<span class='id identifier rubyid_binder'>binder</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span>
|
1026
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_const_set'>const_set</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='comma'>,</span>
|
1027
|
+
<span class='const'>Class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Base</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='comment'># class MetaSchema < ActiveRecord::Base
|
1028
|
+
</span> <span class='id identifier rubyid_singleton_class'>singleton_class</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:define_method</span><span class='comma'>,</span> <span class='symbol'>:table_name_prefix</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='comment'># def self.table_name_prefix
|
1029
|
+
</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_binder'>binder</span><span class='period'>.</span><span class='id identifier rubyid_underscore'>underscore</span><span class='rbrace'>}</span><span class='tstring_content'>_</span><span class='tstring_end'>"</span></span> <span class='comment'># "foo_binder" # If we have a class FooBinder < Binder::AR
|
1030
|
+
</span> <span class='kw'>end</span> <span class='comment'># end
|
1031
|
+
</span> <span class='kw'>end</span><span class='rparen'>)</span> <span class='comment'># end
|
1032
|
+
</span><span class='kw'>end</span></pre>
|
1033
|
+
</td>
|
1034
|
+
</tr>
|
1035
|
+
</table>
|
1036
|
+
</div>
|
1037
|
+
|
1038
|
+
<div class="method_details ">
|
1039
|
+
<h3 class="signature " id="adapter-class_method">
|
1040
|
+
|
1041
|
+
+ (<tt>Object</tt>) <strong>adapter</strong>(adpt = default_adapter)
|
1042
|
+
|
1043
|
+
|
1044
|
+
|
1045
|
+
<span class="aliases">Also known as:
|
1046
|
+
<span class="names"><span id='adaptor-class_method'>adaptor</span></span>
|
1047
|
+
</span>
|
1048
|
+
|
1049
|
+
|
1050
|
+
|
1051
|
+
</h3><div class="docstring">
|
1052
|
+
<div class="discussion">
|
1053
|
+
|
1054
|
+
<p>Set the current adapter</p>
|
1055
|
+
|
1056
|
+
|
1057
|
+
</div>
|
1058
|
+
</div>
|
1059
|
+
<div class="tags">
|
1060
|
+
|
1061
|
+
<div class="examples">
|
1062
|
+
<p class="tag_title">Examples:</p>
|
1063
|
+
|
1064
|
+
|
1065
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Plug</span> <span class='op'><</span> <span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span>
|
1066
|
+
<span class='id identifier rubyid_adapter'>adapter</span> <span class='symbol'>:foobar</span>
|
1067
|
+
<span class='kw'>end</span></code></pre>
|
1068
|
+
|
1069
|
+
</div>
|
1070
|
+
<p class="tag_title">Parameters:</p>
|
1071
|
+
<ul class="param">
|
1072
|
+
|
1073
|
+
<li>
|
1074
|
+
|
1075
|
+
<span class='name'>adpt</span>
|
1076
|
+
|
1077
|
+
|
1078
|
+
<span class='type'></span>
|
1079
|
+
|
1080
|
+
|
1081
|
+
<em class="default">(defaults to: <tt>default_adapter</tt>)</em>
|
1082
|
+
|
1083
|
+
|
1084
|
+
—
|
1085
|
+
<div class='inline'>
|
1086
|
+
<p>the adapter, as a String or Symbol. (default: Binder::AR.default_adapter)</p>
|
1087
|
+
</div>
|
1088
|
+
|
1089
|
+
</li>
|
1090
|
+
|
1091
|
+
</ul>
|
1092
|
+
|
1093
|
+
<p class="tag_title">Returns:</p>
|
1094
|
+
<ul class="return">
|
1095
|
+
|
1096
|
+
<li>
|
1097
|
+
|
1098
|
+
|
1099
|
+
<span class='type'></span>
|
1100
|
+
|
1101
|
+
|
1102
|
+
|
1103
|
+
|
1104
|
+
<div class='inline'>
|
1105
|
+
<p>the current database.</p>
|
1106
|
+
</div>
|
1107
|
+
|
1108
|
+
</li>
|
1109
|
+
|
1110
|
+
</ul>
|
1111
|
+
|
1112
|
+
</div><table class="source_code">
|
1113
|
+
<tr>
|
1114
|
+
<td>
|
1115
|
+
<pre class="lines">
|
1116
|
+
|
1117
|
+
|
1118
|
+
139
|
1119
|
+
140
|
1120
|
+
141
|
1121
|
+
142
|
1122
|
+
143
|
1123
|
+
144
|
1124
|
+
145</pre>
|
1125
|
+
</td>
|
1126
|
+
<td>
|
1127
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 139</span>
|
1128
|
+
|
1129
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_adapter'>adapter</span> <span class='id identifier rubyid_adpt'>adpt</span> <span class='op'>=</span> <span class='id identifier rubyid_default_adapter'>default_adapter</span>
|
1130
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_adpt'>adpt</span> <span class='op'>==</span> <span class='id identifier rubyid_default_adapter'>default_adapter</span>
|
1131
|
+
<span class='ivar'>@adapter</span> <span class='op'>||=</span> <span class='id identifier rubyid_adpt'>adpt</span>
|
1132
|
+
<span class='kw'>else</span>
|
1133
|
+
<span class='ivar'>@adapter</span> <span class='op'>=</span> <span class='id identifier rubyid_adpt'>adpt</span>
|
1134
|
+
<span class='kw'>end</span>
|
1135
|
+
<span class='kw'>end</span></pre>
|
1136
|
+
</td>
|
1137
|
+
</tr>
|
1138
|
+
</table>
|
1139
|
+
</div>
|
1140
|
+
|
1141
|
+
<div class="method_details ">
|
1142
|
+
<h3 class="signature " id="connection-class_method">
|
1143
|
+
|
1144
|
+
+ (<tt>Object</tt>) <strong>connection</strong>(opts = {})
|
1145
|
+
|
1146
|
+
|
1147
|
+
|
1148
|
+
<span class="aliases">Also known as:
|
1149
|
+
<span class="names"><span id='connect_with-class_method'>connect_with</span></span>
|
1150
|
+
</span>
|
1151
|
+
|
1152
|
+
|
1153
|
+
|
1154
|
+
</h3><div class="docstring">
|
1155
|
+
<div class="discussion">
|
1156
|
+
|
1157
|
+
<p>Set the current connection parameters</p>
|
1158
|
+
|
1159
|
+
|
1160
|
+
</div>
|
1161
|
+
</div>
|
1162
|
+
<div class="tags">
|
1163
|
+
|
1164
|
+
<div class="examples">
|
1165
|
+
<p class="tag_title">Examples:</p>
|
1166
|
+
|
1167
|
+
|
1168
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Plug</span> <span class='op'><</span> <span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span>
|
1169
|
+
<span class='id identifier rubyid_adapter'>adapter</span> <span class='symbol'>:foobar</span>
|
1170
|
+
<span class='kw'>end</span></code></pre>
|
1171
|
+
|
1172
|
+
</div>
|
1173
|
+
<p class="tag_title">Parameters:</p>
|
1174
|
+
<ul class="param">
|
1175
|
+
|
1176
|
+
<li>
|
1177
|
+
|
1178
|
+
<span class='name'>opts</span>
|
1179
|
+
|
1180
|
+
|
1181
|
+
<span class='type'></span>
|
1182
|
+
|
1183
|
+
|
1184
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
1185
|
+
|
1186
|
+
|
1187
|
+
—
|
1188
|
+
<div class='inline'>
|
1189
|
+
<p>A Hash, containing options to pass to the
|
1190
|
+
ActiveRecord::Base.establish_connection call (default: {}) user - A user
|
1191
|
+
name as a String. password - A password as a String. host - A host String.</p>
|
1192
|
+
</div>
|
1193
|
+
|
1194
|
+
</li>
|
1195
|
+
|
1196
|
+
</ul>
|
1197
|
+
|
1198
|
+
<p class="tag_title">Returns:</p>
|
1199
|
+
<ul class="return">
|
1200
|
+
|
1201
|
+
<li>
|
1202
|
+
|
1203
|
+
|
1204
|
+
<span class='type'></span>
|
1205
|
+
|
1206
|
+
|
1207
|
+
|
1208
|
+
|
1209
|
+
<div class='inline'>
|
1210
|
+
<p>the current database.</p>
|
1211
|
+
</div>
|
1212
|
+
|
1213
|
+
</li>
|
1214
|
+
|
1215
|
+
</ul>
|
1216
|
+
|
1217
|
+
</div><table class="source_code">
|
1218
|
+
<tr>
|
1219
|
+
<td>
|
1220
|
+
<pre class="lines">
|
1221
|
+
|
1222
|
+
|
1223
|
+
162
|
1224
|
+
163
|
1225
|
+
164</pre>
|
1226
|
+
</td>
|
1227
|
+
<td>
|
1228
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 162</span>
|
1229
|
+
|
1230
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_connection'>connection</span> <span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
1231
|
+
<span class='ivar'>@connection</span> <span class='op'>||=</span> <span class='id identifier rubyid_opts'>opts</span>
|
1232
|
+
<span class='kw'>end</span></pre>
|
1233
|
+
</td>
|
1234
|
+
</tr>
|
1235
|
+
</table>
|
1236
|
+
</div>
|
1237
|
+
|
1238
|
+
<div class="method_details ">
|
1239
|
+
<h3 class="signature " id="connection_data-class_method">
|
1240
|
+
|
1241
|
+
+ (<tt>Object</tt>) <strong>connection_data</strong>
|
1242
|
+
|
1243
|
+
|
1244
|
+
|
1245
|
+
|
1246
|
+
|
1247
|
+
</h3><div class="docstring">
|
1248
|
+
<div class="discussion">
|
1249
|
+
|
1250
|
+
<p>Retrieves a clean set of connection data to establish a connection</p>
|
1251
|
+
|
1252
|
+
|
1253
|
+
</div>
|
1254
|
+
</div>
|
1255
|
+
<div class="tags">
|
1256
|
+
|
1257
|
+
<p class="tag_title">Returns:</p>
|
1258
|
+
<ul class="return">
|
1259
|
+
|
1260
|
+
<li>
|
1261
|
+
|
1262
|
+
|
1263
|
+
<span class='type'></span>
|
1264
|
+
|
1265
|
+
|
1266
|
+
|
1267
|
+
|
1268
|
+
<div class='inline'>
|
1269
|
+
<p>a Hash.</p>
|
1270
|
+
</div>
|
1271
|
+
|
1272
|
+
</li>
|
1273
|
+
|
1274
|
+
</ul>
|
1275
|
+
|
1276
|
+
</div><table class="source_code">
|
1277
|
+
<tr>
|
1278
|
+
<td>
|
1279
|
+
<pre class="lines">
|
1280
|
+
|
1281
|
+
|
1282
|
+
170
|
1283
|
+
171
|
1284
|
+
172
|
1285
|
+
173
|
1286
|
+
174
|
1287
|
+
175
|
1288
|
+
176
|
1289
|
+
177</pre>
|
1290
|
+
</td>
|
1291
|
+
<td>
|
1292
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 170</span>
|
1293
|
+
|
1294
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_connection_data'>connection_data</span>
|
1295
|
+
<span class='id identifier rubyid_opts'>opts</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>database:</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_database'>database</span><span class='comma'>,</span> <span class='label'>adapter:</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_adapter'>adapter</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_connection'>connection</span><span class='rparen'>)</span>
|
1296
|
+
<span class='comment'># We ensure we have a string for the adapter
|
1297
|
+
</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:adapter</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:adapter</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
|
1298
|
+
<span class='comment'># If we have a symbol for the database and the adapter is sqlite3, we create a string and add '.sqlite3' to the end
|
1299
|
+
</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:database</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:database</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_content'>.sqlite3</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:adapter</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sqlite3</span><span class='tstring_end'>'</span></span> <span class='kw'>and</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:database</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='const'>Symbol</span>
|
1300
|
+
<span class='id identifier rubyid_opts'>opts</span>
|
1301
|
+
<span class='kw'>end</span></pre>
|
1302
|
+
</td>
|
1303
|
+
</tr>
|
1304
|
+
</table>
|
1305
|
+
</div>
|
1306
|
+
|
1307
|
+
<div class="method_details ">
|
1308
|
+
<h3 class="signature " id="database-class_method">
|
1309
|
+
|
1310
|
+
+ (<tt>Object</tt>) <strong>database</strong>(db = default_database)
|
1311
|
+
|
1312
|
+
|
1313
|
+
|
1314
|
+
|
1315
|
+
|
1316
|
+
</h3><div class="docstring">
|
1317
|
+
<div class="discussion">
|
1318
|
+
|
1319
|
+
<p>Set the current database</p>
|
1320
|
+
|
1321
|
+
|
1322
|
+
</div>
|
1323
|
+
</div>
|
1324
|
+
<div class="tags">
|
1325
|
+
|
1326
|
+
<div class="examples">
|
1327
|
+
<p class="tag_title">Examples:</p>
|
1328
|
+
|
1329
|
+
|
1330
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Plug</span> <span class='op'><</span> <span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span>
|
1331
|
+
<span class='id identifier rubyid_database'>database</span> <span class='symbol'>:foobar</span>
|
1332
|
+
<span class='kw'>end</span></code></pre>
|
1333
|
+
|
1334
|
+
</div>
|
1335
|
+
<p class="tag_title">Parameters:</p>
|
1336
|
+
<ul class="param">
|
1337
|
+
|
1338
|
+
<li>
|
1339
|
+
|
1340
|
+
<span class='name'>db</span>
|
1341
|
+
|
1342
|
+
|
1343
|
+
<span class='type'></span>
|
1344
|
+
|
1345
|
+
|
1346
|
+
<em class="default">(defaults to: <tt>default_database</tt>)</em>
|
1347
|
+
|
1348
|
+
|
1349
|
+
—
|
1350
|
+
<div class='inline'>
|
1351
|
+
<p>the database, as a String or Symbol. (default: Binder::AR.default_database)</p>
|
1352
|
+
</div>
|
1353
|
+
|
1354
|
+
</li>
|
1355
|
+
|
1356
|
+
</ul>
|
1357
|
+
|
1358
|
+
<p class="tag_title">Returns:</p>
|
1359
|
+
<ul class="return">
|
1360
|
+
|
1361
|
+
<li>
|
1362
|
+
|
1363
|
+
|
1364
|
+
<span class='type'></span>
|
1365
|
+
|
1366
|
+
|
1367
|
+
|
1368
|
+
|
1369
|
+
<div class='inline'>
|
1370
|
+
<p>the current database.</p>
|
1371
|
+
</div>
|
1372
|
+
|
1373
|
+
</li>
|
1374
|
+
|
1375
|
+
</ul>
|
1376
|
+
|
1377
|
+
</div><table class="source_code">
|
1378
|
+
<tr>
|
1379
|
+
<td>
|
1380
|
+
<pre class="lines">
|
1381
|
+
|
1382
|
+
|
1383
|
+
120
|
1384
|
+
121
|
1385
|
+
122
|
1386
|
+
123
|
1387
|
+
124
|
1388
|
+
125
|
1389
|
+
126</pre>
|
1390
|
+
</td>
|
1391
|
+
<td>
|
1392
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 120</span>
|
1393
|
+
|
1394
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_database'>database</span> <span class='id identifier rubyid_db'>db</span> <span class='op'>=</span> <span class='id identifier rubyid_default_database'>default_database</span>
|
1395
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_db'>db</span> <span class='op'>==</span> <span class='id identifier rubyid_default_database'>default_database</span>
|
1396
|
+
<span class='ivar'>@database</span> <span class='op'>||=</span> <span class='id identifier rubyid_db'>db</span>
|
1397
|
+
<span class='kw'>else</span>
|
1398
|
+
<span class='ivar'>@database</span> <span class='op'>=</span> <span class='id identifier rubyid_db'>db</span>
|
1399
|
+
<span class='kw'>end</span>
|
1400
|
+
<span class='kw'>end</span></pre>
|
1401
|
+
</td>
|
1402
|
+
</tr>
|
1403
|
+
</table>
|
1404
|
+
</div>
|
1405
|
+
|
1406
|
+
<div class="method_details ">
|
1407
|
+
<h3 class="signature " id="default_adapter-class_method">
|
1408
|
+
|
1409
|
+
+ (<tt>Object</tt>) <strong>default_adapter</strong>
|
1410
|
+
|
1411
|
+
|
1412
|
+
|
1413
|
+
|
1414
|
+
|
1415
|
+
</h3><div class="docstring">
|
1416
|
+
<div class="discussion">
|
1417
|
+
|
1418
|
+
<p>Retrieves de default database</p>
|
1419
|
+
|
1420
|
+
|
1421
|
+
</div>
|
1422
|
+
</div>
|
1423
|
+
<div class="tags">
|
1424
|
+
|
1425
|
+
<p class="tag_title">Returns:</p>
|
1426
|
+
<ul class="return">
|
1427
|
+
|
1428
|
+
<li>
|
1429
|
+
|
1430
|
+
|
1431
|
+
<span class='type'></span>
|
1432
|
+
|
1433
|
+
|
1434
|
+
|
1435
|
+
|
1436
|
+
<div class='inline'>
|
1437
|
+
<p>a the content of :sqlite3, as a Symbol.</p>
|
1438
|
+
</div>
|
1439
|
+
|
1440
|
+
</li>
|
1441
|
+
|
1442
|
+
</ul>
|
1443
|
+
|
1444
|
+
</div><table class="source_code">
|
1445
|
+
<tr>
|
1446
|
+
<td>
|
1447
|
+
<pre class="lines">
|
1448
|
+
|
1449
|
+
|
1450
|
+
187</pre>
|
1451
|
+
</td>
|
1452
|
+
<td>
|
1453
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 187</span>
|
1454
|
+
|
1455
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_default_adapter'>default_adapter</span><span class='semicolon'>;</span> <span class='symbol'>:sqlite3</span> <span class='kw'>end</span></pre>
|
1456
|
+
</td>
|
1457
|
+
</tr>
|
1458
|
+
</table>
|
1459
|
+
</div>
|
1460
|
+
|
1461
|
+
<div class="method_details ">
|
1462
|
+
<h3 class="signature " id="default_database-class_method">
|
1463
|
+
|
1464
|
+
+ (<tt>'APP_DB'\</tt>) <strong>default_database</strong>
|
1465
|
+
|
1466
|
+
|
1467
|
+
|
1468
|
+
|
1469
|
+
|
1470
|
+
</h3><div class="docstring">
|
1471
|
+
<div class="discussion">
|
1472
|
+
|
1473
|
+
<p>Retrieves de default database</p>
|
1474
|
+
|
1475
|
+
|
1476
|
+
</div>
|
1477
|
+
</div>
|
1478
|
+
<div class="tags">
|
1479
|
+
|
1480
|
+
<p class="tag_title">Returns:</p>
|
1481
|
+
<ul class="return">
|
1482
|
+
|
1483
|
+
<li>
|
1484
|
+
|
1485
|
+
|
1486
|
+
<span class='type'>(<tt>'APP_DB'\</tt>)</span>
|
1487
|
+
|
1488
|
+
|
1489
|
+
|
1490
|
+
—
|
1491
|
+
<div class='inline'>
|
1492
|
+
<p>Returns a the content of ENV'APP_DB'.</p>
|
1493
|
+
</div>
|
1494
|
+
|
1495
|
+
</li>
|
1496
|
+
|
1497
|
+
</ul>
|
1498
|
+
|
1499
|
+
</div><table class="source_code">
|
1500
|
+
<tr>
|
1501
|
+
<td>
|
1502
|
+
<pre class="lines">
|
1503
|
+
|
1504
|
+
|
1505
|
+
182</pre>
|
1506
|
+
</td>
|
1507
|
+
<td>
|
1508
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 182</span>
|
1509
|
+
|
1510
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_default_database'>default_database</span><span class='semicolon'>;</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>APP_DB</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='kw'>end</span></pre>
|
1511
|
+
</td>
|
1512
|
+
</tr>
|
1513
|
+
</table>
|
1514
|
+
</div>
|
1515
|
+
|
1516
|
+
<div class="method_details ">
|
1517
|
+
<h3 class="signature " id="meta_schema-class_method">
|
1518
|
+
|
1519
|
+
+ (<tt>Object</tt>) <strong>meta_schema</strong>
|
1520
|
+
|
1521
|
+
|
1522
|
+
|
1523
|
+
|
1524
|
+
|
1525
|
+
</h3><div class="docstring">
|
1526
|
+
<div class="discussion">
|
1527
|
+
|
1528
|
+
<p>Private: Get the Class holding the current migration metadatas.</p>
|
1529
|
+
|
1530
|
+
|
1531
|
+
</div>
|
1532
|
+
</div>
|
1533
|
+
<div class="tags">
|
1534
|
+
|
1535
|
+
<p class="tag_title">Returns:</p>
|
1536
|
+
<ul class="return">
|
1537
|
+
|
1538
|
+
<li>
|
1539
|
+
|
1540
|
+
|
1541
|
+
<span class='type'></span>
|
1542
|
+
|
1543
|
+
|
1544
|
+
|
1545
|
+
|
1546
|
+
<div class='inline'>
|
1547
|
+
<p>an ActiveRecord::Base subclass.</p>
|
1548
|
+
</div>
|
1549
|
+
|
1550
|
+
</li>
|
1551
|
+
|
1552
|
+
</ul>
|
1553
|
+
|
1554
|
+
</div><table class="source_code">
|
1555
|
+
<tr>
|
1556
|
+
<td>
|
1557
|
+
<pre class="lines">
|
1558
|
+
|
1559
|
+
|
1560
|
+
287
|
1561
|
+
288
|
1562
|
+
289
|
1563
|
+
290
|
1564
|
+
291
|
1565
|
+
292
|
1566
|
+
293
|
1567
|
+
294
|
1568
|
+
295</pre>
|
1569
|
+
</td>
|
1570
|
+
<td>
|
1571
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 287</span>
|
1572
|
+
|
1573
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_meta_schema'>meta_schema</span>
|
1574
|
+
<span class='id identifier rubyid_klass'>klass</span> <span class='op'>=</span> <span class='symbol'>:MetaSchema</span>
|
1575
|
+
<span class='ivar'>@meta_schema</span> <span class='op'>||=</span>
|
1576
|
+
<span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_const_defined?'>const_defined?</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1577
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_const_get'>const_get</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1578
|
+
<span class='kw'>else</span>
|
1579
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid___create_meta_schema_class'>__create_meta_schema_class</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='rparen'>)</span>
|
1580
|
+
<span class='kw'>end</span>
|
1581
|
+
<span class='kw'>end</span></pre>
|
1582
|
+
</td>
|
1583
|
+
</tr>
|
1584
|
+
</table>
|
1585
|
+
</div>
|
1586
|
+
|
1587
|
+
<div class="method_details ">
|
1588
|
+
<h3 class="signature " id="migrate-class_method">
|
1589
|
+
|
1590
|
+
+ (<tt>Object</tt>) <strong>migrate</strong>(version = nil)
|
1591
|
+
|
1592
|
+
|
1593
|
+
|
1594
|
+
|
1595
|
+
|
1596
|
+
</h3><div class="docstring">
|
1597
|
+
<div class="discussion">
|
1598
|
+
|
1599
|
+
<p>Executes a migration.</p>
|
1600
|
+
|
1601
|
+
|
1602
|
+
</div>
|
1603
|
+
</div>
|
1604
|
+
<div class="tags">
|
1605
|
+
|
1606
|
+
<div class="examples">
|
1607
|
+
<p class="tag_title">Examples:</p>
|
1608
|
+
|
1609
|
+
|
1610
|
+
<pre class="example code"><code><span class='comment'># (See the Binder::AR::Version examples for the classes definition.)
|
1611
|
+
</span><span class='const'>Plug</span><span class='period'>.</span><span class='id identifier rubyid_migrate'>migrate</span> <span class='float'>1.0</span> <span class='comment'># Creates table bars.
|
1612
|
+
</span><span class='comment'># => 1.0
|
1613
|
+
</span><span class='const'>Plug</span><span class='period'>.</span><span class='id identifier rubyid_migrate'>migrate</span> <span class='int'>0</span> <span class='comment'># Drop the table bars.
|
1614
|
+
</span><span class='comment'># => 0.0
|
1615
|
+
</span><span class='const'>Plug</span><span class='period'>.</span><span class='id identifier rubyid_migrate'>migrate</span> <span class='comment'># Creates tables bars and foos.
|
1616
|
+
</span><span class='comment'># => 1.1</span></code></pre>
|
1617
|
+
|
1618
|
+
</div>
|
1619
|
+
<p class="tag_title">Parameters:</p>
|
1620
|
+
<ul class="param">
|
1621
|
+
|
1622
|
+
<li>
|
1623
|
+
|
1624
|
+
<span class='name'>version</span>
|
1625
|
+
|
1626
|
+
|
1627
|
+
<span class='type'></span>
|
1628
|
+
|
1629
|
+
|
1630
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
1631
|
+
|
1632
|
+
|
1633
|
+
—
|
1634
|
+
<div class='inline'>
|
1635
|
+
<p>A Float or Numeric indicating the number towards which execute the
|
1636
|
+
migration. If none specified it will migrate to the latest migration.</p>
|
1637
|
+
</div>
|
1638
|
+
|
1639
|
+
</li>
|
1640
|
+
|
1641
|
+
</ul>
|
1642
|
+
|
1643
|
+
<p class="tag_title">Returns:</p>
|
1644
|
+
<ul class="return">
|
1645
|
+
|
1646
|
+
<li>
|
1647
|
+
|
1648
|
+
|
1649
|
+
<span class='type'></span>
|
1650
|
+
|
1651
|
+
|
1652
|
+
|
1653
|
+
|
1654
|
+
<div class='inline'>
|
1655
|
+
<p>the version we migrated to as a Float.</p>
|
1656
|
+
</div>
|
1657
|
+
|
1658
|
+
</li>
|
1659
|
+
|
1660
|
+
</ul>
|
1661
|
+
|
1662
|
+
</div><table class="source_code">
|
1663
|
+
<tr>
|
1664
|
+
<td>
|
1665
|
+
<pre class="lines">
|
1666
|
+
|
1667
|
+
|
1668
|
+
260
|
1669
|
+
261
|
1670
|
+
262
|
1671
|
+
263
|
1672
|
+
264
|
1673
|
+
265
|
1674
|
+
266
|
1675
|
+
267
|
1676
|
+
268
|
1677
|
+
269
|
1678
|
+
270
|
1679
|
+
271
|
1680
|
+
272
|
1681
|
+
273
|
1682
|
+
274
|
1683
|
+
275
|
1684
|
+
276
|
1685
|
+
277
|
1686
|
+
278
|
1687
|
+
279
|
1688
|
+
280
|
1689
|
+
281
|
1690
|
+
282</pre>
|
1691
|
+
</td>
|
1692
|
+
<td>
|
1693
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 260</span>
|
1694
|
+
|
1695
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_migrate'>migrate</span> <span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1696
|
+
<span class='kw'>if</span> <span class='ivar'>@migrations</span>
|
1697
|
+
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='id identifier rubyid_meta_schema'>meta_schema</span>
|
1698
|
+
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid___check_migration_version'>__check_migration_version</span><span class='lparen'>(</span><span class='id identifier rubyid_version'>version</span><span class='rparen'>)</span>
|
1699
|
+
<span class='id identifier rubyid___create_meta_data_table_for'>__create_meta_data_table_for</span><span class='lparen'>(</span><span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
1700
|
+
|
1701
|
+
<span class='id identifier rubyid_s'>s</span> <span class='op'>=</span> <span class='id identifier rubyid_schema'>schema</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span> <span class='op'>||</span> <span class='id identifier rubyid_schema'>schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>version:</span> <span class='int'>0</span><span class='rparen'>)</span>
|
1702
|
+
<span class='kw'>unless</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='op'>==</span> <span class='id identifier rubyid_version'>version</span>
|
1703
|
+
<span class='ivar'>@migrations</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_migration'>migration</span><span class='op'>|</span> <span class='id identifier rubyid_migration'>migration</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span>
|
1704
|
+
<span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_migrate'>migrate</span><span class='lparen'>(</span><span class='symbol'>:up</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='op'><</span> <span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='kw'>and</span> <span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='op'><=</span> <span class='id identifier rubyid_version'>version</span>
|
1705
|
+
|
1706
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='op'>>=</span> <span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='kw'>and</span> <span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='op'>></span> <span class='id identifier rubyid_version'>version</span>
|
1707
|
+
<span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_migrate'>migrate</span><span class='lparen'>(</span><span class='symbol'>:down</span><span class='rparen'>)</span>
|
1708
|
+
<span class='kw'>else</span> <span class='comment'># Handle migrate(0)
|
1709
|
+
</span> <span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_migrate'>migrate</span><span class='lparen'>(</span><span class='symbol'>:down</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='op'>>=</span> <span class='id identifier rubyid_m'>m</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='kw'>and</span> <span class='id identifier rubyid_version'>version</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>
|
1710
|
+
<span class='kw'>end</span>
|
1711
|
+
<span class='kw'>end</span>
|
1712
|
+
<span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_update_attribute'>update_attribute</span> <span class='symbol'>:version</span><span class='comma'>,</span> <span class='id identifier rubyid_version'>version</span>
|
1713
|
+
<span class='kw'>end</span>
|
1714
|
+
<span class='id identifier rubyid_version'>version</span> <span class='op'>=</span> <span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span>
|
1715
|
+
<span class='kw'>end</span>
|
1716
|
+
<span class='id identifier rubyid_version'>version</span>
|
1717
|
+
<span class='kw'>end</span></pre>
|
1718
|
+
</td>
|
1719
|
+
</tr>
|
1720
|
+
</table>
|
1721
|
+
</div>
|
1722
|
+
|
1723
|
+
<div class="method_details ">
|
1724
|
+
<h3 class="signature " id="Version-class_method">
|
1725
|
+
|
1726
|
+
+ (<tt>Object</tt>) <strong>Version</strong>(n)
|
1727
|
+
|
1728
|
+
|
1729
|
+
|
1730
|
+
|
1731
|
+
|
1732
|
+
</h3><div class="docstring">
|
1733
|
+
<div class="discussion">
|
1734
|
+
|
1735
|
+
<p>Creates a new migration version through subclassing.</p>
|
1736
|
+
|
1737
|
+
|
1738
|
+
</div>
|
1739
|
+
</div>
|
1740
|
+
<div class="tags">
|
1741
|
+
|
1742
|
+
<div class="examples">
|
1743
|
+
<p class="tag_title">Examples:</p>
|
1744
|
+
|
1745
|
+
|
1746
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Plug</span> <span class='op'><</span> <span class='const'>Binder</span><span class='op'>::</span><span class='const'>AR</span><span class='semicolon'>;</span> <span class='kw'>end</span></code></pre>
|
1747
|
+
|
1748
|
+
|
1749
|
+
<pre class="example code"><code>class CreateFooTable < Plug::Version 1.0
|
1750
|
+
def self.up
|
1751
|
+
create_table :foos do |t|
|
1752
|
+
t.string :name
|
1753
|
+
t.timestamps
|
1754
|
+
end
|
1755
|
+
end</code></pre>
|
1756
|
+
|
1757
|
+
|
1758
|
+
<pre class="example code"><code>def self.down
|
1759
|
+
drop_table :foos
|
1760
|
+
end
|
1761
|
+
end</code></pre>
|
1762
|
+
|
1763
|
+
|
1764
|
+
<pre class="example code"><code>class CreateBarTable < Plug::Version 1.1
|
1765
|
+
def self.up
|
1766
|
+
create_table :bars do |t|
|
1767
|
+
t.string :title
|
1768
|
+
t.timestamps
|
1769
|
+
end
|
1770
|
+
end</code></pre>
|
1771
|
+
|
1772
|
+
|
1773
|
+
<pre class="example code"><code>def self.down
|
1774
|
+
drop_table :bars
|
1775
|
+
end
|
1776
|
+
end</code></pre>
|
1777
|
+
|
1778
|
+
|
1779
|
+
<pre class="example code"><code><span class='comment'># You can get the migration version for a pecular migration class.
|
1780
|
+
</span><span class='const'>CreateFooTable</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='comment'># => 1.0
|
1781
|
+
</span><span class='const'>CreateBarTable</span><span class='period'>.</span><span class='id identifier rubyid_version'>version</span> <span class='comment'># => 1.1</span></code></pre>
|
1782
|
+
|
1783
|
+
</div>
|
1784
|
+
<p class="tag_title">Parameters:</p>
|
1785
|
+
<ul class="param">
|
1786
|
+
|
1787
|
+
<li>
|
1788
|
+
|
1789
|
+
<span class='name'>n</span>
|
1790
|
+
|
1791
|
+
|
1792
|
+
<span class='type'></span>
|
1793
|
+
|
1794
|
+
|
1795
|
+
|
1796
|
+
—
|
1797
|
+
<div class='inline'>
|
1798
|
+
<p>A migration version number as Float.</p>
|
1799
|
+
</div>
|
1800
|
+
|
1801
|
+
</li>
|
1802
|
+
|
1803
|
+
</ul>
|
1804
|
+
|
1805
|
+
<p class="tag_title">Returns:</p>
|
1806
|
+
<ul class="return">
|
1807
|
+
|
1808
|
+
<li>
|
1809
|
+
|
1810
|
+
|
1811
|
+
<span class='type'></span>
|
1812
|
+
|
1813
|
+
|
1814
|
+
|
1815
|
+
|
1816
|
+
<div class='inline'>
|
1817
|
+
<p>a new Class, subclassing ActiveRecord::Migration.</p>
|
1818
|
+
</div>
|
1819
|
+
|
1820
|
+
</li>
|
1821
|
+
|
1822
|
+
</ul>
|
1823
|
+
|
1824
|
+
</div><table class="source_code">
|
1825
|
+
<tr>
|
1826
|
+
<td>
|
1827
|
+
<pre class="lines">
|
1828
|
+
|
1829
|
+
|
1830
|
+
228
|
1831
|
+
229
|
1832
|
+
230
|
1833
|
+
231
|
1834
|
+
232
|
1835
|
+
233
|
1836
|
+
234
|
1837
|
+
235
|
1838
|
+
236
|
1839
|
+
237
|
1840
|
+
238
|
1841
|
+
239
|
1842
|
+
240
|
1843
|
+
241
|
1844
|
+
242</pre>
|
1845
|
+
</td>
|
1846
|
+
<td>
|
1847
|
+
<pre class="code"><span class="info file"># File 'lib/active_record_binder.rb', line 228</span>
|
1848
|
+
|
1849
|
+
<span class='kw'>def</span> <span class='const'>Version</span> <span class='id identifier rubyid_n'>n</span>
|
1850
|
+
<span class='ivar'>@last_version</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='ivar'>@last_version</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span> <span class='comment'># Assign or retrieves the last migration version number
|
1851
|
+
</span> <span class='comment'># migrations is a pointer to the instance variable
|
1852
|
+
</span> <span class='id identifier rubyid_migrations'>migrations</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='ivar'>@migrations</span> <span class='op'>||=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1853
|
+
<span class='const'>Class</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Migration</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
1854
|
+
<span class='id identifier rubyid_singleton_class'>singleton_class</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:define_method</span><span class='comma'>,</span> <span class='symbol'>:version</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='comment'># def self.version
|
1855
|
+
</span> <span class='id identifier rubyid_n'>n</span> <span class='comment'># n
|
1856
|
+
</span> <span class='kw'>end</span> <span class='comment'># end
|
1857
|
+
</span>
|
1858
|
+
<span class='comment'># Callback invoked whenever a subclass of the current class is created
|
1859
|
+
</span> <span class='id identifier rubyid_singleton_class'>singleton_class</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:define_method</span><span class='comma'>,</span> <span class='symbol'>:inherited</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_s'>s</span><span class='op'>|</span> <span class='comment'># def self.inherited subclass
|
1860
|
+
</span> <span class='id identifier rubyid_migrations'>migrations</span> <span class='op'><<</span> <span class='id identifier rubyid_s'>s</span> <span class='comment'># migrations << subclass
|
1861
|
+
</span> <span class='kw'>end</span> <span class='comment'># end
|
1862
|
+
</span> <span class='kw'>end</span>
|
1863
|
+
<span class='kw'>end</span></pre>
|
1864
|
+
</td>
|
1865
|
+
</tr>
|
1866
|
+
</table>
|
1867
|
+
</div>
|
1868
|
+
|
1869
|
+
</div>
|
1870
|
+
|
1871
|
+
</div>
|
1872
|
+
|
1873
|
+
<div id="footer">
|
1874
|
+
Generated on Thu Feb 21 02:06:17 2013 by
|
1875
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1876
|
+
0.8.4.1 (ruby-1.9.3).
|
1877
|
+
</div>
|
1878
|
+
|
1879
|
+
</body>
|
1880
|
+
</html>
|