multi_ar 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/multi_ar/database.rb +3 -0
- data/lib/multi_ar/interface.rb +26 -28
- data/lib/multi_ar/rake/ext.rb +1 -0
- data/lib/multi_ar/rake/migration_generator.rb +2 -0
- data/lib/multi_ar/rake/tasks.rb +1 -0
- data/lib/multi_ar/version.rb +1 -1
- data/lib/multi_ar.rb +5 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c01f5dbedaf04057f1edbf8402963aa6500ef0d3
|
4
|
+
data.tar.gz: f97e3417a9cdfe73af3549008cc47df54055e472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38d0da40c514cdd74d850d0b2b7116b9707f6cf7f66d507e112848592cd5ecc3f83d495036aa09e518045471608a31a5b6934ade11dd584360fcfd4bfe11f6da
|
7
|
+
data.tar.gz: 663af5abc03f337a16ad458817ceb2fbe8cdf12b9514d5ef008861e6a668c85c959ad58bbe7d7ac9a840511afbb88fa6b176df65b3fba1478522a92397808fc1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/multi_ar/database.rb
CHANGED
data/lib/multi_ar/interface.rb
CHANGED
@@ -9,24 +9,21 @@ module MultiAR
|
|
9
9
|
|
10
10
|
# An utility to ease creation of executable using multi database ActiveRecord
|
11
11
|
# through command line interface.
|
12
|
-
#
|
13
|
-
# Usage:
|
14
|
-
#
|
15
|
-
# TODO: write usage
|
16
|
-
# TODO: mention this usage in README.md too
|
17
12
|
class Interface
|
18
13
|
|
19
14
|
# Options that will be enabled.
|
20
15
|
#
|
21
16
|
# Options supported by this system are:
|
22
|
-
# - config
|
23
|
-
# - db_config
|
24
|
-
# - dry
|
25
|
-
# - environment
|
26
|
-
# - verbose
|
27
|
-
# - databases
|
17
|
+
# - config # `true` or `String`
|
18
|
+
# - db_config # `true` or `String`
|
19
|
+
# - dry # boolean
|
20
|
+
# - environment # `true` or `String`
|
21
|
+
# - verbose # boolean
|
22
|
+
# - databases # `true` or `Array`
|
28
23
|
#
|
29
|
-
#
|
24
|
+
# If value is `true`, an option will be added to CLI interface. If the value is something else, the option will be populated by this value instead.
|
25
|
+
#
|
26
|
+
# `environment` option is enabled by default, rest are disabled.
|
30
27
|
attr_accessor :options
|
31
28
|
|
32
29
|
# Version shown with --version flag on CLI
|
@@ -35,9 +32,6 @@ module MultiAR
|
|
35
32
|
# Description of the application show in usage texts on CLI
|
36
33
|
attr_accessor :description
|
37
34
|
|
38
|
-
# Array of databases that will be used insted if none have not been passed through CLI.
|
39
|
-
attr_accessor :databases
|
40
|
-
|
41
35
|
# If set to true, migration framework and other Rake related functionality will be enabled.
|
42
36
|
attr_accessor :migration_framework
|
43
37
|
|
@@ -51,7 +45,7 @@ module MultiAR
|
|
51
45
|
#
|
52
46
|
# This is used in --init.
|
53
47
|
#
|
54
|
-
#
|
48
|
+
# @todo what for this actually is? Write an example or just tell what for this should be used.
|
55
49
|
attr_accessor :dependencies
|
56
50
|
|
57
51
|
def initialize
|
@@ -61,19 +55,19 @@ module MultiAR
|
|
61
55
|
end
|
62
56
|
|
63
57
|
# @note Consumes ARGV, create copy of it if you need it for something.
|
64
|
-
#
|
58
|
+
# @todo hardcode shorthands
|
65
59
|
def cli
|
66
60
|
p = Trollop::Parser.new
|
67
61
|
p.version @version if @version
|
68
62
|
p.banner @description if @description
|
69
63
|
p.opt "init", "Create stub environment with configuration and database.yaml", type: :string
|
70
|
-
p.opt "databases", "List of databases to perform operations", type: :strings if @options["databases"]
|
71
|
-
p.opt "db_config", "Path to database config file", type: :string, default: "config/database.yaml" if @options["db_config"]
|
72
|
-
p.opt "config", "Path to MultiAR framework config file", type: :string, default: "config/settings.yaml" if @options["config"]
|
73
|
-
p.opt "dry", "Run the program without doing anything. Useful for debugging with -v", type: :flag if @options["dry"]
|
64
|
+
p.opt "databases", "List of databases to perform operations", type: :strings if @options["databases"] == true
|
65
|
+
p.opt "db_config", "Path to database config file", type: :string, default: "config/database.yaml" if @options["db_config"] == true
|
66
|
+
p.opt "config", "Path to MultiAR framework config file", type: :string, default: "config/settings.yaml" if @options["config"] == true
|
67
|
+
p.opt "dry", "Run the program without doing anything. Useful for debugging with -v", type: :flag if @options["dry"] == true
|
74
68
|
p.opt "environment", "The environment to use. Corresponds to database config name " +
|
75
69
|
"(environment for foo_development is “development”).", type: :string, default: "development"
|
76
|
-
p.opt "verbose", "Be verbose", type: :flag if @options["verbose"]
|
70
|
+
p.opt "verbose", "Be verbose", type: :flag if @options["verbose"] == true
|
77
71
|
|
78
72
|
if @migration_framework == true
|
79
73
|
p.opt "all_rake_tasks", "List all Rake tasks, not only commented ones", short: "A", type: :flag
|
@@ -99,10 +93,16 @@ module MultiAR
|
|
99
93
|
result
|
100
94
|
end
|
101
95
|
|
96
|
+
@options.each do |key, value|
|
97
|
+
next if value == true
|
98
|
+
# Not bothering to do checks as we just take the intended values, and not looping the array otherwise
|
99
|
+
opts[key] = value
|
100
|
+
end
|
101
|
+
|
102
102
|
bootstrap opts if opts["init"] # Bootstrap will exit after execution; in that case nothing after this will be run.
|
103
103
|
|
104
104
|
raise "--config must be path to valid file" if @options["config"] and not File.exist? opts["config"]
|
105
|
-
raise "config
|
105
|
+
raise "Database config #{opts["db_config"]} seems to be missing" if @options["db_config"] and not File.exist? opts["db_config"]
|
106
106
|
|
107
107
|
@opts = opts
|
108
108
|
|
@@ -110,7 +110,7 @@ module MultiAR
|
|
110
110
|
|
111
111
|
# Then run Rake tasks as requested
|
112
112
|
|
113
|
-
return if not @migration_framework # TODO: I think there should be much more fine grained control for this
|
113
|
+
return opts if not @migration_framework # TODO: I think there should be much more fine grained control for this
|
114
114
|
|
115
115
|
if opts["tasks"] || opts["all_rake_tasks"]
|
116
116
|
@multi_ar.list_tasks all_rake_tasks: opts["all_rake_tasks"]
|
@@ -132,14 +132,12 @@ module MultiAR
|
|
132
132
|
@multi_ar = MultiAR.new config: @opts["config"],
|
133
133
|
databases: @opts["databases"],
|
134
134
|
db_config: @opts["db_config"],
|
135
|
-
environment: @opts["environment"]
|
136
|
-
|
137
|
-
MultiAR.add_migration_dir @opts["migration_dir"]
|
135
|
+
environment: @opts["environment"],
|
136
|
+
migration_dirs: [ @opts["migration_dir"] ]
|
138
137
|
end
|
139
138
|
|
140
139
|
# @note This method will always quit the application or raise another exception for errors. Catch SystemExit if that’s not good for you.
|
141
140
|
def bootstrap opts
|
142
|
-
opts["databases"] ||= @databases
|
143
141
|
raise "--databases must be given when bootstrapping." unless opts["databases"]
|
144
142
|
raise "#{opts["init"]} already exists" if File.exist? opts["init"]
|
145
143
|
|
data/lib/multi_ar/rake/ext.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require "rails/generators/active_record/migration/migration_generator"
|
3
3
|
require "active_record/tasks/database_tasks"
|
4
4
|
|
5
|
+
|
6
|
+
# @api private
|
5
7
|
module ActiveRecordMigrations
|
6
8
|
module Generators
|
7
9
|
class MigrationGenerator < ::ActiveRecord::Generators::MigrationGenerator
|
data/lib/multi_ar/rake/tasks.rb
CHANGED
data/lib/multi_ar/version.rb
CHANGED
data/lib/multi_ar.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "multi_ar/rake/tasks"
|
|
5
5
|
|
6
6
|
require_relative "multi_ar/database"
|
7
7
|
|
8
|
+
# Main module.
|
8
9
|
module MultiAR
|
9
10
|
|
10
11
|
# Base of MultiAR gem.
|
@@ -16,6 +17,8 @@ module MultiAR
|
|
16
17
|
attr_reader :db_config
|
17
18
|
attr_reader :environment
|
18
19
|
|
20
|
+
# @api private
|
21
|
+
# This will always be overridden, when MultiAR is initialized. Don’t try to do any funny logic with this.
|
19
22
|
@@migration_dirs = []
|
20
23
|
|
21
24
|
class << self
|
@@ -26,7 +29,7 @@ module MultiAR
|
|
26
29
|
|
27
30
|
# @param databases array of available databases
|
28
31
|
# @todo config file is overriding parameters passed here... I think it should be other way around, but need more custom logic for that :/
|
29
|
-
def initialize databases:, environment: "development", config: "config/multi_ar.yaml", db_config: "config/database.yaml"
|
32
|
+
def initialize databases:, environment: "development", config: "config/multi_ar.yaml", db_config: "config/database.yaml", migration_dirs: []
|
30
33
|
|
31
34
|
# first load config
|
32
35
|
if not config.nil? and File.exist? config
|
@@ -45,6 +48,7 @@ module MultiAR
|
|
45
48
|
@databases = databases
|
46
49
|
@db_config = db_config
|
47
50
|
@environment = environment
|
51
|
+
@@migration_dirs = migration_dirs unless migration_dirs.empty? # This takes care of that it will only be overridden if there is any given values, making default configs work
|
48
52
|
|
49
53
|
Database.initialize db_config: db_config
|
50
54
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samu Voutilainen
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
Ws73WZ+F+DOnfopIMUaeYUzKyUG+59p17ls//xzTouiLjcC9ee5ZaC9e+TzYsp4t
|
30
30
|
ofnwRrqEHVW+zRWs/VIwm70F2Jnl5eSc3MjyhpWIC0eGFXtBY1XYCrHeCdQ=
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2015-10-
|
32
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: trollop
|
metadata.gz.sig
CHANGED
Binary file
|