standardapi 7.1.2 → 7.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/standard_api/version.rb +1 -1
- data/lib/standard_api/views/application/_schema.json.jbuilder +2 -2
- data/lib/standard_api/views/application/_schema.streamer +2 -2
- data/lib/standard_api/visitors/validations.rb +13 -0
- data/test/standard_api/standard_api_test.rb +4 -0
- data/test/standard_api/test_app/models.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32cddbd957fc3a489fdb218dd229a7c2c9a0c6c0da919a0ae88d053447f80f1c
|
4
|
+
data.tar.gz: 8771b13221d1ebfdab96e26f482adbb6fa409cac70da0b5c6b8722628e63e35e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1b60baae979d8e0787cb22440b5f8030c4f2d398bc32aba9238a50af60b3b88a69fd0b23ccf64a965d06642b53686c41901c072d5f6d91a50144ff599174d7e
|
7
|
+
data.tar.gz: bf28b97423f785ee69cd138931b40e94737c6eb7de6ef662280d9deda64f4ee7dc366e66d89133cc999aa79a072db3d4c36f4f5889420be19d0af5ae267ea012
|
data/lib/standard_api/version.rb
CHANGED
@@ -71,13 +71,13 @@ else
|
|
71
71
|
json.set! 'auto_populated', !!column.auto_populated? if column.respond_to?(:auto_populated?)
|
72
72
|
|
73
73
|
json.set! 'readonly', (if controller.respond_to?("#{ model.model_name.singular }_attributes")
|
74
|
-
!controller.send("#{ model.model_name.singular }_attributes").include?(column.name)
|
74
|
+
!controller.send("#{ model.model_name.singular }_attributes").map(&:to_s).include?(column.name)
|
75
75
|
else
|
76
76
|
model.readonly_attribute?(column.name)
|
77
77
|
end)
|
78
78
|
|
79
79
|
visitor = StandardAPI::Visitors::Validator.new
|
80
|
-
validations = model.validators.select { |v| v.attributes.include?(column.name.to_sym) }.map { |v| visitor.accept(v, {}) }
|
80
|
+
validations = model.validators.select { |v| v.attributes.include?(column.name.to_sym) }.map { |v| visitor.accept(v, {}) }.compact
|
81
81
|
json.set! 'validations', validations
|
82
82
|
end
|
83
83
|
end
|
@@ -81,13 +81,13 @@ else
|
|
81
81
|
json.set! 'auto_populated', !!column.auto_populated? if column.respond_to?(:auto_populated?)
|
82
82
|
|
83
83
|
json.set! 'readonly', (if controller.respond_to?("#{ model.model_name.singular }_attributes")
|
84
|
-
!controller.send("#{ model.model_name.singular }_attributes").include?(column.name)
|
84
|
+
!controller.send("#{ model.model_name.singular }_attributes").map(&:to_s).include?(column.name)
|
85
85
|
else
|
86
86
|
true
|
87
87
|
end)
|
88
88
|
|
89
89
|
visitor = StandardAPI::Visitors::Validator.new
|
90
|
-
validations = model.validators.select { |v| v.attributes.include?(column.name.to_sym) }.map { |v| visitor.accept(v, {}) }
|
90
|
+
validations = model.validators.select { |v| v.attributes.include?(column.name.to_sym) }.map { |v| visitor.accept(v, {}) }.compact
|
91
91
|
json.set! 'validations', validations
|
92
92
|
end
|
93
93
|
end
|
@@ -47,12 +47,25 @@ module StandardAPI
|
|
47
47
|
visit_validator(:with, o.options)
|
48
48
|
end
|
49
49
|
|
50
|
+
def visit_ActiveModel_Validations_FormatValidator(o, col)
|
51
|
+
visit_validator(:format, o.options)
|
52
|
+
end
|
53
|
+
|
50
54
|
private
|
51
55
|
|
52
56
|
def visit_validator(name, options)
|
53
57
|
{ name => options.empty? ? true : options.as_json }
|
54
58
|
end
|
55
59
|
|
60
|
+
def visit(object, collector = nil)
|
61
|
+
dispatch_method = dispatch[object.class]
|
62
|
+
if collector
|
63
|
+
send dispatch_method, object, collector
|
64
|
+
else
|
65
|
+
send dispatch_method, object
|
66
|
+
end
|
67
|
+
rescue NoMethodError => e
|
68
|
+
end
|
56
69
|
|
57
70
|
end
|
58
71
|
|
@@ -164,6 +164,10 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|
164
164
|
assert_equal true, schema['models']['Account']['attributes']['id']['readonly']
|
165
165
|
assert_equal false, schema['models']['Account']['attributes']['name']['readonly']
|
166
166
|
|
167
|
+
assert_equal [
|
168
|
+
{"format"=>{"allow_nil"=>true, "with"=>"(?-mix:.+@.+)"}}
|
169
|
+
], schema['models']['Account']['attributes']['email']['validations']
|
170
|
+
|
167
171
|
assert_equal [
|
168
172
|
{ "presence" => true }
|
169
173
|
], schema['models']['Property']['attributes']['name']['validations']
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# = Models
|
2
2
|
|
3
3
|
class Account < ActiveRecord::Base
|
4
|
+
validates :email, format: /.+@.+/, allow_nil: true
|
4
5
|
has_many :photos, -> { order(:created_at) }
|
5
6
|
belongs_to :property
|
6
7
|
belongs_to :subject, polymorphic: true
|
@@ -113,6 +114,7 @@ class CreateModelTables < ActiveRecord::Migration[6.0]
|
|
113
114
|
|
114
115
|
create_table "accounts", force: :cascade do |t|
|
115
116
|
t.string 'name', limit: 255
|
117
|
+
t.string 'email', limit: 255
|
116
118
|
t.integer 'property_id'
|
117
119
|
t.integer "subject_id"
|
118
120
|
t.string "subject_type"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standardapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|