modalfields 1.1.11 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +0 -12
- data/VERSION +1 -1
- data/lib/modalfields/modalfields.rb +41 -12
- data/modalfields.gemspec +8 -9
- metadata +131 -127
data/TODO
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
type synonyms (timestamp, datetime)
|
2
|
-
|
3
1
|
process specifiers (to add validations for required, etc.)(detect index modifications) decide what to do with multiple-column indices
|
4
2
|
|
5
|
-
refactor into multiple files
|
6
|
-
|
7
3
|
add extensible specifiers:
|
8
4
|
ModalFields.specify do
|
9
5
|
required do |model, column|
|
@@ -23,11 +19,3 @@ of extra attributes)
|
|
23
19
|
status enum_field(:draft, :approved, :published), :required
|
24
20
|
instead of
|
25
21
|
status :enum_field, :required, :values=>[:draft, :approved, :published]
|
26
|
-
|
27
|
-
Vendorized Installation:
|
28
|
-
Rails 2
|
29
|
-
script/plugin install git://github.com/jgoizueta/modalfields.git
|
30
|
-
Rails 3
|
31
|
-
rails plugin install git://github.com/jgoizueta/modalfields.git
|
32
|
-
|
33
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -90,7 +90,7 @@ module ModalFields
|
|
90
90
|
|
91
91
|
class DeclarationsDsl < DslBase
|
92
92
|
def initialize(model)
|
93
|
-
@model = model
|
93
|
+
@model = model
|
94
94
|
end
|
95
95
|
def field(name, type, *args)
|
96
96
|
declaration = FieldDeclaration.declare(name, type, *args)
|
@@ -113,16 +113,26 @@ module ModalFields
|
|
113
113
|
end
|
114
114
|
|
115
115
|
module FieldDeclarationClassMethods
|
116
|
-
def fields(&blk)
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
116
|
+
def fields(param=nil, &blk)
|
117
|
+
if param == :omitted
|
118
|
+
unless self.respond_to?(:fields_info)
|
119
|
+
self.instance_eval do
|
120
|
+
def fields_info
|
121
|
+
:omitted
|
122
|
+
end
|
122
123
|
end
|
123
124
|
end
|
125
|
+
else
|
126
|
+
@fields_info ||= []
|
127
|
+
unless self.respond_to?(:fields_info)
|
128
|
+
self.instance_eval do
|
129
|
+
def fields_info
|
130
|
+
@fields_info
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
DeclarationsDsl.new(self).instance_eval(&blk)
|
124
135
|
end
|
125
|
-
DeclarationsDsl.new(self).instance_eval(&blk)
|
126
136
|
end
|
127
137
|
end
|
128
138
|
|
@@ -336,8 +346,11 @@ module ModalFields
|
|
336
346
|
# model.columns will fail if the table does not exist
|
337
347
|
existing_fields = model.columns rescue []
|
338
348
|
deleted_model = existing_fields.empty?
|
339
|
-
|
340
|
-
|
349
|
+
submodels = model.send(:subclasses)
|
350
|
+
assocs = model.reflect_on_all_associations(:belongs_to) +
|
351
|
+
submodels.map{|sc| sc.reflect_on_all_associations(:belongs_to)}.flatten
|
352
|
+
association_fields = assocs.map{ |r|
|
353
|
+
# up to ActiveRecord 3.1 we had primary_key_name in AssociationReflection; now it's foreign_key
|
341
354
|
cols = [r.respond_to?(:primary_key_name) ? r.primary_key_name : r.foreign_key]
|
342
355
|
if r.options[:polymorphic]
|
343
356
|
t = r.options[:foreign_type]
|
@@ -357,7 +370,9 @@ module ModalFields
|
|
357
370
|
pk_fields = pk_fields.select{|pk| pk=='id'}
|
358
371
|
end
|
359
372
|
if model.respond_to?(:fields_info)
|
360
|
-
|
373
|
+
return [[]]*4 if model.fields_info==:omitted
|
374
|
+
declared_fields = model_fields_info(model)
|
375
|
+
declared_fields += submodels.map{|sc| Array(model_fields_info(sc))}.flatten
|
361
376
|
indices = model.connection.indexes(model.table_name) # name, columns, unique, spatial
|
362
377
|
|
363
378
|
existing_declared_fields = []
|
@@ -382,7 +397,7 @@ module ModalFields
|
|
382
397
|
column = existing_declared_fields.detect{|f| f.name.to_s == field_declaration.name.to_s}
|
383
398
|
identical = false
|
384
399
|
column = map_column_to_field_declaration(column)
|
385
|
-
if field_declaration.type
|
400
|
+
if unified_type(field_declaration.type) == unified_type(column.type.to_sym)
|
386
401
|
attrs = definitions[column.type.to_sym]
|
387
402
|
attr_keys = attrs.keys
|
388
403
|
decl_attrs = attr_keys.map{|a|
|
@@ -508,6 +523,20 @@ module ModalFields
|
|
508
523
|
}
|
509
524
|
end
|
510
525
|
|
526
|
+
TYPE_SYNONYMS = {
|
527
|
+
:timestamp => :datetime
|
528
|
+
}
|
529
|
+
|
530
|
+
def unified_type(type)
|
531
|
+
type &&= type.to_sym
|
532
|
+
TYPE_SYNONYMS[type] || type
|
533
|
+
end
|
534
|
+
|
535
|
+
def model_fields_info(model)
|
536
|
+
fields_info = model && model.respond_to?(:fields_info) && model.fields_info
|
537
|
+
fields_info.kind_of?(Array) ? fields_info : nil
|
538
|
+
end
|
539
|
+
|
511
540
|
end
|
512
541
|
|
513
542
|
|
data/modalfields.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.
|
7
|
+
s.name = "modalfields"
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Javier Goizueta"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-09-04"
|
13
|
+
s.description = "ModelFields is a Rails plugin that adds fields declarations to your models."
|
14
|
+
s.email = "jgoizueta@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.rdoc",
|
@@ -54,14 +54,13 @@ Gem::Specification.new do |s|
|
|
54
54
|
"test/test_diff.rb",
|
55
55
|
"test/test_update.rb"
|
56
56
|
]
|
57
|
-
s.homepage =
|
57
|
+
s.homepage = "http://github.com/jgoizueta/modalfields"
|
58
58
|
s.licenses = ["MIT"]
|
59
59
|
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version =
|
61
|
-
s.summary =
|
60
|
+
s.rubygems_version = "1.8.23"
|
61
|
+
s.summary = "Model annotator with Ruby (Hobo-like) syntax and hooks."
|
62
62
|
|
63
63
|
if s.respond_to? :specification_version then
|
64
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
65
64
|
s.specification_version = 3
|
66
65
|
|
67
66
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
@@ -1,159 +1,169 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: modalfields
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 1
|
8
|
-
- 11
|
9
|
-
version: 1.1.11
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Javier Goizueta
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: activesupport
|
22
|
-
requirement:
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 2
|
29
|
-
- 3
|
30
|
-
- 5
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 2.3.5
|
32
22
|
type: :runtime
|
33
23
|
prerelease: false
|
34
|
-
version_requirements:
|
35
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
36
31
|
name: activerecord
|
37
|
-
requirement:
|
38
|
-
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 2
|
44
|
-
- 3
|
45
|
-
- 5
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
46
37
|
version: 2.3.5
|
47
38
|
type: :runtime
|
48
39
|
prerelease: false
|
49
|
-
version_requirements:
|
50
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.5
|
46
|
+
- !ruby/object:Gem::Dependency
|
51
47
|
name: shoulda
|
52
|
-
requirement:
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
60
54
|
type: :development
|
61
55
|
prerelease: false
|
62
|
-
version_requirements:
|
63
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
64
63
|
name: rdoc
|
65
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
66
65
|
none: false
|
67
|
-
requirements:
|
66
|
+
requirements:
|
68
67
|
- - ~>
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
- 3
|
72
|
-
- 12
|
73
|
-
version: "3.12"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.12'
|
74
70
|
type: :development
|
75
71
|
prerelease: false
|
76
|
-
version_requirements:
|
77
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
78
79
|
name: bundler
|
79
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
80
81
|
none: false
|
81
|
-
requirements:
|
82
|
+
requirements:
|
82
83
|
- - ~>
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
- 1
|
86
|
-
version: "1"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1'
|
87
86
|
type: :development
|
88
87
|
prerelease: false
|
89
|
-
version_requirements:
|
90
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1'
|
94
|
+
- !ruby/object:Gem::Dependency
|
91
95
|
name: jeweler
|
92
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
93
97
|
none: false
|
94
|
-
requirements:
|
98
|
+
requirements:
|
95
99
|
- - ~>
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
segments:
|
98
|
-
- 1
|
99
|
-
- 8
|
100
|
-
- 3
|
100
|
+
- !ruby/object:Gem::Version
|
101
101
|
version: 1.8.3
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
|
-
version_requirements:
|
105
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.3
|
110
|
+
- !ruby/object:Gem::Dependency
|
106
111
|
name: sqlite3
|
107
|
-
requirement:
|
108
|
-
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
- 0
|
114
|
-
version: "0"
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
115
118
|
type: :development
|
116
119
|
prerelease: false
|
117
|
-
version_requirements:
|
118
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
119
127
|
name: pg
|
120
|
-
requirement:
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- -
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
|
126
|
-
- 0
|
127
|
-
version: "0"
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
128
134
|
type: :development
|
129
135
|
prerelease: false
|
130
|
-
version_requirements:
|
131
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
132
143
|
name: rails
|
133
|
-
requirement:
|
134
|
-
none: false
|
135
|
-
requirements:
|
136
|
-
- -
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
segments:
|
139
|
-
- 2
|
140
|
-
- 3
|
141
|
-
- 0
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
142
149
|
version: 2.3.0
|
143
150
|
type: :runtime
|
144
151
|
prerelease: false
|
145
|
-
version_requirements:
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 2.3.0
|
146
158
|
description: ModelFields is a Rails plugin that adds fields declarations to your models.
|
147
159
|
email: jgoizueta@gmail.com
|
148
160
|
executables: []
|
149
|
-
|
150
161
|
extensions: []
|
151
|
-
|
152
|
-
extra_rdoc_files:
|
162
|
+
extra_rdoc_files:
|
153
163
|
- LICENSE.txt
|
154
164
|
- README.rdoc
|
155
165
|
- TODO
|
156
|
-
files:
|
166
|
+
files:
|
157
167
|
- .document
|
158
168
|
- Gemfile
|
159
169
|
- Gemfile.lock
|
@@ -189,38 +199,32 @@ files:
|
|
189
199
|
- test/schema.rb
|
190
200
|
- test/test_diff.rb
|
191
201
|
- test/test_update.rb
|
192
|
-
has_rdoc: true
|
193
202
|
homepage: http://github.com/jgoizueta/modalfields
|
194
|
-
licenses:
|
203
|
+
licenses:
|
195
204
|
- MIT
|
196
205
|
post_install_message:
|
197
206
|
rdoc_options: []
|
198
|
-
|
199
|
-
require_paths:
|
207
|
+
require_paths:
|
200
208
|
- lib
|
201
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
202
210
|
none: false
|
203
|
-
requirements:
|
204
|
-
- -
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
|
207
|
-
segments:
|
211
|
+
requirements:
|
212
|
+
- - ! '>='
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
segments:
|
208
216
|
- 0
|
209
|
-
|
210
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
hash: -2875707183532562244
|
218
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
219
|
none: false
|
212
|
-
requirements:
|
213
|
-
- -
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
|
216
|
-
- 0
|
217
|
-
version: "0"
|
220
|
+
requirements:
|
221
|
+
- - ! '>='
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: '0'
|
218
224
|
requirements: []
|
219
|
-
|
220
225
|
rubyforge_project:
|
221
|
-
rubygems_version: 1.
|
226
|
+
rubygems_version: 1.8.23
|
222
227
|
signing_key:
|
223
228
|
specification_version: 3
|
224
229
|
summary: Model annotator with Ruby (Hobo-like) syntax and hooks.
|
225
230
|
test_files: []
|
226
|
-
|