autoforme 1.9.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +26 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +72 -12
- data/autoforme.js +97 -56
- data/lib/autoforme/action.rb +29 -24
- data/lib/autoforme/frameworks/rails.rb +10 -2
- data/lib/autoforme/frameworks/roda.rb +16 -5
- data/lib/autoforme/frameworks/sinatra.rb +9 -2
- data/lib/autoforme/model.rb +1 -1
- data/lib/autoforme/models/sequel.rb +36 -7
- data/lib/autoforme/version.rb +2 -2
- data/lib/autoforme.rb +7 -8
- data/lib/roda/plugins/autoforme.rb +1 -1
- metadata +26 -19
- data/Rakefile +0 -69
- data/spec/all.rb +0 -2
- data/spec/associations_spec.rb +0 -802
- data/spec/basic_spec.rb +0 -1150
- data/spec/mtm_spec.rb +0 -509
- data/spec/rails_spec_helper.rb +0 -78
- data/spec/roda_spec.rb +0 -72
- data/spec/roda_spec_helper.rb +0 -87
- data/spec/sequel_spec_helper.rb +0 -43
- data/spec/sinatra_spec_helper.rb +0 -55
- data/spec/spec_helper.rb +0 -79
- data/spec/unit_spec.rb +0 -511
@@ -98,14 +98,26 @@ module AutoForme
|
|
98
98
|
ref[:keys].zip(ref[:primary_keys].map{|k| obj.send(k)})
|
99
99
|
end
|
100
100
|
|
101
|
+
# Array of many to many association name strings for editable
|
102
|
+
# many to many associations.
|
103
|
+
def editable_mtm_association_names
|
104
|
+
association_names([:many_to_many]) do |r|
|
105
|
+
model.method_defined?(r.add_method) && model.method_defined?(r.remove_method)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
101
109
|
# Array of many to many association name strings.
|
102
110
|
def mtm_association_names
|
103
111
|
association_names([:many_to_many])
|
104
112
|
end
|
105
113
|
|
106
|
-
# Array of association name strings for given association types
|
114
|
+
# Array of association name strings for given association types. If a block is
|
115
|
+
# given, only include associations where the block returns truthy.
|
107
116
|
def association_names(types=SUPPORTED_ASSOCIATION_TYPES)
|
108
|
-
model.all_association_reflections.
|
117
|
+
model.all_association_reflections.
|
118
|
+
select{|r| types.include?(r[:type]) && (!block_given? || yield(r))}.
|
119
|
+
map{|r| r[:name]}.
|
120
|
+
sort_by(&:to_s)
|
109
121
|
end
|
110
122
|
|
111
123
|
# Save the object, returning the object if successful, or nil if not.
|
@@ -138,7 +150,7 @@ module AutoForme
|
|
138
150
|
columns[i] = reflection[:name]
|
139
151
|
end
|
140
152
|
end
|
141
|
-
columns.
|
153
|
+
columns.sort!
|
142
154
|
end
|
143
155
|
|
144
156
|
# Add a filter restricting access to only rows where the column name
|
@@ -158,7 +170,7 @@ module AutoForme
|
|
158
170
|
params = request.params
|
159
171
|
ds = apply_associated_eager(:search, request, all_dataset_for(type, request))
|
160
172
|
columns_for(:search_form, request).each do |c|
|
161
|
-
if (v = params[c.to_s]) && !v.empty?
|
173
|
+
if (v = params[c.to_s]) && !(v = v.to_s).empty?
|
162
174
|
if association?(c)
|
163
175
|
ref = model.association_reflection(c)
|
164
176
|
ads = ref.associated_dataset
|
@@ -168,9 +180,16 @@ module AutoForme
|
|
168
180
|
primary_key = S.qualify(ref.associated_class.table_name, ref.primary_key)
|
169
181
|
ds = ds.where(S.qualify(model.table_name, ref[:key])=>ads.where(primary_key=>v).select(primary_key))
|
170
182
|
elsif column_type(c) == :string
|
171
|
-
ds = ds.where(S.ilike(S.qualify(model.table_name, c), "%#{ds.escape_like(v
|
183
|
+
ds = ds.where(S.ilike(S.qualify(model.table_name, c), "%#{ds.escape_like(v)}%"))
|
172
184
|
else
|
173
|
-
|
185
|
+
begin
|
186
|
+
typecasted_value = model.db.typecast_value(column_type(c), v)
|
187
|
+
rescue S::InvalidValue
|
188
|
+
ds = ds.where(false)
|
189
|
+
break
|
190
|
+
else
|
191
|
+
ds = ds.where(S.qualify(model.table_name, c)=>typecasted_value)
|
192
|
+
end
|
174
193
|
end
|
175
194
|
end
|
176
195
|
end
|
@@ -293,7 +312,17 @@ module AutoForme
|
|
293
312
|
ids.each do |id|
|
294
313
|
next if id.to_s.empty?
|
295
314
|
ret = assoc_class ? assoc_class.with_pk(:association, request, id) : obj.send(:_apply_association_options, ref, ref.associated_class.dataset.clone).with_pk!(id)
|
296
|
-
|
315
|
+
begin
|
316
|
+
model.db.transaction(:savepoint=>true){obj.send(meth, ret)}
|
317
|
+
rescue S::UniqueConstraintViolation
|
318
|
+
# Already added, safe to ignore
|
319
|
+
rescue S::ConstraintViolation
|
320
|
+
# Old versions of sqlite3 and jdbc-sqlite3 can raise generic
|
321
|
+
# ConstraintViolation instead of UniqueConstraintViolation
|
322
|
+
# :nocov:
|
323
|
+
raise unless model.db.database_type == :sqlite
|
324
|
+
# :nocov:
|
325
|
+
end
|
297
326
|
end
|
298
327
|
end
|
299
328
|
end
|
data/lib/autoforme/version.rb
CHANGED
@@ -6,11 +6,11 @@ module AutoForme
|
|
6
6
|
MAJOR = 1
|
7
7
|
|
8
8
|
# The minor version of AutoForme, updated for new feature releases of AutoForme.
|
9
|
-
MINOR =
|
9
|
+
MINOR = 12
|
10
10
|
|
11
11
|
# The patch version of AutoForme, updated only for bug fixes from the last
|
12
12
|
# feature release.
|
13
|
-
TINY =
|
13
|
+
TINY = 0
|
14
14
|
|
15
15
|
# Version constant, use <tt>AutoForme.version</tt> instead.
|
16
16
|
VERSION = "#{MAJOR}.#{MINOR}.#{TINY}".freeze
|
data/lib/autoforme.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
3
|
require 'forme'
|
4
|
-
require 'thread'
|
5
4
|
require 'rack/utils'
|
6
5
|
|
7
6
|
module AutoForme
|
@@ -50,10 +49,10 @@ module AutoForme
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
require_relative 'autoforme/opts_attributes'
|
53
|
+
require_relative 'autoforme/model'
|
54
|
+
require_relative 'autoforme/framework'
|
55
|
+
require_relative 'autoforme/request'
|
56
|
+
require_relative 'autoforme/action'
|
57
|
+
require_relative 'autoforme/table'
|
58
|
+
require_relative 'autoforme/version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoforme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forme
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-global_expectations
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: capybara
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -214,7 +228,6 @@ files:
|
|
214
228
|
- CHANGELOG
|
215
229
|
- MIT-LICENSE
|
216
230
|
- README.rdoc
|
217
|
-
- Rakefile
|
218
231
|
- autoforme.js
|
219
232
|
- lib/autoforme.rb
|
220
233
|
- lib/autoforme/action.rb
|
@@ -229,21 +242,15 @@ files:
|
|
229
242
|
- lib/autoforme/table.rb
|
230
243
|
- lib/autoforme/version.rb
|
231
244
|
- lib/roda/plugins/autoforme.rb
|
232
|
-
- spec/all.rb
|
233
|
-
- spec/associations_spec.rb
|
234
|
-
- spec/basic_spec.rb
|
235
|
-
- spec/mtm_spec.rb
|
236
|
-
- spec/rails_spec_helper.rb
|
237
|
-
- spec/roda_spec.rb
|
238
|
-
- spec/roda_spec_helper.rb
|
239
|
-
- spec/sequel_spec_helper.rb
|
240
|
-
- spec/sinatra_spec_helper.rb
|
241
|
-
- spec/spec_helper.rb
|
242
|
-
- spec/unit_spec.rb
|
243
245
|
homepage: http://github.com/jeremyevans/autoforme
|
244
246
|
licenses:
|
245
247
|
- MIT
|
246
|
-
metadata:
|
248
|
+
metadata:
|
249
|
+
bug_tracker_uri: https://github.com/jeremyevans/autoforme/issues
|
250
|
+
changelog_uri: http://autoforme.jeremyevans.net/files/CHANGELOG.html
|
251
|
+
documentation_uri: http://autoforme.jeremyevans.net
|
252
|
+
mailing_list_uri: https://github.com/jeremyevans/autoforme/discussions
|
253
|
+
source_code_uri: https://github.com/jeremyevans/autoforme
|
247
254
|
post_install_message:
|
248
255
|
rdoc_options:
|
249
256
|
- "--quiet"
|
@@ -259,14 +266,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
259
266
|
requirements:
|
260
267
|
- - ">="
|
261
268
|
- !ruby/object:Gem::Version
|
262
|
-
version:
|
269
|
+
version: 1.9.2
|
263
270
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
264
271
|
requirements:
|
265
272
|
- - ">="
|
266
273
|
- !ruby/object:Gem::Version
|
267
274
|
version: '0'
|
268
275
|
requirements: []
|
269
|
-
rubygems_version: 3.
|
276
|
+
rubygems_version: 3.3.7
|
270
277
|
signing_key:
|
271
278
|
specification_version: 4
|
272
279
|
summary: Web Administrative Console for Roda/Sinatra/Rails and Sequel::Model
|
data/Rakefile
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require "rake"
|
2
|
-
require "rake/clean"
|
3
|
-
|
4
|
-
CLEAN.include ["autoforme-*.gem", "rdoc", "coverage"]
|
5
|
-
|
6
|
-
desc "Build autoforme gem"
|
7
|
-
task :package=>[:clean] do |p|
|
8
|
-
sh %{#{FileUtils::RUBY} -S gem build autoforme.gemspec}
|
9
|
-
end
|
10
|
-
|
11
|
-
### Specs
|
12
|
-
|
13
|
-
spec = proc do |env|
|
14
|
-
env.each{|k,v| ENV[k] = v}
|
15
|
-
sh "#{FileUtils::RUBY} spec/all.rb"
|
16
|
-
env.each{|k,v| ENV.delete(k)}
|
17
|
-
end
|
18
|
-
task :default => :roda_spec
|
19
|
-
|
20
|
-
desc "Run specs for all frameworks"
|
21
|
-
spec_tasks = [:roda_spec, :sinatra_spec]
|
22
|
-
if RUBY_VERSION >= '1.9'
|
23
|
-
spec_tasks << :rails_spec
|
24
|
-
end
|
25
|
-
task :spec => spec_tasks
|
26
|
-
|
27
|
-
%w'roda sinatra rails'.each do |framework|
|
28
|
-
desc "Run specs with for #{framework} with coverage"
|
29
|
-
task "#{framework}_spec" do
|
30
|
-
spec.call('FRAMEWORK'=>framework)
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Run specs with coverage for #{framework}"
|
34
|
-
task "#{framework}_spec_cov" do
|
35
|
-
spec.call('FRAMEWORK'=>framework, 'COVERAGE'=>'1')
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "Run specs with -w for #{framework}, some warnings filtered"
|
39
|
-
task "#{framework}_spec_w" do
|
40
|
-
spec.call('FRAMEWORK'=>framework, 'RUBYOPT'=>'-w', 'WARNING'=>'1')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
### RDoc
|
45
|
-
|
46
|
-
RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'AutoForme: Web Administrative Console for Sinatra/Rails and Sequel']
|
47
|
-
|
48
|
-
begin
|
49
|
-
gem 'hanna-nouveau'
|
50
|
-
RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
|
51
|
-
rescue Gem::LoadError
|
52
|
-
end
|
53
|
-
|
54
|
-
rdoc_task_class = begin
|
55
|
-
require "rdoc/task"
|
56
|
-
RDoc::Task
|
57
|
-
rescue LoadError
|
58
|
-
require "rake/rdoctask"
|
59
|
-
Rake::RDocTask
|
60
|
-
end
|
61
|
-
|
62
|
-
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
|
63
|
-
|
64
|
-
rdoc_task_class.new do |rdoc|
|
65
|
-
rdoc.rdoc_dir = "rdoc"
|
66
|
-
rdoc.options += RDOC_OPTS
|
67
|
-
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
68
|
-
end
|
69
|
-
|
data/spec/all.rb
DELETED