declare_schema 1.4.0.colin.3 → 1.4.0.colin.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d774a80915bfd6f22349e18be176e237c901d595a871144a08d73478946147b
4
- data.tar.gz: 0cc5d18ba43357d595dff24ff3a2bf3f9443b9d3f8ed9ec909d53708b2820984
3
+ metadata.gz: 770c10f063190aa951ca0ab0956c1988876e9a60c235e08ac9013d6a2f55dc3d
4
+ data.tar.gz: e0935d656bc3dd48e21c41edfbfbaf8fa416dee00bac305fcaa8b08a85bc0c02
5
5
  SHA512:
6
- metadata.gz: 96b51490860259a27e1b1fcbe02bab2722ca069ec9ee314879ccf563fc4f420c44485de9ec57035165a057953a9ba4705c5575c38f6a4592088d47c8704dafc1
7
- data.tar.gz: ddb153c4999b17c8c74885b4bfa9ef7488992c760797808af40840cdb579f8e162d66b0cf043b1543905ef1282252c5dd371d40881cd403bdba2429b6590f81a
6
+ metadata.gz: d8e261efe79f5b6fdbb86f1fec4a81445e65baf664d26dd6db2c3e85d2d94c305967a4e0f9f5dcce0106daab83480975034dd20c47a319b9365a60b031ec7d49
7
+ data.tar.gz: 22da299dd84f766df2668d4a81f86d3398be03cab012ac098fc1d7d1fab10d65e6ecc0b3fec126ff7c4b57ee18df6c5cab0219fc681b146891f98c06131e3f74
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- declare_schema (1.4.0.colin.3)
4
+ declare_schema (1.4.0.colin.5)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -52,23 +52,23 @@ module DeclareSchema
52
52
  end
53
53
 
54
54
  def index_definitions_with_primary_key
55
- [
55
+ @index_definitions_with_primary_key ||= Set.new([
56
56
  IndexDefinition.new(self, foreign_keys, unique: true, name: Model::IndexDefinition::PRIMARY_KEY_NAME), # creates a primary composite key on both foreign keys
57
57
  IndexDefinition.new(self, foreign_keys.last) # not unique by itself; combines with primary key to be unique
58
- ]
58
+ ])
59
59
  end
60
60
 
61
61
  alias_method :index_definitions, :index_definitions_with_primary_key
62
62
 
63
63
  def ignore_indexes
64
- []
64
+ @ignore_indexes ||= Set.new
65
65
  end
66
66
 
67
67
  def constraint_specs
68
- [
68
+ @constraint_specs ||= Set.new([
69
69
  ForeignKeyDefinition.new(self, foreign_keys.first, parent_table: foreign_key_classes.first.table_name, constraint_name: "#{join_table}_FK1", dependent: :delete),
70
70
  ForeignKeyDefinition.new(self, foreign_keys.last, parent_table: foreign_key_classes.last.table_name, constraint_name: "#{join_table}_FK2", dependent: :delete)
71
- ]
71
+ ])
72
72
  end
73
73
  end
74
74
  end
@@ -26,9 +26,9 @@ module DeclareSchema
26
26
  inheriting_cattr_reader field_specs: HashWithIndifferentAccess.new
27
27
 
28
28
  # index_definitions holds IndexDefinition objects for all the declared indexes.
29
- inheriting_cattr_reader index_definitions: []
30
- inheriting_cattr_reader ignore_indexes: []
31
- inheriting_cattr_reader constraint_specs: []
29
+ inheriting_cattr_reader index_definitions: Set.new
30
+ inheriting_cattr_reader ignore_indexes: Set.new
31
+ inheriting_cattr_reader constraint_specs: Set.new
32
32
 
33
33
  # table_options holds optional configuration for the create_table statement
34
34
  # supported options include :charset and :collation
@@ -50,11 +50,7 @@ module DeclareSchema
50
50
 
51
51
  module ClassMethods
52
52
  def index(fields, **options)
53
- # make index idempotent
54
- index = ::DeclareSchema::Model::IndexDefinition.new(self, fields, **options)
55
- unless index_definitions.any? { |index_spec| index_spec.equivalent?(index) }
56
- index_definitions << index
57
- end
53
+ index_definitions << ::DeclareSchema::Model::IndexDefinition.new(self, fields, **options)
58
54
  end
