autoforme 1.9.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.select{|r| types.include?(r[:type])}.map{|r| r[:name]}.sort_by(&:to_s)
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.sort_by(&:to_s)
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.to_s)}%"))
183
+ ds = ds.where(S.ilike(S.qualify(model.table_name, c), "%#{ds.escape_like(v)}%"))
172
184
  else
173
- ds = ds.where(S.qualify(model.table_name, c)=>model.db.typecast_value(column_type(c), v))
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
- obj.send(meth, ret)
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
@@ -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
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 = 1
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
- require 'autoforme/opts_attributes'
54
- require 'autoforme/model'
55
- require 'autoforme/framework'
56
- require 'autoforme/request'
57
- require 'autoforme/action'
58
- require 'autoforme/table'
59
- require 'autoforme/version'
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'
@@ -1,6 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- require 'autoforme'
3
+ require_relative '../../autoforme'
4
4
 
5
5
  class Roda
6
6
  module RodaPlugins
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.9.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: 2019-07-22 00:00:00.000000000 Z
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: 1.6.0
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: 1.6.0
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: '0'
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.0.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
@@ -1,2 +0,0 @@
1
- puts "Running specs with #{ENV['FRAMEWORK']||'roda'} framework"
2
- Dir['./spec/*_spec.rb'].each{|f| require f}