dm-is-reflective 1.0.1.rc → 1.0.1
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/CHANGES.md +226 -0
- data/README.md +132 -0
- data/Rakefile +0 -1
- data/{TODO → TODO.md} +1 -1
- data/dm-is-reflective.gemspec +33 -44
- data/lib/dm-is-reflective/version.rb +1 -1
- data/task/.gitignore +1 -0
- data/task/gemgem.rb +119 -17
- metadata +59 -37
- data/CHANGES +0 -201
- data/CONTRIBUTORS +0 -1
- data/NOTICE +0 -20
- data/README +0 -123
- data/README.rdoc +0 -123
- data/lib/dm-is-reflective/is/version.rb +0 -8
data/CHANGES.md
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
# CHANGES
|
2
|
+
|
3
|
+
## dm-is-reflective 1.0.1, 2012-05-16
|
4
|
+
|
5
|
+
* allow_nil is more close to db's semantics, not required. Thanks miaout17.
|
6
|
+
`:allow_nil` allows empty value, but `:required` does not. So here we
|
7
|
+
always use `:allow_nil` to match db's semantics.
|
8
|
+
|
9
|
+
## dm-is-reflective 1.0.0, 2011-06-16
|
10
|
+
|
11
|
+
* updated against dm-core 1.1.0
|
12
|
+
|
13
|
+
## dm-is-reflective 0.9.0, 2010-07-05
|
14
|
+
|
15
|
+
* adapted to dm-core 1.0.0
|
16
|
+
* reanmed AbstractAdapter to DataObjectsAdapter
|
17
|
+
|
18
|
+
## dm-is-reflective 0.8.0, 2009-09-16
|
19
|
+
|
20
|
+
* require dm-core 0.10.0 and above now
|
21
|
+
* Serial would map to Serial not Integer now
|
22
|
+
* no more type_map now
|
23
|
+
* no more Extlib::Hook to load adapter
|
24
|
+
|
25
|
+
## dm-mapping 0.7.1, never released as a gem
|
26
|
+
|
27
|
+
don't open module Migration and edit it, instead, use include, more see:
|
28
|
+
|
29
|
+
* added DataMapper::Mapping::AbstractAdapter
|
30
|
+
* added DataMapper::Mapping::Sqlite3Adapter
|
31
|
+
* added DataMapper::Mapping::MysqlAdapter
|
32
|
+
* added DataMapper::Mapping::PostgresAdapter
|
33
|
+
* each adapter was included in related adapter in DataMapper.
|
34
|
+
* Model#fields now accept repository name as argument
|
35
|
+
|
36
|
+
there's differences between adapters,
|
37
|
+
Sqlite3 added default => 'UL' in Boolean type,
|
38
|
+
Mysql can't tell whether it's a Boolean or Tinyint,
|
39
|
+
and Postgres is fine. see test/abstract.rb: super_user_fields for detail.
|
40
|
+
|
41
|
+
## dm-mapping 0.7.0, 2008-09-01
|
42
|
+
|
43
|
+
* feature added
|
44
|
+
|
45
|
+
- added postgres support.
|
46
|
+
|
47
|
+
* bug fixed
|
48
|
+
|
49
|
+
- fixed key mapping in mysql adapter. PRI and MUL are all keys.
|
50
|
+
- use DM::Text.size as default text size in sqlite3.
|
51
|
+
|
52
|
+
## dm-mapping 0.6.2, 2008-08-30
|
53
|
+
|
54
|
+
* mapping more data types for mysql.
|
55
|
+
* don't map TINYINT to TrueClass with mysql, skip it in type_map.
|
56
|
+
|
57
|
+
## dm-mapping 0.6.1, 2008-08-22
|
58
|
+
|
59
|
+
* gem 'dm-core', '>=0.9.3' instead of '=0.9.3'
|
60
|
+
|
61
|
+
## dm-mapping 0.6.0, 2008-08-16
|
62
|
+
|
63
|
+
* mapping returns an array of properties indicating fields it mapped.
|
64
|
+
* performance boosted by refactored mapping implementation.
|
65
|
+
* changed the way using auto_genclass!, now accepts args like mapping!
|
66
|
+
* changed fields to return field name with Symbol instead of String.
|
67
|
+
this would make it be more consistent with DataMapper.
|
68
|
+
* storage names remain String.
|
69
|
+
* added more mysql data type to map
|
70
|
+
* use Extlib::Hook to setup dm-mapping instead of stupid alias_method.
|
71
|
+
* removed ensure_require in model. always setup DataMapper before define model.
|
72
|
+
|
73
|
+
## dm-mapping 0.5.0, 2008-08-14
|
74
|
+
|
75
|
+
* feature added
|
76
|
+
|
77
|
+
- added mysql support.
|
78
|
+
- reflect size 65535 in TEXT for sqlite3.
|
79
|
+
|
80
|
+
* bug fixed
|
81
|
+
|
82
|
+
- reflect VARCHAR(size) instead of default size in sqlite3.
|
83
|
+
|
84
|
+
* misc
|
85
|
+
|
86
|
+
- renamed sqlite3adapter to sqlite3_adapter.
|
87
|
+
|
88
|
+
## dm-mapping 0.4.1, 2008-08-14
|
89
|
+
|
90
|
+
* removed type hack, replaced with rejecting special type to lookup.
|
91
|
+
|
92
|
+
## dm-mapping 0.4.0, 2008-08-04
|
93
|
+
|
94
|
+
* added Migration#auto_genclass!.
|
95
|
+
* updated README.
|
96
|
+
* added more rdoc.
|
97
|
+
|
98
|
+
## dm-mapping 0.3.0, 2008-08-04
|
99
|
+
|
100
|
+
* added support of mapping Integer, DateTime, etc.
|
101
|
+
* renamed some internals.
|
102
|
+
* changed the way requiring adapter. no more setup first.
|
103
|
+
* added Migration#storages_and_fields
|
104
|
+
* added mapping :serial => true for primary key.
|
105
|
+
* added mapping :default, and :nullable.
|
106
|
+
* added support of mapping name. (through passing symbol or string)
|
107
|
+
* added support of multiple arguments.
|
108
|
+
* removed Mapping::All, use /.*/ instead.
|
109
|
+
|
110
|
+
## dm-mapping 0.2.1, 2008-08-03
|
111
|
+
|
112
|
+
* fixed a bug that type map should lookup for parent.
|
113
|
+
* fixed a bug that sql type could be lower case.
|
114
|
+
fixed by calling upcase.
|
115
|
+
|
116
|
+
## dm-mapping 0.2.0, 2008-08-02
|
117
|
+
|
118
|
+
* added Sqlite3Adapter::Migration#fields
|
119
|
+
* added DataMapper::Model#mapping
|
120
|
+
* added DataMapper::Model#fields
|
121
|
+
* added DataMapper::TypeMap#find_primitive for reversed lookup.
|
122
|
+
mapping SQL type back to Ruby type.
|
123
|
+
* added corresponded test.
|
124
|
+
|
125
|
+
## dm-mapping 0.1.0, 2008-07-27
|
126
|
+
|
127
|
+
* birthday!
|
128
|
+
* added DataMapper.repository.storages for sqlite3.
|
129
|
+
* please refer:
|
130
|
+
<http://groups.google.com/group/datamapper/browse_thread/thread/b9ca41120c5c9389>
|
131
|
+
|
132
|
+
original message:
|
133
|
+
|
134
|
+
from Lin Jen-Shin
|
135
|
+
to DataMapper
|
136
|
+
cc godfat
|
137
|
+
date Sun, Jul 27, 2008 at 5:40 PM
|
138
|
+
subject Manipulate an existing database.
|
139
|
+
mailed-by gmail.com
|
140
|
+
|
141
|
+
Greetings,
|
142
|
+
|
143
|
+
DataMapper looks very promising for me, so I am thinking of
|
144
|
+
using it in the near future. I hate separate my domain objects into
|
145
|
+
two parts in Rails, writing migration and switching to ActiveRecord,
|
146
|
+
vice versa, is very annoying to me.
|
147
|
+
|
148
|
+
But there's a very convenient feature to me in ActiveRecord,
|
149
|
+
that is ActiveRecord automatically mapping all fields in a table.
|
150
|
+
It makes me easily control an existing database without any domain object.
|
151
|
+
|
152
|
+
For example,
|
153
|
+
|
154
|
+
require 'active_record'
|
155
|
+
|
156
|
+
ActiveRecord::Base.establish_connection(
|
157
|
+
:adapter => 'sqlite3',
|
158
|
+
:database => 'db/development.sqlite3'
|
159
|
+
)
|
160
|
+
|
161
|
+
clsas User < ActiveRecord::Base
|
162
|
+
end
|
163
|
+
|
164
|
+
User.find 1
|
165
|
+
=> #<User id: 1, account: "admin", created_at: "2008-05-18 20:08:37", etc.>
|
166
|
+
|
167
|
+
Some people would use database admin such as phpMyAdmin to
|
168
|
+
accomplish this kind of task, but I prefer anything in Ruby,
|
169
|
+
calling Ruby function, manipulating data without SQL and
|
170
|
+
any domain object. (i.e. I didn't have to load up entire environment.)
|
171
|
+
|
172
|
+
In DataMapper, I didn't find an easy way to accomplish this.
|
173
|
+
I am sorry if there's one but I didn't find it, please point out,
|
174
|
+
many thanks. In short, I would like to do this in DataMapper:
|
175
|
+
|
176
|
+
class User
|
177
|
+
include DataMapper::Resource
|
178
|
+
mapping :account, :created_at
|
179
|
+
end
|
180
|
+
|
181
|
+
or
|
182
|
+
|
183
|
+
class User
|
184
|
+
include DataMapper::Resource
|
185
|
+
mapping All
|
186
|
+
end
|
187
|
+
|
188
|
+
class User
|
189
|
+
include DataMapper::ResourceAll
|
190
|
+
end
|
191
|
+
|
192
|
+
or
|
193
|
+
|
194
|
+
class User
|
195
|
+
include DataMapper::Resource
|
196
|
+
mapping *storage_fields
|
197
|
+
end
|
198
|
+
|
199
|
+
The above User.storage_fields should return an Array,
|
200
|
+
telling all the fields in the table, e.g. [:account, :created_at, :etc]
|
201
|
+
or a Hash includes data type, e.g. {:account => String,
|
202
|
+
:created_at => DateTime}
|
203
|
+
then mapping *storage_fields should change to:
|
204
|
+
|
205
|
+
mapping *storage_fields.each_key.to_a
|
206
|
+
|
207
|
+
If it's possible, a feature returning the database schema as well:
|
208
|
+
|
209
|
+
DataMapper.repository.storages
|
210
|
+
# => [:users, :posts, :etc]
|
211
|
+
|
212
|
+
DataMapper.repository.storages_and_fields
|
213
|
+
# => {:users => {:account => String},
|
214
|
+
:posts => {:title => String, :content => Text}}
|
215
|
+
|
216
|
+
or returning DataObject::Field, DataObject::Storage, etc.
|
217
|
+
|
218
|
+
DataMapper.repository.storage
|
219
|
+
# => [#<DataObject::Storage @name='users' @fields=
|
220
|
+
[#<DataObject::Field @name='account' @type=String>]>]
|
221
|
+
|
222
|
+
If you feel this kind of feature is indeed needed or not bad for
|
223
|
+
adding it, I could try to provide a patch for it. Though I didn't
|
224
|
+
read the source code deeply, not knowning it's easy or not.
|
225
|
+
|
226
|
+
sincerely,
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# dm-is-reflective
|
2
|
+
|
3
|
+
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
|
+
|
5
|
+
## LINKS:
|
6
|
+
|
7
|
+
* [github](https://github.com/godfat/dm-is-reflective)
|
8
|
+
* [rubygems](https://rubygems.org/gems/dm-is-reflective)
|
9
|
+
* [rdoc](http://rdoc.info/github/godfat/dm-is-reflective)
|
10
|
+
|
11
|
+
## DESCRIPTION:
|
12
|
+
|
13
|
+
DataMapper plugin that helps you manipulate an existing database.
|
14
|
+
It creates mappings between existing columns and model's properties.
|
15
|
+
|
16
|
+
## SYNOPSIS:
|
17
|
+
|
18
|
+
``` ruby
|
19
|
+
require 'dm-is-reflective' # this would require 'dm-core'
|
20
|
+
dm = DataMapper.setup :default, 'sqlite:db/dev.sqlite3'
|
21
|
+
|
22
|
+
class User
|
23
|
+
include DataMapper::Resource
|
24
|
+
is :reflective
|
25
|
+
|
26
|
+
# map all, returning an array of properties indicating fields it mapped
|
27
|
+
reflect /.*/ # e.g. => [#<Property:#<Class:0x18f89b8>:id>,
|
28
|
+
# #<Property:#<Class:0x18f89b8>:title>,
|
29
|
+
# #<Property:#<Class:0x18f89b8>:body>,
|
30
|
+
# #<Property:#<Class:0x18f89b8>:user_id>]
|
31
|
+
|
32
|
+
# map all (with no argument at all)
|
33
|
+
reflect
|
34
|
+
|
35
|
+
# mapping for field name ended with _at, and started with salt_
|
36
|
+
reflect /_at$/, /^salt_/
|
37
|
+
|
38
|
+
# mapping id and email
|
39
|
+
reflect :id, :email
|
40
|
+
|
41
|
+
# mapping all fields with type String, and id
|
42
|
+
reflect String, :id
|
43
|
+
|
44
|
+
# mapping login, and all fields with type Integer
|
45
|
+
reflect :login, Integer
|
46
|
+
end
|
47
|
+
|
48
|
+
# there's no guarantee of the order in storages array
|
49
|
+
dm.storages
|
50
|
+
# => ['users']
|
51
|
+
|
52
|
+
# there's no guarantee of the order in fields array
|
53
|
+
User.fields
|
54
|
+
# => [[:created_at, DateTime, {:required => false}],
|
55
|
+
[:email, String, {:required => false, :length => 255,
|
56
|
+
:default => 'nospam@nospam.tw'}],
|
57
|
+
[:id, Serial, {:required => true, :serial => true,
|
58
|
+
:key => true}],
|
59
|
+
[:salt_first, String, {:required => false, :length => 50}],
|
60
|
+
[:salt_second, String, {:required => false, :length => 50}]]
|
61
|
+
|
62
|
+
dm.fields('users').sort_by{ |field| field.first.to_s } ==
|
63
|
+
User.fields.sort_by{ |field| field.first.to_s }
|
64
|
+
# => true
|
65
|
+
|
66
|
+
dm.storages_and_fields
|
67
|
+
# => {'users' => [[:id, Serial, {:required => true,
|
68
|
+
:serial => true,
|
69
|
+
:key => true}],
|
70
|
+
[:email, String, {:required => false,
|
71
|
+
:default =>
|
72
|
+
'nospam@nospam.tw'}],
|
73
|
+
[:created_at, DateTime, {:required => false}],
|
74
|
+
[:salt_first, String, {:required => false,
|
75
|
+
:length => 50}],
|
76
|
+
[:salt_second, String, {:required => false,
|
77
|
+
:length => 50}]]}
|
78
|
+
|
79
|
+
# there's no guarantee of the order in returned array
|
80
|
+
dm.auto_genclass!
|
81
|
+
# => [DataMapper::Is::Reflective::User,
|
82
|
+
DataMapper::Is::Reflective::SchemaInfo,
|
83
|
+
DataMapper::Is::Reflective::Session]
|
84
|
+
|
85
|
+
# you can change the scope of generated models:
|
86
|
+
dm.auto_genclass! :scope => Object
|
87
|
+
# => [User, SchemaInfo, Session]
|
88
|
+
|
89
|
+
# you can generate classes for tables you specified only:
|
90
|
+
dm.auto_genclass! :scope => Object, :storages => /^phpbb_/
|
91
|
+
# => [PhpbbUser, PhpbbPost, PhpbbConfig]
|
92
|
+
|
93
|
+
# you can generate classes with String too:
|
94
|
+
dm.auto_genclass! :storages => ['users', 'config'], :scope => Object
|
95
|
+
# => [User, Config]
|
96
|
+
|
97
|
+
# you can generate a class only:
|
98
|
+
dm.auto_genclass! :storages => 'users'
|
99
|
+
# => [DataMapper::Is::Reflective::User]
|
100
|
+
```
|
101
|
+
|
102
|
+
## REQUIREMENTS:
|
103
|
+
|
104
|
+
* dm-core
|
105
|
+
* dm-do-adapter
|
106
|
+
* choose one: dm-sqlite-adapter, dm-postgres-adapter, dm-mysql-adapter
|
107
|
+
|
108
|
+
## INSTALL:
|
109
|
+
|
110
|
+
gem install dm-is-reflective
|
111
|
+
|
112
|
+
## CONTRIBUTORS:
|
113
|
+
|
114
|
+
* Lin Jen-Shin (@godfat)
|
115
|
+
|
116
|
+
## LICENSE:
|
117
|
+
|
118
|
+
Apache License 2.0
|
119
|
+
|
120
|
+
Copyright (c) 2008-2012, Lin Jen-Shin (godfat)
|
121
|
+
|
122
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
123
|
+
you may not use this file except in compliance with the License.
|
124
|
+
You may obtain a copy of the License at
|
125
|
+
|
126
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
127
|
+
|
128
|
+
Unless required by applicable law or agreed to in writing, software
|
129
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
130
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
131
|
+
See the License for the specific language governing permissions and
|
132
|
+
limitations under the License.
|
data/Rakefile
CHANGED
data/{TODO → TODO.md}
RENAMED
data/dm-is-reflective.gemspec
CHANGED
@@ -1,52 +1,41 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.0.1
|
4
|
+
s.name = "dm-is-reflective"
|
5
|
+
s.version = "1.0.1"
|
6
6
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email = [
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
%q{CHANGES},
|
14
|
-
%q{CONTRIBUTORS},
|
15
|
-
%q{LICENSE},
|
16
|
-
%q{TODO}]
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Lin Jen-Shin (godfat)"]
|
9
|
+
s.date = "2012-05-16"
|
10
|
+
s.description = "DataMapper plugin that helps you manipulate an existing database.\nIt creates mappings between existing columns and model's properties."
|
11
|
+
s.email = ["godfat (XD) godfat.org"]
|
17
12
|
s.files = [
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
s.
|
43
|
-
s.
|
44
|
-
%q{--main},
|
45
|
-
%q{README}]
|
46
|
-
s.require_paths = [%q{lib}]
|
47
|
-
s.rubygems_version = %q{1.8.5}
|
48
|
-
s.summary = %q{DataMapper plugin that helps you manipulate an existing database. It creates mappings between existing columns and model's properties.}
|
49
|
-
s.test_files = [%q{test/test_dm-is-reflective.rb}]
|
13
|
+
".gitignore",
|
14
|
+
".gitmodules",
|
15
|
+
"CHANGES.md",
|
16
|
+
"Gemfile",
|
17
|
+
"LICENSE",
|
18
|
+
"README.md",
|
19
|
+
"Rakefile",
|
20
|
+
"TODO.md",
|
21
|
+
"dm-is-reflective.gemspec",
|
22
|
+
"lib/dm-is-reflective.rb",
|
23
|
+
"lib/dm-is-reflective/is/adapters/data_objects_adapter.rb",
|
24
|
+
"lib/dm-is-reflective/is/adapters/mysql_adapter.rb",
|
25
|
+
"lib/dm-is-reflective/is/adapters/postgres_adapter.rb",
|
26
|
+
"lib/dm-is-reflective/is/adapters/sqlite_adapter.rb",
|
27
|
+
"lib/dm-is-reflective/is/reflective.rb",
|
28
|
+
"lib/dm-is-reflective/version.rb",
|
29
|
+
"task/.gitignore",
|
30
|
+
"task/gemgem.rb",
|
31
|
+
"test/abstract.rb",
|
32
|
+
"test/setup_db.sh",
|
33
|
+
"test/test_dm-is-reflective.rb"]
|
34
|
+
s.homepage = "https://github.com/godfat/dm-is-reflective"
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.24"
|
37
|
+
s.summary = "DataMapper plugin that helps you manipulate an existing database."
|
38
|
+
s.test_files = ["test/test_dm-is-reflective.rb"]
|
50
39
|
|
51
40
|
if s.respond_to? :specification_version then
|
52
41
|
s.specification_version = 3
|