upknit 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36b93e53c0a99f134394333ccc3bc21e409adbe7
4
+ data.tar.gz: 0227d085fb4b67afd1b2047fcaea918a7d0993a8
5
+ SHA512:
6
+ metadata.gz: ac5601670b24225e1c03efe1d0bba347f63c7fb71c8d2be25086d7604680b0ad38e65e0cc51eacb300536cc76d51c382243667480e6bdb16ec3806492be0fdd8
7
+ data.tar.gz: 6cb3593354e3cf5891f5100c3cc1cbd4612c530342efcde8d8f9ff24171857b7d6f5d844b18ed8edcf7a399d917381693a42c9de4a954174be6344abb1bf2874
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 OZAWA Sakuro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Upknit
2
+
3
+ Adding this gem to a Rails application with PostgreSQL automatically enables UUID primary key.
4
+
5
+ ## Usage
6
+
7
+ Add this gem to your Rails application.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'upknit'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Internals
20
+
21
+ This gem does two things to enable UUID primary key.
22
+
23
+ 1. Enable PostgreSQL's extension for calculation of UUID(v4).
24
+ 2. Configure generators to use UUID as primary key for newly generated tables.
25
+
26
+ ## License
27
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ load 'rails/tasks/statistics.rake'
11
+
12
+ require 'bundler/gem_tasks'
13
+
14
+ load 'rspec/rails/tasks/rspec.rake'
15
+
16
+ Dir['lib/tasks/*.rake'].each(&method(:load))
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
5
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
6
+ # skip rubocop tasks
7
+ end
@@ -0,0 +1,8 @@
1
+ begin
2
+ require 'yard'
3
+ require 'yard/rake/yardoc_task'
4
+
5
+ YARD::Rake::YardocTask.new
6
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
7
+ # skip yard tasks
8
+ end
@@ -0,0 +1,38 @@
1
+ require 'active_record/connection_adapters/postgresql_adapter'
2
+
3
+ # An extension to {ActiveRecord::ConnectionAdapters::PostgresqlAdapter}.
4
+ #
5
+ # When included, this module adds two methods to support UUID extension
6
+ # * #enable_uuid
7
+ # * #uuid_extension
8
+ module Upknit
9
+ module ConnectionExtension
10
+ module PostgreSQL
11
+ # Enables a extension which adds UUID function to the system.
12
+ # @return [void]
13
+ def enable_uuid
14
+ enable_extension(uuid_extension)
15
+ end
16
+
17
+ # Returns the name of UUID extension which should be used in current connection.
18
+ # @return [String] Name of the extension
19
+ def uuid_extension
20
+ (UUID_EXTENSIONS & available_extensions).first
21
+ end
22
+
23
+ private
24
+
25
+ # UUID support extensions in desired order
26
+ # Note: Use of uuid-ossp for random UUID(v4) is discouraged
27
+ # https://www.postgresql.org/docs/9.6/static/uuid-ossp.html
28
+ UUID_EXTENSIONS = %w(pgcrypto uuid-ossp).freeze
29
+ private_constant :UUID_EXTENSIONS
30
+
31
+ def available_extensions
32
+ exec_query('SELECT Name FROM pg_available_extensions').cast_values
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include Upknit::ConnectionExtension::PostgreSQL
@@ -0,0 +1 @@
1
+ require 'upknit/connection_extension/postgresql'
@@ -0,0 +1,18 @@
1
+ require 'active_record/tasks/postgresql_database_tasks'
2
+
3
+ module Upknit
4
+ module EnableUuidExtensionOnCreate
5
+ module PostgreSQL
6
+ def create(master_established=false)
7
+ super
8
+ connection.enable_uuid
9
+ end
10
+
11
+ def self.prepend(mod)
12
+ mod.extend(self)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ ActiveRecord::Tasks::PostgreSQLDatabaseTasks.prepend Upknit::EnableUuidExtensionOnCreate::PostgreSQL
@@ -0,0 +1 @@
1
+ require 'upknit/enable_uuid_extension_on_create/postgresql'
@@ -0,0 +1,8 @@
1
+ module Upknit
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
5
+
6
+ require 'upknit/connection_extension'
7
+ require 'upknit/enable_uuid_extension_on_create'
8
+ require 'upknit/set_default_primary_key_to_uuid'
@@ -0,0 +1,28 @@
1
+ require 'active_support/concern'
2
+ require 'upknit/connection_extension'
3
+
4
+ module Upknit
5
+ module SetDefaultPrimaryKeyToUuid
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ initializer 'upknit.set_default_primary_key_to_uuid', after: :load_config_initializers do
10
+ ActiveRecord::Base.establish_connection
11
+ uuid_extension = ActiveRecord::Base.connection&.uuid_extension
12
+ config.app_generators do |g|
13
+ case uuid_extension
14
+ when 'pgcrypto'
15
+ g.orm :active_record, primary_key_type: :uuid
16
+ when 'uuid-ossp'
17
+ g.orm :active_record, primary_key_type: 'uuid, default: -> { "uuid_generate_v4()" }'
18
+ else
19
+ $stderr.ptus 'upknit gem is installed, but UUUID is not supported'
20
+ # UUID not supported
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ Upknit::Engine.include Upknit::SetDefaultPrimaryKeyToUuid
@@ -0,0 +1,3 @@
1
+ module Upknit
2
+ VERSION = '0.9.1'.freeze
3
+ end
data/lib/upknit.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'upknit/engine'
2
+
3
+ module Upknit
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: upknit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - OZAWA Sakuro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: kramdown
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |
112
+ This rails engine configures necessary settings to enable native UUID primary key
113
+ in rails + postgresql environment.
114
+ email:
115
+ - sakuro@2238club.org
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - MIT-LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/tasks/rubocop.rake
124
+ - lib/tasks/yard.rake
125
+ - lib/upknit.rb
126
+ - lib/upknit/connection_extension.rb
127
+ - lib/upknit/connection_extension/postgresql.rb
128
+ - lib/upknit/enable_uuid_extension_on_create.rb
129
+ - lib/upknit/enable_uuid_extension_on_create/postgresql.rb
130
+ - lib/upknit/engine.rb
131
+ - lib/upknit/set_default_primary_key_to_uuid.rb
132
+ - lib/upknit/version.rb
133
+ homepage: https://github.com/sakuro/upknit
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.11
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: UUID primary key enabler for rails.
157
+ test_files: []