59
55
 
60
56
  def primary_key_index(*fields)
@@ -69,7 +65,7 @@ module DeclareSchema
69
65
  end
70
66
 
71
67
  # tell the migration generator to ignore the named index. Useful for existing indexes, or for indexes
72
- # that can't be automatically generated (for example: a prefix index in MySQL)
68
+ # that can't be automatically generated.
73
69
  def ignore_index(index_name)
74
70
  ignore_indexes << index_name.to_s
75
71
  end
@@ -124,13 +120,14 @@ module DeclareSchema
124
120
  when String
125
121
  Kernel.warn("belongs_to index: 'name' is deprecated; use index: { name: 'name' } instead (in #{name})")
126
122
  index_options[:name] = index_value
127
- # when false -- impossible since we checked that above
128
123
  when true
124
+ when false
125
+ raise ArgumentError, "belongs_to index: false contradicts others options #{options.inspect} (in #{name})"
129
126
  when nil
130
127
  when Hash
131
128
  index_options = index_value
132
129
  else
133
- raise ArgumentError, "belongs_to index: must be true or false or a Hash; got #{index_value.inspect}"
130
+ raise ArgumentError, "belongs_to index: must be true or false or a Hash; got #{index_value.inspect} (in #{name})"
134
131
  end
135
132
 
136
133
  if options.has_key?(:unique)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeclareSchema
4
- VERSION = "1.4.0.colin.3"
4
+ VERSION = "1.4.0.colin.5"
5
5
  end
@@ -141,8 +141,8 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
141
141
  end
142
142
 
143
143
  describe 'ignore_indexes' do
144
- it 'returns empty array' do
145
- expect(subject.ignore_indexes).to eq([])
144
+ it 'returns empty Set' do
145
+ expect(subject.ignore_indexes).to eq(Set.new)
146
146
  end
147
147
  end
148
148
 
@@ -156,10 +156,11 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do
156
156
  expect(result.first.parent_table_name).to be(Parent1.table_name)
157
157
  expect(result.first.on_delete_cascade).to be_truthy
158
158
 
159
- expect(result.last).to be_a(::DeclareSchema::Model::ForeignKeyDefinition)
160
- expect(result.last.foreign_key).to eq(foreign_keys.last)
161
- expect(result.last.parent_table_name).to be(Parent2.table_name)
162
- expect(result.last.on_delete_cascade).to be_truthy
159
+ sample = result.to_a.last
160
+ expect(sample).to be_a(::DeclareSchema::Model::ForeignKeyDefinition)
161
+ expect(sample.foreign_key).to eq(foreign_keys.last)
162
+ expect(sample.parent_table_name).to be(Parent2.table_name)
163
+ expect(sample.on_delete_cascade).to be_truthy
163
164
  end
164
165
  end
165
166
  end
@@ -112,15 +112,16 @@ RSpec.describe DeclareSchema::Model::IndexDefinition do
112
112
  it do
113
113
  expect(model_class.index_definitions.size).to eq(1)
114
114
 
115
- expect(model_class.index_definitions[0].name).to eq('index_index_definition_test_models_on_name')
116
- expect(model_class.index_definitions[0].fields).to eq(['name'])
117
- expect(model_class.index_definitions[0].unique).to eq(false)
115
+ sample = model_class.index_definitions.to_a.first
116
+ expect(sample.name).to eq('index_index_definition_test_models_on_name')
117
+ expect(sample.fields).to eq(['name'])
118
+ expect(sample.unique).to eq(false)
118
119
  end
119
120
  end
120
121
 
121
122
  describe 'has index_definitions_with_primary_key' do
122
123
  it do
123
- expect(model_class.index_definitions_with_primary_key).to be_kind_of(Array)
124
+ expect(model_class.index_definitions_with_primary_key).to be_kind_of(Set)
124
125
  result = model_class.index_definitions_with_primary_key.sort_by(&:name)
125
126
  expect(result.size).to eq(2)
126
127
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: declare_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.colin.3
4
+ version: 1.4.0.colin.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-13 00:00:00.000000000 Z
11
+ date: 2024-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails