declare_schema 1.4.0.colin.3 → 1.4.0.colin.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d774a80915bfd6f22349e18be176e237c901d595a871144a08d73478946147b
4
- data.tar.gz: 0cc5d18ba43357d595dff24ff3a2bf3f9443b9d3f8ed9ec909d53708b2820984
3
+ metadata.gz: b48f50b03282da270199e8bb46e4e7a2d69068a8753203364835db206692a94a
4
+ data.tar.gz: b72de21ed3123f0b4e9527d5e5ee805742b2c21628adeabd4213925858062914
5
5
  SHA512:
6
- metadata.gz: 96b51490860259a27e1b1fcbe02bab2722ca069ec9ee314879ccf563fc4f420c44485de9ec57035165a057953a9ba4705c5575c38f6a4592088d47c8704dafc1
7
- data.tar.gz: ddb153c4999b17c8c74885b4bfa9ef7488992c760797808af40840cdb579f8e162d66b0cf043b1543905ef1282252c5dd371d40881cd403bdba2429b6590f81a
6
+ metadata.gz: 24edb7af1a43c955d5bc3664d755ea30d225bf1bce15e98765693ee7de2da87b4d66c42b0c6f6818b5a81b9485536da4ccd824319b91744eee6837c7317d80ca
7
+ data.tar.gz: 996169b7db3b3a8426968e8924181a0c588b7035d00a563fb78708eb8e47e2384f20b5838a2bc491ccbef3f45c6e3f462c3e0095261477841cfe666b320acfd2
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.4)
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
@@ -16,7 +16,6 @@ module DeclareSchema
16
16
  # attr_types holds the type class for any attribute reader (i.e. getter
17
17
  # method) that returns rich-types
18
18
  inheriting_cattr_reader attr_types: HashWithIndifferentAccess.new
19
- inheriting_cattr_reader attr_order: []
20
19
 
21
20
  # field_specs holds FieldSpec objects for every declared
22
21
  # field. Note that attribute readers are created (by ActiveRecord)
@@ -26,9 +25,9 @@ module DeclareSchema
26
25
  inheriting_cattr_reader field_specs: HashWithIndifferentAccess.new
27
26
 
28
27
  # 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: []
28
+ inheriting_cattr_reader index_definitions: Set.new
29
+ inheriting_cattr_reader ignore_indexes: Set.new
30
+ inheriting_cattr_reader constraint_specs: Set.new
32
31
 
33
32
  # table_options holds optional configuration for the create_table statement
34
33
  # supported options include :charset and :collation
@@ -50,11 +49,7 @@ module DeclareSchema
50
49
 
51
50
  module ClassMethods
52
51
  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
52
+ index_definitions << ::DeclareSchema::Model::IndexDefinition.new(self, fields, **options)
58
53
  end
59
54
 
60
55
  def primary_key_index(*fields)
@@ -85,7 +80,6 @@ module DeclareSchema
85
80
  _add_validations_for_field(name, type, args, options)
86
81
  _add_index_for_field(name, args, options)
87
82
  field_specs[name] = ::DeclareSchema::Model::FieldSpec.new(self, name, type, position: field_specs.size, **options)
88
- attr_order << name unless attr_order.include?(name)
89
83
  end
90
84
 
91
85
  def index_definitions_with_primary_key
@@ -124,13 +118,14 @@ module DeclareSchema
124
118
  when String
125
119
  Kernel.warn("belongs_to index: 'name' is deprecated; use index: { name: 'name' } instead (in #{name})")
126
120
  index_options[:name] = index_value
127
- # when false -- impossible since we checked that above
128
121
  when true
122
+ when false
123
+ raise ArgumentError, "belongs_to index: false contradicts others options #{options.inspect} (in #{name})"
129
124
  when nil
130
125
  when Hash
131
126
  index_options = index_value
132
127
  else
133
- raise ArgumentError, "belongs_to index: must be true or false or a Hash; got #{index_value.inspect}"
128
+ raise ArgumentError, "belongs_to index: must be true or false or a Hash; got #{index_value.inspect} (in #{name})"
134
129
  end
135
130
 
136
131
  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.4"
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,7 +1,7 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development adapted from hobo_fields by Tom Locke