forest_liana 9.17.4 → 9.17.6
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.
- checksums.yaml +4 -4
- data/app/models/forest_liana/model/collection.rb +1 -0
- data/app/services/forest_liana/apimap_sorter.rb +1 -0
- data/app/services/forest_liana/schema_adapter.rb +14 -0
- data/lib/forest_liana/collection.rb +1 -0
- data/lib/forest_liana/engine.rb +6 -1
- data/lib/forest_liana/schema_file_updater.rb +2 -0
- data/lib/forest_liana/version.rb +1 -1
- data/spec/lib/forest_liana/collection_spec.rb +1 -0
- data/spec/lib/forest_liana/engine_spec.rb +50 -0
- data/spec/services/forest_liana/schema_adapter_spec.rb +1 -0
- data/test/services/forest_liana/schema_adapter_test.rb +33 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b410ae815afe1b2592a38ab27cb5133198fb76b4624dee5217cdb2c65583a74
|
|
4
|
+
data.tar.gz: 2527c8944450bd5348962ef65dea48c6e7e1f1bf434e409bdbb26591d93d03c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87d6d1e526ae2ea81c8eb5f0f4d557ae0cf65e406708cea7d998455f54d7eeee9bf9667efb6637e71b1a5deb4b084fc1fdd1dacb936499b00ab3bdcfdaec9178
|
|
7
|
+
data.tar.gz: fc0ee5ba0847140d5830715b861ccab6fe273fa7ea7c5f63ade342fa85645823c77ba51e91e2ef746dd5343c9a65e1d4012bf699fb6990e8b12dcdc344ac18db
|
|
@@ -37,6 +37,7 @@ class ForestLiana::Model::Collection
|
|
|
37
37
|
field[:enums] = nil unless field.key?(:enums)
|
|
38
38
|
field[:integration] = nil unless field.key?(:integration)
|
|
39
39
|
field[:is_filterable] = true unless field.key?(:is_filterable)
|
|
40
|
+
field[:is_primary_key] = false unless field.key?(:is_primary_key)
|
|
40
41
|
field[:is_read_only] = false unless field.key?(:is_read_only)
|
|
41
42
|
field[:is_required] = false unless field.key?(:is_required)
|
|
42
43
|
field[:is_sortable] = true unless field.key?(:is_sortable)
|
|
@@ -248,6 +248,7 @@ module ForestLiana
|
|
|
248
248
|
relationship: get_relationship_type(association),
|
|
249
249
|
reference: "#{association.name.to_s}.id",
|
|
250
250
|
inverse_of: @model.name.demodulize.underscore,
|
|
251
|
+
is_primary_key: false,
|
|
251
252
|
is_filterable: false,
|
|
252
253
|
is_sortable: true,
|
|
253
254
|
is_read_only: false,
|
|
@@ -278,6 +279,7 @@ module ForestLiana
|
|
|
278
279
|
field[:field] = association.name
|
|
279
280
|
field[:inverse_of] = inverse_of(association)
|
|
280
281
|
field[:relationship] = get_relationship_type(association)
|
|
282
|
+
field[:is_primary_key] = false
|
|
281
283
|
|
|
282
284
|
ForestLiana::SchemaUtils.disable_filter_and_sort_if_cross_db!(
|
|
283
285
|
field,
|
|
@@ -332,6 +334,7 @@ module ForestLiana
|
|
|
332
334
|
schema = {
|
|
333
335
|
field: column.name,
|
|
334
336
|
type: column_type,
|
|
337
|
+
is_primary_key: primary_key?(column),
|
|
335
338
|
is_filterable: true,
|
|
336
339
|
is_sortable: true,
|
|
337
340
|
is_read_only: false,
|
|
@@ -351,6 +354,16 @@ module ForestLiana
|
|
|
351
354
|
add_validations(schema, column)
|
|
352
355
|
end
|
|
353
356
|
|
|
357
|
+
def primary_key?(column)
|
|
358
|
+
pk = @model.primary_key
|
|
359
|
+
if pk.is_a?(Array)
|
|
360
|
+
# NOTICE: composite_primary_keys exposes an Array of column names.
|
|
361
|
+
pk.map(&:to_s).include?(column.name)
|
|
362
|
+
else
|
|
363
|
+
!pk.nil? && pk.to_s == column.name
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
354
367
|
def get_schema_for_association(association)
|
|
355
368
|
opts ={
|
|
356
369
|
field: association.name.to_s,
|
|
@@ -358,6 +371,7 @@ module ForestLiana
|
|
|
358
371
|
relationship: get_relationship_type(association),
|
|
359
372
|
reference: "#{ForestLiana.name_for(association.klass)}.id",
|
|
360
373
|
inverse_of: inverse_of(association),
|
|
374
|
+
is_primary_key: false,
|
|
361
375
|
is_filterable: !is_many_association(association),
|
|
362
376
|
is_sortable: true,
|
|
363
377
|
is_read_only: false,
|
|
@@ -68,6 +68,7 @@ module ForestLiana::Collection
|
|
|
68
68
|
opts[:is_read_only] = true unless opts.has_key?(:is_read_only)
|
|
69
69
|
opts[:is_read_only] = false if opts.has_key?(:set)
|
|
70
70
|
opts[:is_required] = false unless opts.has_key?(:is_required)
|
|
71
|
+
opts[:is_primary_key] = false unless opts.has_key?(:is_primary_key)
|
|
71
72
|
opts[:type] = "String" unless opts.has_key?(:type)
|
|
72
73
|
opts[:default_value] = nil unless opts.has_key?(:default_value)
|
|
73
74
|
opts[:integration] = nil unless opts.has_key?(:integration)
|
data/lib/forest_liana/engine.rb
CHANGED
|
@@ -59,7 +59,12 @@ module ForestLiana
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def rake?
|
|
62
|
-
|
|
62
|
+
# NOTICE: `rails db:migrate` runs through Rake but exposes $0 as `rails`,
|
|
63
|
+
# so matching the binary name alone let the bootstrapper introspect
|
|
64
|
+
# models mid-migration (crashing on enums backed by a pending column).
|
|
65
|
+
return true if File.basename($0) == 'rake'
|
|
66
|
+
|
|
67
|
+
defined?(Rake) && Rake.application.top_level_tasks.any? { |task| task != 'default' }
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
def database_available?
|
|
@@ -26,6 +26,7 @@ module ForestLiana
|
|
|
26
26
|
'enums',
|
|
27
27
|
'integration',
|
|
28
28
|
'is_filterable',
|
|
29
|
+
'is_primary_key',
|
|
29
30
|
'is_read_only',
|
|
30
31
|
'is_required',
|
|
31
32
|
'is_sortable',
|
|
@@ -86,6 +87,7 @@ module ForestLiana
|
|
|
86
87
|
field['enums'] = nil unless field.has_key?('enums')
|
|
87
88
|
field['integration'] = nil unless field.has_key?('integration')
|
|
88
89
|
field['is_filterable'] = false unless field.has_key?('is_filterable')
|
|
90
|
+
field['is_primary_key'] = false unless field.has_key?('is_primary_key')
|
|
89
91
|
field['is_read_only'] = true unless field.has_key?('is_read_only')
|
|
90
92
|
field['is_required'] = false unless field.has_key?('is_required')
|
|
91
93
|
field['is_sortable'] = false unless field.has_key?('is_sortable')
|
data/lib/forest_liana/version.rb
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
|
|
3
|
+
module ForestLiana
|
|
4
|
+
describe Engine do
|
|
5
|
+
subject(:engine) { ForestLiana::Engine.instance }
|
|
6
|
+
|
|
7
|
+
describe '#rake?' do
|
|
8
|
+
around do |example|
|
|
9
|
+
original_program_name = $0
|
|
10
|
+
example.run
|
|
11
|
+
$0 = original_program_name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'when invoked through the legacy `rake` binary' do
|
|
15
|
+
it 'returns true' do
|
|
16
|
+
$0 = '/usr/local/bin/rake'
|
|
17
|
+
|
|
18
|
+
expect(engine.rake?).to be(true)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when invoked through `rails` while running a Rake task (e.g. rails db:migrate)' do
|
|
23
|
+
it 'returns true so the bootstrapper does not introspect models mid-task' do
|
|
24
|
+
$0 = '/usr/local/bin/rails'
|
|
25
|
+
allow(Rake.application).to receive(:top_level_tasks).and_return(['db:migrate'])
|
|
26
|
+
|
|
27
|
+
expect(engine.rake?).to be(true)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'when booting the application to serve (rails server / console)' do
|
|
32
|
+
it 'returns false so the bootstrapper runs and builds the apimap' do
|
|
33
|
+
$0 = '/usr/local/bin/rails'
|
|
34
|
+
allow(Rake.application).to receive(:top_level_tasks).and_return([])
|
|
35
|
+
|
|
36
|
+
expect(engine.rake?).to be(false)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'when only the default Rake task is present' do
|
|
41
|
+
it 'returns false' do
|
|
42
|
+
$0 = '/usr/local/bin/rails'
|
|
43
|
+
allow(Rake.application).to receive(:top_level_tasks).and_return(['default'])
|
|
44
|
+
|
|
45
|
+
expect(engine.rake?).to be(false)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -36,6 +36,39 @@ module ForestLiana
|
|
|
36
36
|
assert fields.size == 1
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
test 'the standard primary key column is flagged is_primary_key: true' do
|
|
40
|
+
adapter = SchemaAdapter.new(IntegerField)
|
|
41
|
+
schema = adapter.send(:get_schema_for_column, IntegerField.columns_hash['id'])
|
|
42
|
+
assert_equal true, schema[:is_primary_key]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'a non primary key column is flagged is_primary_key: false' do
|
|
46
|
+
adapter = SchemaAdapter.new(IntegerField)
|
|
47
|
+
schema = adapter.send(:get_schema_for_column, IntegerField.columns_hash['field'])
|
|
48
|
+
assert_equal false, schema[:is_primary_key]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
test 'every column of a composite primary key is flagged is_primary_key: true' do
|
|
52
|
+
adapter = SchemaAdapter.new(BelongsToField)
|
|
53
|
+
BelongsToField.define_singleton_method(:primary_key) { ['id', 'has_one_field_id'] }
|
|
54
|
+
is_pk = ->(name) do
|
|
55
|
+
adapter.send(:get_schema_for_column, BelongsToField.columns_hash[name])[:is_primary_key]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
assert_equal true, is_pk.call('id')
|
|
59
|
+
assert_equal true, is_pk.call('has_one_field_id')
|
|
60
|
+
assert_equal false, is_pk.call('has_many_field_id')
|
|
61
|
+
ensure
|
|
62
|
+
BelongsToField.singleton_class.send(:remove_method, :primary_key)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test 'an association is flagged is_primary_key: false' do
|
|
66
|
+
adapter = SchemaAdapter.new(HasOneField)
|
|
67
|
+
association = HasOneField.reflect_on_association(:belongs_to_field)
|
|
68
|
+
schema = adapter.send(:get_schema_for_association, association)
|
|
69
|
+
assert_equal false, schema[:is_primary_key]
|
|
70
|
+
end
|
|
71
|
+
|
|
39
72
|
test 'belongsTo relationship' do
|
|
40
73
|
schema = SchemaAdapter.new(BelongsToField).perform
|
|
41
74
|
fields = schema.fields.select do |field|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_liana
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 9.17.
|
|
4
|
+
version: 9.17.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sandro Munda
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -438,6 +438,7 @@ files:
|
|
|
438
438
|
- spec/helpers/forest_liana/schema_helper_spec.rb
|
|
439
439
|
- spec/lib/forest_liana/bootstrapper_spec.rb
|
|
440
440
|
- spec/lib/forest_liana/collection_spec.rb
|
|
441
|
+
- spec/lib/forest_liana/engine_spec.rb
|
|
441
442
|
- spec/lib/forest_liana/schema_file_updater_spec.rb
|
|
442
443
|
- spec/rails_helper.rb
|
|
443
444
|
- spec/requests/actions_controller_spec.rb
|
|
@@ -749,6 +750,7 @@ test_files:
|
|
|
749
750
|
- spec/helpers/forest_liana/schema_helper_spec.rb
|
|
750
751
|
- spec/lib/forest_liana/bootstrapper_spec.rb
|
|
751
752
|
- spec/lib/forest_liana/collection_spec.rb
|
|
753
|
+
- spec/lib/forest_liana/engine_spec.rb
|
|
752
754
|
- spec/lib/forest_liana/schema_file_updater_spec.rb
|
|
753
755
|
- spec/rails_helper.rb
|
|
754
756
|
- spec/requests/actions_controller_spec.rb
|