uuidable 0.1.3 → 0.2.0

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
  SHA1:
3
- metadata.gz: 7243fffe7adb312c2dbf701e37b459c4e5d3cd12
4
- data.tar.gz: 9925352679e6fba0c5a6df14497f72d47170a939
3
+ metadata.gz: 20a81bfd257b2ccc14fcf0d5534cf959dd312e02
4
+ data.tar.gz: 80d2fd04ee3c6d969c46737ec209e6673fb07a64
5
5
  SHA512:
6
- metadata.gz: 28fe8675eee77c1d8b6ae4ca32603fe0a020533e0f3bf5cac68bf72e5b8a3e1d0447be37331d3d7d8569081e9c30e1d704417d2ef3b5ed698ce59d1c12087c81
7
- data.tar.gz: 594ab432715ebbe4a4a9872550c967a4f476e3d0682eb11813ad835ab902b7f13aa12a52f9494b56213b1da49e49173f5e83eb0f4517955109f332c0a5ec56ae
6
+ metadata.gz: 826e63ce56cedda8472dda13aaa4032786263743bf9f88fe3ff5a530afba6d9261de75dbed7a4a2f57bf887672f1a653766a8c60957f9cad06b4501c30d6a5d4
7
+ data.tar.gz: 8c20370fe8c1b20d91e3a96e66deefc6bbe9145ded75024999b363241c0a0029c3bb975fc65da40f28952e6d59f6fcf43c414f61d3dc2ac9ad9d452c5a6ce9d6
@@ -1,22 +1,39 @@
1
1
  module Uuidable
2
2
  COLUMN_NAME = :uuid
3
3
  COLUMN_TYPE = :binary
4
- COLUMN_OPTIONS = { limit: 36, null: false, index: true }.freeze
4
+ COLUMN_OPTIONS = { limit: 36, null: false }.freeze
5
+ INDEX_OPTIONS = { unique: true }.freeze
5
6
 
6
7
  # Module adds method to table definition
7
8
  module TableDefinition
8
9
  def uuid(opts = {})
9
- column COLUMN_NAME, COLUMN_TYPE, opts.merge(COLUMN_OPTIONS)
10
+ index_opts = opts.delete(:index)
11
+ column_name = opts.delete(:column_name) || COLUMN_NAME
12
+
13
+ column column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts)
14
+ index column_name, INDEX_OPTIONS.merge(index_opts) unless index_opts == false
10
15
  end
11
16
  end
12
17
 
13
18
  # Module adds method to alter table migration
14
19
  module Migration
15
20
  def add_uuid_column(table_name, opts = {})
16
- add_column table_name, COLUMN_NAME, COLUMN_TYPE, opts.merge(COLUMN_OPTIONS)
21
+ index_opts = opts.delete(:index)
22
+ column_name = opts.delete(:column_name) || COLUMN_NAME
23
+
24
+ add_column table_name, column_name, COLUMN_TYPE, COLUMN_OPTIONS.merge(opts)
25
+
26
+ add_uuid_index(index_opts.merge(column_name: column_name)) unless index_opts == false
27
+ end
28
+
29
+ def add_uuid_index(table_name, opts = {})
30
+ column_name = opts.delete(:column_name) || COLUMN_NAME
31
+
32
+ add_index table_name, column_name, INDEX_OPTIONS.merge(opts)
17
33
  end
18
34
  end
19
35
  end
36
+
20
37
  if defined? ActiveRecord::ConnectionAdapters::TableDefinition
21
38
  ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Uuidable::TableDefinition
22
39
  end
@@ -1,3 +1,3 @@
1
1
  module Uuidable
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uuidable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gnuskov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-05 00:00:00.000000000 Z
11
+ date: 2017-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.6.12
158
+ rubygems_version: 2.6.13
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Helps using uuid everywhere in routes instead of id for ActiveRecord models.