uuids 1.4.0 → 1.4.1
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/.rubocop.yml +1 -0
- data/bin/uuids +2 -2
- data/lib/generators/install/copy_migration.rb +104 -0
- data/lib/generators/install.rb +92 -0
- data/lib/generators.rb +10 -0
- data/lib/uuids/version.rb +1 -2
- data/lib/uuids.rb +6 -3
- data/spec/{uuids/models → app/models/uuids}/uuid_spec.rb +0 -0
- data/spec/bin/uuids_spec.rb +52 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/lib/generators/install/copy_migration_spec.rb +66 -0
- data/spec/lib/generators/install_spec.rb +73 -0
- data/spec/{uuids/lib → lib/uuids}/base_spec.rb +0 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/spec_helper_dev.rb +15 -0
- data/spec/{initializers → support/all/config}/focus.rb +0 -0
- data/spec/{initializers → support/all/config}/garbage_collection.rb +0 -0
- data/spec/{initializers → support/all/config}/random_order.rb +0 -0
- data/spec/{initializers → support/all/config}/rspec.rb +0 -0
- data/spec/{initializers → support/development/config}/sandbox.rb +1 -1
- data/spec/support/development/config/timecop.rb +1 -0
- data/spec/support/{capture.rb → development/helpers/capture.rb} +0 -0
- data/spec/support/development/helpers/migrations.rb +6 -0
- data/spec/support/{sandbox.rb → development/helpers/sandbox.rb} +1 -16
- data/spec/support/development/matchers/migrations.rb +15 -0
- data/spec/support/development/matchers/sandbox.rb +14 -0
- data/spec/{initializers → support/runtime/config}/database_cleaner.rb +0 -0
- data/spec/{initializers → support/runtime/config}/factory_girl.rb +0 -0
- data/spec/{initializers → support/runtime/config}/i18n.rb +0 -0
- data/spec/{factories → support/runtime/factories}/records.rb +0 -0
- data/spec/{factories → support/runtime/factories}/uuids.rb +0 -0
- metadata +68 -47
- data/lib/uuids/generators/install/migration.rb +0 -62
- data/lib/uuids/generators/install.rb +0 -84
- data/spec/initializers/migrations.rb +0 -3
- data/spec/support/migrations.rb +0 -16
- data/spec/uuids/cli/install_spec.rb +0 -49
- data/spec/uuids/lib/generators/install/migration_spec.rb +0 -41
- data/spec/uuids/lib/generators/install_spec.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da4310e0513240c73c5f30d4d04fe9806271af8
|
4
|
+
data.tar.gz: 4a0f7b2b9b9a141ad21e76b1d0f44cfc6fec9b41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fa00c4678aee17d4d0ceef8da2ec8c2019e4363107ef1ba772f9ca89daa99fae98a1aaf49e887259a716994a68b55364abd05bc9be2a5f3b898bb6b04955756
|
7
|
+
data.tar.gz: a2eb9c7475f5ccce7d5d1cb4ae45054ef3e9c9400585e28b10060135c1d8dfac8d39cd7e2f9ca526043aa64915c786493456b879ed76fe8515f69d6ca9f508be
|
data/.rubocop.yml
CHANGED
data/bin/uuids
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative "../install"
|
3
|
+
|
4
|
+
module Generators
|
5
|
+
class Install
|
6
|
+
|
7
|
+
# Description for migration to copy.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# copy = CopyMigration.new(
|
12
|
+
# gemname: "uuids",
|
13
|
+
# source_root: "/",
|
14
|
+
# source_file: "/db/migrate/20141016112506_create_uuids_uuids.rb",
|
15
|
+
# target_root: "/items",
|
16
|
+
# target_dir: "db/migrate"
|
17
|
+
# )
|
18
|
+
#
|
19
|
+
# copy.source
|
20
|
+
# # => "/db/migrate/20141016112506_create_uuids_uuids.rb"
|
21
|
+
# copy.target
|
22
|
+
# # => "/db/migrate/20150101000001_create_uuids_uuids.uuids.rb"
|
23
|
+
# copy.content
|
24
|
+
# # => returns uuids content.
|
25
|
+
# copy.created?
|
26
|
+
# # => returns true after the first copy created with any timestamp.
|
27
|
+
#
|
28
|
+
class CopyMigration
|
29
|
+
|
30
|
+
# Initialized parameters.
|
31
|
+
attr_reader(
|
32
|
+
:gemname, :source_root, :source_file, :target_root, :target_dir
|
33
|
+
)
|
34
|
+
|
35
|
+
# Instance initializer.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# CopyMigration.new(params)
|
39
|
+
#
|
40
|
+
# Params:
|
41
|
+
# <tt>:gemname</tt>:: the name of the gem.
|
42
|
+
# <tt>:source_root</tt>:: the uuids db/migrate folder path.
|
43
|
+
# <tt>:source_file</tt>:: full path to migration file.
|
44
|
+
# <tt>:target_root</tt>:: path to root of application to create copy.
|
45
|
+
# <tt>:target_dir</tt>:: a folder in application root for migrations.
|
46
|
+
#
|
47
|
+
# All params are required.
|
48
|
+
#
|
49
|
+
def initialize(params)
|
50
|
+
@gemname = params[:gemname]
|
51
|
+
@source_root = params[:source_root]
|
52
|
+
@source_file = params[:source_file]
|
53
|
+
@target_root = params[:target_root]
|
54
|
+
@target_dir = params[:target_dir]
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns a source path to the migration.
|
58
|
+
def source
|
59
|
+
filepath.relative_path_from(rootpath).to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns a target file name to copy the migration to.
|
63
|
+
def target
|
64
|
+
File.join(target_dir, "#{ timestamp }#{ suffix }")
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the migration content.
|
68
|
+
def content
|
69
|
+
File.read filepath
|
70
|
+
end
|
71
|
+
|
72
|
+
# Checks if a copy already created.
|
73
|
+
def created?
|
74
|
+
search != []
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def filepath
|
80
|
+
@filepath ||= Pathname.new(source_file)
|
81
|
+
end
|
82
|
+
|
83
|
+
def suffix
|
84
|
+
@suffix ||= "#{ basename }.#{ gemname }.rb"
|
85
|
+
end
|
86
|
+
|
87
|
+
def search
|
88
|
+
Dir[File.join(target_root, target_dir, "*#{ suffix }")]
|
89
|
+
end
|
90
|
+
|
91
|
+
def rootpath
|
92
|
+
Pathname.new(source_root)
|
93
|
+
end
|
94
|
+
|
95
|
+
def timestamp
|
96
|
+
@timestamp ||= Time.now.utc.strftime "%Y%m%d%H%M%S"
|
97
|
+
end
|
98
|
+
|
99
|
+
def basename
|
100
|
+
File.basename(source_file, ".rb")[14..-1]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
# An installer for the `uuids` gem.
|
6
|
+
# Copies module migration into an external project.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# installer = Generators::Install.start [], { dummy: true }
|
10
|
+
# # => creates `spec/dummy/db/migrage/{timestamp}_uuids_uuids.uuids.rb
|
11
|
+
#
|
12
|
+
# Options:
|
13
|
+
# <tt>dummy:</tt> (optional, boolean, default: false)
|
14
|
+
# ... flag to copy migrations to a dummy app. If not set, the migration
|
15
|
+
# will be added to the root `db/migrate` folder.
|
16
|
+
#
|
17
|
+
# Adds the "uuids" gem's migration to a module that uses the gem.
|
18
|
+
#
|
19
|
+
class Install < Thor::Group
|
20
|
+
include Thor::Actions
|
21
|
+
|
22
|
+
# Root for db migrations to be copied.
|
23
|
+
source_root File.expand_path "../../../db/migrate", __FILE__
|
24
|
+
namespace :install
|
25
|
+
|
26
|
+
class_option(
|
27
|
+
:dummy,
|
28
|
+
aliases: "-d",
|
29
|
+
default: false,
|
30
|
+
desc: "Copy migrations to dummy (`spec/dummy/db/migrate`) folder.",
|
31
|
+
required: false,
|
32
|
+
type: :boolean
|
33
|
+
)
|
34
|
+
|
35
|
+
class_option(
|
36
|
+
:folder,
|
37
|
+
aliases: "-f",
|
38
|
+
desc: "A folder to copy migrations to (`given_folder/db/migrate`).",
|
39
|
+
required: false,
|
40
|
+
type: :string
|
41
|
+
)
|
42
|
+
|
43
|
+
# Creates a folder for migrations.
|
44
|
+
def prepare_folder
|
45
|
+
empty_directory dir, skip: true
|
46
|
+
end
|
47
|
+
|
48
|
+
# Copies migrations to proper folder
|
49
|
+
def copy_migrations
|
50
|
+
copies.each do |copy|
|
51
|
+
copy_file copy.source, copy.target, copy.content unless copy.created?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def source_root
|
58
|
+
File.expand_path "../../../db/migrate", __FILE__
|
59
|
+
end
|
60
|
+
|
61
|
+
def dir
|
62
|
+
@dir ||= "#{ folder || dummy || "" }db/migrate/"
|
63
|
+
end
|
64
|
+
|
65
|
+
def folder
|
66
|
+
@folder ||= begin
|
67
|
+
folder = options["folder"]
|
68
|
+
folder ? "#{ folder }/" : nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def dummy
|
73
|
+
@dummy ||= "spec/dummy/" if options["dummy"]
|
74
|
+
end
|
75
|
+
|
76
|
+
def sources
|
77
|
+
@sources ||= Dir[File.expand_path("*.rb", source_root)]
|
78
|
+
end
|
79
|
+
|
80
|
+
def copies
|
81
|
+
@copies ||= sources.map do |file|
|
82
|
+
CopyMigration.new(
|
83
|
+
gemname: "uuids",
|
84
|
+
source_root: source_root,
|
85
|
+
source_file: file,
|
86
|
+
target_root: destination_root,
|
87
|
+
target_dir: dir
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/generators.rb
ADDED
data/lib/uuids/version.rb
CHANGED
data/lib/uuids.rb
CHANGED
@@ -3,8 +3,11 @@ require "active_record"
|
|
3
3
|
require "i18n"
|
4
4
|
require "securerandom"
|
5
5
|
|
6
|
-
#
|
6
|
+
# `uuids` gem content.
|
7
7
|
root = File.expand_path "../..", __FILE__
|
8
|
-
|
9
|
-
|
8
|
+
Dir[File.join(root, "lib/uuids/**/*.rb")].each { |f| require f }
|
9
|
+
Dir[File.join(root, "app/**/*.rb")].each { |f| require f }
|
10
|
+
|
11
|
+
# Namespace for `uuids` gem code.
|
12
|
+
module Uuids
|
10
13
|
end
|
File without changes
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper_dev"
|
3
|
+
|
4
|
+
describe "$ uuids", :sandbox do
|
5
|
+
|
6
|
+
let(:files_in_sandbox) { Dir["#{ sandbox }/**/*.*"] }
|
7
|
+
|
8
|
+
describe "install" do
|
9
|
+
|
10
|
+
context "without options" do
|
11
|
+
|
12
|
+
let!(:dir) { "#{ sandbox }/db/migrate" }
|
13
|
+
before { run_in_sandbox "uuids install" }
|
14
|
+
|
15
|
+
it "copies migrations to 'db/migrate'" do
|
16
|
+
migrations.each { |file| expect(dir).to have_migration_from file }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "doesn't add other files" do
|
20
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "-d" do
|
25
|
+
|
26
|
+
let!(:dir) { "#{ sandbox }/spec/dummy/db/migrate" }
|
27
|
+
before { run_in_sandbox "uuids install -d" }
|
28
|
+
|
29
|
+
it "copies migrations to 'spec/dummy/db/migrate'" do
|
30
|
+
migrations.each { |file| expect(dir).to have_migration_from file }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "doesn't add other files" do
|
34
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "-f folder" do
|
39
|
+
|
40
|
+
let!(:dir) { "#{ sandbox }/folder/db/migrate" }
|
41
|
+
before { run_in_sandbox "uuids install -f folder" }
|
42
|
+
|
43
|
+
it "copies migrations to 'some_path/db/migrate'" do
|
44
|
+
migrations.each { |file| expect(dir).to have_migration_from file }
|
45
|
+
end
|
46
|
+
|
47
|
+
it "doesn't add other files" do
|
48
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper_dev"
|
3
|
+
|
4
|
+
module Generators
|
5
|
+
class Install
|
6
|
+
describe CopyMigration, :sandbox do
|
7
|
+
|
8
|
+
let(:filename) { "20140101010101_create_items_items" }
|
9
|
+
let(:filepath) { "#{ sandbox }/#{ filename }.rb" }
|
10
|
+
let(:content) { "some content" }
|
11
|
+
let(:params) do
|
12
|
+
{
|
13
|
+
gemname: "uuids",
|
14
|
+
source_root: sandbox,
|
15
|
+
source_file: filepath,
|
16
|
+
target_root: sandbox,
|
17
|
+
target_dir: "db/migrate"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
before { File.write filepath, content }
|
22
|
+
subject { CopyMigration.new params }
|
23
|
+
|
24
|
+
describe "#source" do
|
25
|
+
|
26
|
+
it "returns migrations source" do
|
27
|
+
expect(subject.source).to eq("#{ filename }.rb")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#target" do
|
32
|
+
|
33
|
+
let(:regexp) do
|
34
|
+
Regexp.new "db/migrate/\\d{14}_create_items_items[.]uuids[.]rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns the name of migration target" do
|
38
|
+
expect(subject.target).to match(regexp)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#content" do
|
43
|
+
|
44
|
+
it "returns the migration content" do
|
45
|
+
expect(subject.content).to eq(content)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#created?" do
|
50
|
+
|
51
|
+
let(:folder) { File.join sandbox, "db", "migrate" }
|
52
|
+
let(:copy) { File.join(folder, "#{ filename }.uuids.rb") }
|
53
|
+
|
54
|
+
it "returns false before migration copy created" do
|
55
|
+
expect(subject).not_to be_created
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns true after migration copy created" do
|
59
|
+
FileUtils.mkdir_p folder
|
60
|
+
File.write copy, content
|
61
|
+
expect(subject).to be_created
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper_dev"
|
3
|
+
|
4
|
+
module Generators
|
5
|
+
describe Install, :sandbox do
|
6
|
+
|
7
|
+
describe "#invoke_all" do
|
8
|
+
|
9
|
+
def run_with_options(options = {})
|
10
|
+
try_in_sandbox do
|
11
|
+
subject = Install.new [], options
|
12
|
+
subject.invoke_all
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:files_in_sandbox) { Dir["#{ sandbox }/**/*.*"] }
|
17
|
+
|
18
|
+
context "without options" do
|
19
|
+
|
20
|
+
let!(:dir) { "#{ sandbox }/db/migrate" }
|
21
|
+
before { run_with_options }
|
22
|
+
|
23
|
+
it "copies migrations to 'db/migrate'" do
|
24
|
+
migrations.each { |file| expect(dir).to have_migration_from file }
|
25
|
+
end
|
26
|
+
|
27
|
+
it "doesn't add other files" do
|
28
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "dummy: true" do
|
33
|
+
|
34
|
+
let!(:dir) { "#{ sandbox }/spec/dummy/db/migrate" }
|
35
|
+
before { run_with_options dummy: true }
|
36
|
+
|
37
|
+
it "copies migrations to 'spec/dummy/db/migrate'" do
|
38
|
+
migrations.each { |file| expect(dir).to have_migration_from file }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "doesn't add other files" do
|
42
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "folder: 'folder'" do
|
47
|
+
|
48
|
+
let!(:dir) { "#{ sandbox }/folder/db/migrate" }
|
49
|
+
before { run_with_options folder: "folder" }
|
50
|
+
|
51
|
+
it "copies migrations to 'some_path/db/migrate'" do
|
52
|
+
migrations.each { |file| expect(dir).to have_migration_from file }
|
53
|
+
end
|
54
|
+
|
55
|
+
it "doesn't add other files" do
|
56
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "if a migration is already added" do
|
61
|
+
|
62
|
+
before do
|
63
|
+
run_with_options
|
64
|
+
Timecop.travel(Time.now + 10) { run_with_options }
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't copy it again" do
|
68
|
+
expect(files_in_sandbox.count).to eq migrations.count
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
require "coveralls"
|
3
3
|
Coveralls.wear! "rails"
|
4
4
|
|
5
|
-
# Loads dummy
|
5
|
+
# Loads dummy app.
|
6
6
|
require_relative "dummy/lib/dummy"
|
7
7
|
|
8
|
-
# Loads
|
9
|
-
%w(
|
10
|
-
|
8
|
+
# Loads support files for runtime tests.
|
9
|
+
%w(runtime all).each do |env|
|
10
|
+
support = File.expand_path "../support/#{ env }/**/*.rb", __FILE__
|
11
|
+
Dir[support].each { |f| require f }
|
11
12
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Helper for testing dev environment features (generators) outside of
|
2
|
+
# applications (both lib/uuids and dummy).
|
3
|
+
|
4
|
+
# Checks code
|
5
|
+
require "coveralls"
|
6
|
+
Coveralls.wear! "rails"
|
7
|
+
|
8
|
+
# Loads generators.
|
9
|
+
require_relative "../lib/generators"
|
10
|
+
|
11
|
+
# Loads support files for development tests.
|
12
|
+
%w(development all).each do |env|
|
13
|
+
support = File.expand_path "../support/#{ env }/**/*.rb", __FILE__
|
14
|
+
Dir[support].each { |f| require f }
|
15
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require "timecop"
|
File without changes
|
@@ -2,7 +2,7 @@ require_relative "capture"
|
|
2
2
|
|
3
3
|
# Path to the `tmp/sandbox`.
|
4
4
|
def sandbox
|
5
|
-
@sandbox ||= File.expand_path "
|
5
|
+
@sandbox ||= File.expand_path "../../../../../tmp/sandbox", __FILE__
|
6
6
|
end
|
7
7
|
|
8
8
|
# Clears `tmp/sandbox`.
|
@@ -27,18 +27,3 @@ def run_in_sandbox(command)
|
|
27
27
|
try_in_sandbox { result = `#{ command }` }
|
28
28
|
result
|
29
29
|
end
|
30
|
-
|
31
|
-
# Checks if a file with given name exists in the sandbox.
|
32
|
-
#
|
33
|
-
# @example
|
34
|
-
#
|
35
|
-
# it "adds file.rb", :sandbox do
|
36
|
-
# expect("file.rb").to present_in_sandbox
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
RSpec::Matchers.define :present_in_sandbox do
|
40
|
-
match do |filename|
|
41
|
-
file = File.join(sandbox, filename)
|
42
|
-
expect(File.exist? file).to be_truthy
|
43
|
-
end
|
44
|
-
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Checks if a directory has a migration from given source file.
|
2
|
+
RSpec::Matchers.define :have_migration_from do |source|
|
3
|
+
match do |dir|
|
4
|
+
|
5
|
+
# Search file that matches source with any timestamp.
|
6
|
+
basename = File.basename(source, ".rb")[14..-1]
|
7
|
+
sample = "*#{ basename }.uuids.rb"
|
8
|
+
search = File.join(dir, sample)
|
9
|
+
file = Dir[search].first
|
10
|
+
|
11
|
+
# Check the file exists and has required content.
|
12
|
+
expect(file).not_to be_nil
|
13
|
+
expect(File.read file).to eq File.read source
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Checks if a file with given name exists in the sandbox.
|
2
|
+
#
|
3
|
+
# @example
|
4
|
+
#
|
5
|
+
# it "adds file.rb", :sandbox do
|
6
|
+
# expect("file.rb").to present_in_sandbox
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
RSpec::Matchers.define :present_in_sandbox do
|
10
|
+
match do |filename|
|
11
|
+
file = File.join(sandbox, filename)
|
12
|
+
expect(File.exist? file).to be_truthy
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :
|
47
|
+
version: '0.19'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.19'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: database_cleaner
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '10.3'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: timecop
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.7'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.7'
|
167
181
|
description: AR model to store uuids assigned to various resources. It is expected
|
168
182
|
a resource can be identified by many UUIDs.
|
169
183
|
email: andrew.kozin@gmail.com
|
@@ -183,12 +197,15 @@ files:
|
|
183
197
|
- config/locales/en.yml
|
184
198
|
- config/locales/ru.yml
|
185
199
|
- db/migrate/20141016112506_create_uuids_uuids.rb
|
200
|
+
- lib/generators.rb
|
201
|
+
- lib/generators/install.rb
|
202
|
+
- lib/generators/install/copy_migration.rb
|
186
203
|
- lib/uuids.rb
|
187
204
|
- lib/uuids/base.rb
|
188
205
|
- lib/uuids/base/has_uuids.rb
|
189
|
-
- lib/uuids/generators/install.rb
|
190
|
-
- lib/uuids/generators/install/migration.rb
|
191
206
|
- lib/uuids/version.rb
|
207
|
+
- spec/app/models/uuids/uuid_spec.rb
|
208
|
+
- spec/bin/uuids_spec.rb
|
192
209
|
- spec/dummy/Rakefile
|
193
210
|
- spec/dummy/app/models/city.rb
|
194
211
|
- spec/dummy/app/models/record.rb
|
@@ -202,26 +219,27 @@ files:
|
|
202
219
|
- spec/dummy/db/schema.rb
|
203
220
|
- spec/dummy/db/test.sqlite3
|
204
221
|
- spec/dummy/lib/dummy.rb
|
205
|
-
- spec/
|
206
|
-
- spec/
|
207
|
-
- spec/
|
208
|
-
- spec/initializers/factory_girl.rb
|
209
|
-
- spec/initializers/focus.rb
|
210
|
-
- spec/initializers/garbage_collection.rb
|
211
|
-
- spec/initializers/i18n.rb
|
212
|
-
- spec/initializers/migrations.rb
|
213
|
-
- spec/initializers/random_order.rb
|
214
|
-
- spec/initializers/rspec.rb
|
215
|
-
- spec/initializers/sandbox.rb
|
222
|
+
- spec/lib/generators/install/copy_migration_spec.rb
|
223
|
+
- spec/lib/generators/install_spec.rb
|
224
|
+
- spec/lib/uuids/base_spec.rb
|
216
225
|
- spec/spec_helper.rb
|
217
|
-
- spec/
|
218
|
-
- spec/support/
|
219
|
-
- spec/support/
|
220
|
-
- spec/
|
221
|
-
- spec/
|
222
|
-
- spec/
|
223
|
-
- spec/
|
224
|
-
- spec/
|
226
|
+
- spec/spec_helper_dev.rb
|
227
|
+
- spec/support/all/config/focus.rb
|
228
|
+
- spec/support/all/config/garbage_collection.rb
|
229
|
+
- spec/support/all/config/random_order.rb
|
230
|
+
- spec/support/all/config/rspec.rb
|
231
|
+
- spec/support/development/config/sandbox.rb
|
232
|
+
- spec/support/development/config/timecop.rb
|
233
|
+
- spec/support/development/helpers/capture.rb
|
234
|
+
- spec/support/development/helpers/migrations.rb
|
235
|
+
- spec/support/development/helpers/sandbox.rb
|
236
|
+
- spec/support/development/matchers/migrations.rb
|
237
|
+
- spec/support/development/matchers/sandbox.rb
|
238
|
+
- spec/support/runtime/config/database_cleaner.rb
|
239
|
+
- spec/support/runtime/config/factory_girl.rb
|
240
|
+
- spec/support/runtime/config/i18n.rb
|
241
|
+
- spec/support/runtime/factories/records.rb
|
242
|
+
- spec/support/runtime/factories/uuids.rb
|
225
243
|
homepage: https://github.com/nepalez/uuids
|
226
244
|
licenses:
|
227
245
|
- MIT
|
@@ -247,11 +265,7 @@ signing_key:
|
|
247
265
|
specification_version: 4
|
248
266
|
summary: UUIDs AR model.
|
249
267
|
test_files:
|
250
|
-
- spec/
|
251
|
-
- spec/uuids/models/uuid_spec.rb
|
252
|
-
- spec/uuids/lib/generators/install/migration_spec.rb
|
253
|
-
- spec/uuids/lib/generators/install_spec.rb
|
254
|
-
- spec/uuids/lib/base_spec.rb
|
268
|
+
- spec/spec_helper_dev.rb
|
255
269
|
- spec/spec_helper.rb
|
256
270
|
- spec/dummy/config/environment.rb
|
257
271
|
- spec/dummy/config/database.yml
|
@@ -266,20 +280,27 @@ test_files:
|
|
266
280
|
- spec/dummy/app/models/city.rb
|
267
281
|
- spec/dummy/lib/dummy.rb
|
268
282
|
- spec/dummy/Rakefile
|
269
|
-
- spec/
|
270
|
-
- spec/
|
271
|
-
- spec/
|
272
|
-
- spec/
|
273
|
-
- spec/
|
274
|
-
- spec/
|
275
|
-
- spec/
|
276
|
-
- spec/
|
277
|
-
- spec/
|
278
|
-
- spec/
|
279
|
-
- spec/
|
280
|
-
- spec/support/
|
281
|
-
- spec/support/
|
282
|
-
- spec/support/
|
283
|
+
- spec/app/models/uuids/uuid_spec.rb
|
284
|
+
- spec/lib/generators/install/copy_migration_spec.rb
|
285
|
+
- spec/lib/generators/install_spec.rb
|
286
|
+
- spec/lib/uuids/base_spec.rb
|
287
|
+
- spec/bin/uuids_spec.rb
|
288
|
+
- spec/support/development/config/timecop.rb
|
289
|
+
- spec/support/development/config/sandbox.rb
|
290
|
+
- spec/support/development/matchers/sandbox.rb
|
291
|
+
- spec/support/development/matchers/migrations.rb
|
292
|
+
- spec/support/development/helpers/capture.rb
|
293
|
+
- spec/support/development/helpers/sandbox.rb
|
294
|
+
- spec/support/development/helpers/migrations.rb
|
295
|
+
- spec/support/all/config/garbage_collection.rb
|
296
|
+
- spec/support/all/config/focus.rb
|
297
|
+
- spec/support/all/config/random_order.rb
|
298
|
+
- spec/support/all/config/rspec.rb
|
299
|
+
- spec/support/runtime/config/i18n.rb
|
300
|
+
- spec/support/runtime/config/factory_girl.rb
|
301
|
+
- spec/support/runtime/config/database_cleaner.rb
|
302
|
+
- spec/support/runtime/factories/uuids.rb
|
303
|
+
- spec/support/runtime/factories/records.rb
|
283
304
|
- Rakefile
|
284
305
|
- ".rubocop.yml"
|
285
306
|
has_rdoc:
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "../install"
|
3
|
-
|
4
|
-
module Uuids
|
5
|
-
module Generators
|
6
|
-
class Install
|
7
|
-
|
8
|
-
# Description for migration to copy.
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# migration = Migration.new(
|
12
|
-
# "/uuids/db/migrate/20141016112506_create_uuids_uuids.rb"
|
13
|
-
# )
|
14
|
-
# migration.source
|
15
|
-
# # => "/uuids/db/migrate/20141016112506_create_uuids_uuids.rb"
|
16
|
-
# migration.target
|
17
|
-
# # => "20150101000001_create_uuids_uuids.uuids.rb"
|
18
|
-
# migration.content
|
19
|
-
# # => returns uuids content.
|
20
|
-
#
|
21
|
-
class Migration
|
22
|
-
|
23
|
-
# A source file for migration.
|
24
|
-
attr_reader :source
|
25
|
-
|
26
|
-
# Initializes the migration from given source file.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# migration = Migration.new(
|
30
|
-
# "/uuids/db/migrate/20141016112506_create_uuids_uuids.rb"
|
31
|
-
# )
|
32
|
-
#
|
33
|
-
# Params:
|
34
|
-
# +source+:: A file name to initalize a migration from.
|
35
|
-
#
|
36
|
-
def initialize(source)
|
37
|
-
@source = source
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a target file name to copy the migration to.
|
41
|
-
def target
|
42
|
-
@target ||= "#{ timestamp }#{ basename }.uuids.rb"
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the migration content .
|
46
|
-
def content
|
47
|
-
@content ||= File.read source
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def timestamp
|
53
|
-
@timestamp ||= Time.now.utc.strftime "%Y%m%d%H%M%S"
|
54
|
-
end
|
55
|
-
|
56
|
-
def basename
|
57
|
-
@basename ||= File.basename(source, ".rb")[14..-1]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "thor"
|
3
|
-
|
4
|
-
module Uuids
|
5
|
-
|
6
|
-
# A namespace for +Uuids+ thor-based generators.
|
7
|
-
module Generators
|
8
|
-
|
9
|
-
# An installer for the module. Copies module migration to external gem.
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
# installer = Uuids::Generators::Install.start [], { dummy: true }
|
13
|
-
# # => creates `spec/dummy/db/migrage/{timestamp}_uuids_uuids.uuids.rb
|
14
|
-
#
|
15
|
-
# Options:
|
16
|
-
# <tt>dummy:</tt> (optional, boolean, default: false)
|
17
|
-
# ... flag to copy migrations to a dummy app. If not set, the migration
|
18
|
-
# will be added to the root `db/migrate` folder.
|
19
|
-
#
|
20
|
-
# Adds the "uuids" gem's migration to a module that uses the gem.
|
21
|
-
#
|
22
|
-
class Install < Thor::Group
|
23
|
-
include Thor::Actions
|
24
|
-
|
25
|
-
class_option(
|
26
|
-
:dummy,
|
27
|
-
aliases: "-d",
|
28
|
-
default: false,
|
29
|
-
desc: "Copy migrations to dummy (`spec/dummy/db/migrate`) folder.",
|
30
|
-
required: false,
|
31
|
-
type: :boolean
|
32
|
-
)
|
33
|
-
|
34
|
-
class_option(
|
35
|
-
:folder,
|
36
|
-
aliases: "-f",
|
37
|
-
desc: "A folder to copy migrations to (`given_folder/db/migrate`).",
|
38
|
-
required: false,
|
39
|
-
type: :string
|
40
|
-
)
|
41
|
-
|
42
|
-
# Creates a folder for migrations.
|
43
|
-
def prepare_folder
|
44
|
-
empty_directory dir, skip: true
|
45
|
-
end
|
46
|
-
|
47
|
-
# Copies migrations to proper folder
|
48
|
-
def copy_migrations
|
49
|
-
migrations.each do |migration|
|
50
|
-
FileUtils.copy_file(
|
51
|
-
migration.source,
|
52
|
-
"#{ destination_root }/#{ dir }#{ migration.target }",
|
53
|
-
migration.content
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def dir
|
61
|
-
@dir ||= "#{ folder || dummy || "" }db/migrate/"
|
62
|
-
end
|
63
|
-
|
64
|
-
def folder
|
65
|
-
@folder ||= begin
|
66
|
-
folder = options["folder"]
|
67
|
-
folder ? "#{ folder }/" : nil
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def dummy
|
72
|
-
@dummy ||= "spec/dummy/" if options["dummy"]
|
73
|
-
end
|
74
|
-
|
75
|
-
def sources
|
76
|
-
@sources ||= Dir[File.expand_path "../../db/migrate/*.rb"]
|
77
|
-
end
|
78
|
-
|
79
|
-
def migrations
|
80
|
-
@migrations ||= sources.map { |source| Migration.new source }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/spec/support/migrations.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# Returns a list of all module's migrations.
|
2
|
-
def migrations
|
3
|
-
@migrations ||= begin
|
4
|
-
Dir[File.expand_path "../../../db/migrate/*.rb", __FILE__]
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Checks if a directory has a migration from given source file.
|
9
|
-
RSpec::Matchers.define :have_migration_from do |source|
|
10
|
-
match do |dir|
|
11
|
-
search = "#{ dir }/*#{ File.basename(source, ".rb")[14..-1] }.uuids.rb"
|
12
|
-
file = Dir[search].first
|
13
|
-
expect(file).not_to be_nil
|
14
|
-
expect(File.read file).to eq File.read source
|
15
|
-
end
|
16
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe "$ uuids install", :sandbox do
|
5
|
-
|
6
|
-
let(:files_in_sandbox) { Dir["#{ sandbox }/**/*.*"] }
|
7
|
-
|
8
|
-
context "without options" do
|
9
|
-
|
10
|
-
let!(:dir) { "#{ sandbox }/db/migrate" }
|
11
|
-
before { run_in_sandbox "uuids install" }
|
12
|
-
|
13
|
-
it "copies migrations to 'db/migrate'" do
|
14
|
-
migrations.each { |file| expect(dir).to have_migration_from file }
|
15
|
-
end
|
16
|
-
|
17
|
-
it "doesn't add other files" do
|
18
|
-
expect(files_in_sandbox.count).to eq migrations.count
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "-d" do
|
23
|
-
|
24
|
-
let!(:dir) { "#{ sandbox }/spec/dummy/db/migrate" }
|
25
|
-
before { run_in_sandbox "uuids install -d" }
|
26
|
-
|
27
|
-
it "copies migrations to 'spec/dummy/db/migrate'" do
|
28
|
-
migrations.each { |file| expect(dir).to have_migration_from file }
|
29
|
-
end
|
30
|
-
|
31
|
-
it "doesn't add other files" do
|
32
|
-
expect(files_in_sandbox.count).to eq migrations.count
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "-f folder" do
|
37
|
-
|
38
|
-
let!(:dir) { "#{ sandbox }/folder/db/migrate" }
|
39
|
-
before { run_in_sandbox "uuids install -f folder" }
|
40
|
-
|
41
|
-
it "copies migrations to 'some_path/db/migrate'" do
|
42
|
-
migrations.each { |file| expect(dir).to have_migration_from file }
|
43
|
-
end
|
44
|
-
|
45
|
-
it "doesn't add other files" do
|
46
|
-
expect(files_in_sandbox.count).to eq migrations.count
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module Uuids
|
5
|
-
module Generators
|
6
|
-
class Install
|
7
|
-
describe Migration, :sandbox do
|
8
|
-
|
9
|
-
let(:filename) { "20140101010101_create_items_items" }
|
10
|
-
let(:filepath) { "#{ sandbox }/#{ filename }.rb" }
|
11
|
-
let(:content) { "some content" }
|
12
|
-
|
13
|
-
before { File.write filepath, content }
|
14
|
-
subject { Migration.new filepath }
|
15
|
-
|
16
|
-
describe "#source" do
|
17
|
-
|
18
|
-
it "returns migrations source" do
|
19
|
-
expect(subject.source).to eq filepath
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#target" do
|
24
|
-
|
25
|
-
it "returns the name of migration target" do
|
26
|
-
target = subject.target
|
27
|
-
expect(target[0..13]).to match(/\d{14}/)
|
28
|
-
expect(target[14..-1]).to eq "#{ filename[14..-1] }.uuids.rb"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#content" do
|
33
|
-
|
34
|
-
it "returns the migration content" do
|
35
|
-
expect(subject.content).to eq content
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
require "support/migrations"
|
4
|
-
|
5
|
-
module Uuids
|
6
|
-
module Generators
|
7
|
-
describe Install, :sandbox do
|
8
|
-
|
9
|
-
describe "#invoke_all" do
|
10
|
-
|
11
|
-
def run_with_options(options = {})
|
12
|
-
try_in_sandbox do
|
13
|
-
subject = Uuids::Generators::Install.new [], options
|
14
|
-
subject.invoke_all
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:files_in_sandbox) { Dir["#{ sandbox }/**/*.*"] }
|
19
|
-
|
20
|
-
context "without options" do
|
21
|
-
|
22
|
-
let!(:dir) { "#{ sandbox }/db/migrate" }
|
23
|
-
before { run_with_options }
|
24
|
-
|
25
|
-
it "copies migrations to 'db/migrate'" do
|
26
|
-
migrations.each { |file| expect(dir).to have_migration_from file }
|
27
|
-
end
|
28
|
-
|
29
|
-
it "doesn't add other files" do
|
30
|
-
expect(files_in_sandbox.count).to eq migrations.count
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "dummy: true" do
|
35
|
-
|
36
|
-
let!(:dir) { "#{ sandbox }/spec/dummy/db/migrate" }
|
37
|
-
before { run_with_options dummy: true }
|
38
|
-
|
39
|
-
it "copies migrations to 'spec/dummy/db/migrate'" do
|
40
|
-
migrations.each { |file| expect(dir).to have_migration_from file }
|
41
|
-
end
|
42
|
-
|
43
|
-
it "doesn't add other files" do
|
44
|
-
expect(files_in_sandbox.count).to eq migrations.count
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "folder: 'folder'" do
|
49
|
-
|
50
|
-
let!(:dir) { "#{ sandbox }/folder/db/migrate" }
|
51
|
-
before { run_with_options folder: "folder" }
|
52
|
-
|
53
|
-
it "copies migrations to 'some_path/db/migrate'" do
|
54
|
-
migrations.each { |file| expect(dir).to have_migration_from file }
|
55
|
-
end
|
56
|
-
|
57
|
-
it "doesn't add other files" do
|
58
|
-
expect(files_in_sandbox.count).to eq migrations.count
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|