exportr 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -1
- data/.rspec +2 -0
- data/Gemfile +2 -2
- data/LICENSE +18 -14
- data/README.md +28 -45
- data/Rakefile +8 -1
- data/config/exportr.yml +2 -0
- data/exportr.gemspec +17 -21
- data/ext/exportr/exportr.c +109 -0
- data/ext/exportr/extconf.rb +2 -0
- data/lib/exportr/version.rb +1 -1
- data/lib/exportr.rb +2 -2
- data/lib/generators/exportr/templates/exportr.yml +3 -3
- data/spec/exportr_spec.rb +19 -0
- data/spec/spec_helper.rb +11 -0
- metadata +68 -19
- data/bin/exportr +0 -5
- data/lib/exportr/base.rb +0 -38
- data/lib/exportr/command/core.rb +0 -52
- data/lib/exportr/command/helpers.rb +0 -30
- data/lib/exportr/command/messages.rb +0 -23
- data/lib/exportr/command.rb +0 -85
- data/lib/exportr/railtie.rb +0 -25
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
-
Copyright (
|
1
|
+
Copyright (c) 2013 richardcalahan
|
2
2
|
|
3
|
-
|
4
|
-
copy of this software and associated documentation files (the "Software"),
|
5
|
-
to deal in the Software without restriction, including without limitation
|
6
|
-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
7
|
-
and/or sell copies of the Software, and to permit persons to whom the Software
|
8
|
-
is furnished to do so, subject to the following conditions:
|
3
|
+
MIT License
|
9
4
|
|
10
|
-
|
11
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,73 +1,56 @@
|
|
1
|
-
|
1
|
+
## Exportr: An environment manager for Ruby development
|
2
2
|
|
3
|
-
|
3
|
+
### Description
|
4
4
|
|
5
|
-
|
5
|
+
Exportr is a simple environment variable manager for Ruby development. It reads key-value pairs from a yaml file and merges these pairs into Ruby's ENV hash when you `require 'exportr'`.
|
6
6
|
|
7
|
-
|
7
|
+
The yaml file must be in one of Exportr's predefined locations. The paths are relative to the present working directory of the Ruby process. (The list will grow as Exportr is tested in various frameworks.)
|
8
8
|
|
9
|
-
|
9
|
+
```
|
10
|
+
/exportr.yml
|
11
|
+
/config/exportr.yml
|
12
|
+
```
|
10
13
|
|
11
|
-
|
14
|
+
### Basic Usage
|
12
15
|
|
13
|
-
|
16
|
+
Install the gem.
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
group :development do
|
18
|
-
gem 'exportr'
|
19
|
-
end
|
18
|
+
`$ gem install exportr`
|
20
19
|
|
21
|
-
|
20
|
+
Create an exportr.yml file in one of the predefined locations.
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
Run the generator.
|
22
|
+
Require the gem.
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
The generator creates a yaml file in your config directory. It will store key:value pairs to be loaded as environment variables when your app launches. You can edit it manually, or use the command line interface.
|
24
|
+
`require 'exportr'`
|
30
25
|
|
31
|
-
###
|
26
|
+
### Rails
|
32
27
|
|
33
|
-
|
34
|
-
You can use flags longform *e.g.* `--add, --remove, --clear, --list` or shorhand *e.g.* `-a, -r, -c, -l`.
|
28
|
+
Exportr comes with a rails generator that will create `config/exportr.yml` and add it to your `.gitignore` file.
|
35
29
|
|
36
|
-
|
30
|
+
Add the gem to your Gemfile
|
37
31
|
|
38
|
-
|
32
|
+
```
|
33
|
+
group :development do
|
34
|
+
gem 'exportr'
|
35
|
+
end
|
36
|
+
```
|
39
37
|
|
40
|
-
|
38
|
+
Run bundle install.
|
41
39
|
|
42
|
-
|
40
|
+
`$ bundle install`
|
43
41
|
|
44
|
-
|
42
|
+
Start your app server.
|
45
43
|
|
46
|
-
|
44
|
+
`$ rails server`
|
47
45
|
|
48
|
-
**
|
46
|
+
**Notes**
|
49
47
|
|
50
|
-
|
48
|
+
You will need to restart your server/ruby process after changing the yaml file. You can optionally manually load additions to the yaml file by calling `Exportr.export`.
|
51
49
|
|
52
|
-
**Version**
|
53
50
|
|
54
|
-
$ exportr --version
|
55
51
|
|
56
|
-
**Help**
|
57
52
|
|
58
|
-
$ exportr --help
|
59
53
|
|
60
|
-
|
61
|
-
### FYI
|
62
54
|
|
63
|
-
You'll need to restart your webserver for the changes to take effect.
|
64
55
|
|
65
|
-
### New Updates!
|
66
56
|
|
67
|
-
Exportr now supports system configuration files for production deployments of rails apps. By default, exportr will load the YAML file in /etc/#{application_name}_#{rails_env}.yml. The prefix, '/etc', can be overridden by setting the environment variable EXPORTR_PREFIX.
|
68
|
-
|
69
|
-
Make sure the file is readable by your web process.
|
70
|
-
|
71
|
-
### License
|
72
|
-
|
73
|
-
Exportr © 2012 by Richard Calahan and contributors at [All Day Every Day](http://alldayeveryday.com). It is licensed under the MIT license. See the include LICENSE file for details.
|
data/Rakefile
CHANGED
data/config/exportr.yml
ADDED
data/exportr.gemspec
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "exportr/version"
|
4
2
|
|
5
|
-
|
6
|
-
s.name = "exportr"
|
7
|
-
s.version = Exportr::VERSION
|
8
|
-
s.authors = ["Richard Calahan"]
|
9
|
-
s.email = ["richard@alldayeveryday.com"]
|
10
|
-
s.homepage = ""
|
11
|
-
s.summary = 'Rails environment variable manager'
|
12
|
-
s.description = 'Helps manage rails application specific environment variables for multiple apps in development.'
|
13
|
-
|
14
|
-
s.rubyforge_project = "exportr"
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
# specify any dependencies here; for example:
|
22
|
-
#s.add_development_dependency "optparse"
|
23
|
-
# s.add_runtime_dependency "optparse"
|
3
|
+
require 'exportr/version'
|
24
4
|
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'exportr'
|
7
|
+
gem.version = Exportr::VERSION
|
8
|
+
gem.authors = ['Richard Calahan']
|
9
|
+
gem.email = ['richard@calahan.me']
|
10
|
+
gem.description = 'Helps manage ruby application specific environment variables for multiple apps in development.'
|
11
|
+
gem.summary = 'Ruby environment variable manager'
|
12
|
+
gem.homepage = 'https://github.com/richardcalahan/exportr'
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.extensions = Dir.glob 'ext/**/extconf.rb'
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
gem.add_development_dependency 'rake'
|
19
|
+
gem.add_development_dependency 'rake-compiler'
|
20
|
+
gem.add_development_dependency 'rspec'
|
25
21
|
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "ruby/util.h"
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <unistd.h>
|
5
|
+
|
6
|
+
#define FILE "exportr.yml"
|
7
|
+
|
8
|
+
static const char *d_scan[] = { "", "config", 0 };
|
9
|
+
|
10
|
+
static VALUE File = Qnil;
|
11
|
+
static VALUE rb_file ( void )
|
12
|
+
{
|
13
|
+
if ( TYPE(File) == T_NIL ) {
|
14
|
+
File = rb_const_get(rb_cObject, rb_intern("File"));
|
15
|
+
}
|
16
|
+
|
17
|
+
return File;
|
18
|
+
}
|
19
|
+
|
20
|
+
static VALUE Yaml = Qnil;
|
21
|
+
static VALUE rb_yaml ( void )
|
22
|
+
{
|
23
|
+
if ( TYPE(Yaml) == T_NIL ) {
|
24
|
+
Yaml = rb_const_get(rb_cObject, rb_intern("YAML"));
|
25
|
+
}
|
26
|
+
|
27
|
+
return Yaml;
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE exportr_config_file ( void )
|
31
|
+
{
|
32
|
+
VALUE filepath, frag;
|
33
|
+
VALUE exists = Qfalse;
|
34
|
+
|
35
|
+
int i;
|
36
|
+
for ( i=0; 1; i++ ) {
|
37
|
+
if ( d_scan[i] == 0 ) break;
|
38
|
+
|
39
|
+
frag = rb_str_new2(d_scan[i]);
|
40
|
+
if ( strlen(d_scan[i]) > 0 ) rb_str_cat2(frag, "/");
|
41
|
+
rb_str_cat2(frag, FILE);
|
42
|
+
|
43
|
+
filepath = rb_funcall(rb_file(), rb_intern("expand_path"), 1, frag);
|
44
|
+
exists = rb_funcall(rb_file(), rb_intern("exists?"), 1, filepath);
|
45
|
+
|
46
|
+
if ( TYPE(exists) == T_TRUE ) break;
|
47
|
+
|
48
|
+
filepath = Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
return filepath;
|
52
|
+
}
|
53
|
+
|
54
|
+
static int exportr_set_env ( VALUE k, VALUE v, VALUE data )
|
55
|
+
{
|
56
|
+
if ( TYPE(v) != T_STRING ) {
|
57
|
+
v = rb_funcall(v, rb_intern("to_s"), 0);
|
58
|
+
}
|
59
|
+
|
60
|
+
Check_Type(k, T_STRING);
|
61
|
+
Check_Type(v, T_STRING);
|
62
|
+
|
63
|
+
ruby_setenv(StringValuePtr(k), StringValuePtr(v));
|
64
|
+
|
65
|
+
return ST_CONTINUE;
|
66
|
+
}
|
67
|
+
|
68
|
+
static VALUE exportr_read ( void )
|
69
|
+
{
|
70
|
+
VALUE data;
|
71
|
+
VALUE config = exportr_config_file();
|
72
|
+
VALUE hash = Qnil;
|
73
|
+
|
74
|
+
if ( TYPE(config) != T_NIL ) {
|
75
|
+
data = rb_funcall(rb_file(), rb_intern("read"), 1, config);
|
76
|
+
hash = rb_funcall(rb_yaml(), rb_intern("load"), 1, data);
|
77
|
+
return hash;
|
78
|
+
}
|
79
|
+
return Qnil;
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE exportr_export ( void )
|
83
|
+
{
|
84
|
+
VALUE hash = exportr_read();
|
85
|
+
|
86
|
+
if ( TYPE(hash) == T_HASH ) {
|
87
|
+
rb_hash_foreach(hash, *exportr_set_env, Qnil);
|
88
|
+
return Qtrue;
|
89
|
+
}
|
90
|
+
|
91
|
+
return Qfalse;
|
92
|
+
}
|
93
|
+
|
94
|
+
void Init_exportr ( void )
|
95
|
+
{
|
96
|
+
rb_require("yaml");
|
97
|
+
|
98
|
+
VALUE rb_mExportr;
|
99
|
+
|
100
|
+
rb_mExportr = rb_define_module("Exportr");
|
101
|
+
rb_define_singleton_method(rb_mExportr, "export", exportr_export, 0);
|
102
|
+
rb_define_singleton_method(rb_mExportr, "read", exportr_read, 0);
|
103
|
+
rb_define_singleton_method(rb_mExportr, "config_file", exportr_config_file, 0);
|
104
|
+
|
105
|
+
/*
|
106
|
+
* Manually call read on Exportr module when lib is loaded
|
107
|
+
*/
|
108
|
+
rb_funcall(rb_mExportr, rb_intern("export"), 0);
|
109
|
+
}
|
data/lib/exportr/version.rb
CHANGED
data/lib/exportr.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# This file is loaded
|
2
|
-
#
|
1
|
+
# This file is loaded with ruby's environment to set app specific environment variables.
|
2
|
+
# Set environment variables in the format [KEY]: [VALUE]
|
3
3
|
#
|
4
4
|
# FACEBOOK_APP_KEY: '234443366312034'
|
5
5
|
# S3_BUCKET: 'myapp-production'
|
6
6
|
|
7
|
-
---
|
7
|
+
---
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'exportr'
|
3
|
+
|
4
|
+
describe Exportr do
|
5
|
+
|
6
|
+
it 'finds configuration file' do
|
7
|
+
File.exists?(Exportr.config_file).should == true
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'reads configuration file' do
|
11
|
+
Exportr.read['FOO'].should == 'bar'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'wrote configuration file to ENV' do
|
15
|
+
ENV['FOO'].should == 'bar'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
# config.treat_symbols_as_metadata_keys_with_true_values = true
|
3
|
+
# config.run_all_when_everything_filtered = true
|
4
|
+
# config.filter_run :focus
|
5
|
+
|
6
|
+
# Run specs in random order to surface order dependencies. If you find an
|
7
|
+
# order dependency and want to debug it, you can fix the order by providing
|
8
|
+
# the seed, which is printed after each run.
|
9
|
+
# --seed 1234
|
10
|
+
# config.order = 'random'
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exportr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,35 +9,82 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake-compiler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Helps manage ruby application specific environment variables for multiple
|
15
63
|
apps in development.
|
16
64
|
email:
|
17
|
-
- richard@
|
18
|
-
executables:
|
19
|
-
|
20
|
-
|
65
|
+
- richard@calahan.me
|
66
|
+
executables: []
|
67
|
+
extensions:
|
68
|
+
- ext/exportr/extconf.rb
|
21
69
|
extra_rdoc_files: []
|
22
70
|
files:
|
23
71
|
- .gitignore
|
72
|
+
- .rspec
|
24
73
|
- Gemfile
|
25
74
|
- LICENSE
|
26
75
|
- README.md
|
27
76
|
- Rakefile
|
28
|
-
-
|
77
|
+
- config/exportr.yml
|
29
78
|
- exportr.gemspec
|
79
|
+
- ext/exportr/exportr.c
|
80
|
+
- ext/exportr/extconf.rb
|
30
81
|
- lib/exportr.rb
|
31
|
-
- lib/exportr/base.rb
|
32
|
-
- lib/exportr/command.rb
|
33
|
-
- lib/exportr/command/core.rb
|
34
|
-
- lib/exportr/command/helpers.rb
|
35
|
-
- lib/exportr/command/messages.rb
|
36
|
-
- lib/exportr/railtie.rb
|
37
82
|
- lib/exportr/version.rb
|
38
83
|
- lib/generators/exportr/exportr_generator.rb
|
39
84
|
- lib/generators/exportr/templates/exportr.yml
|
40
|
-
|
85
|
+
- spec/exportr_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: https://github.com/richardcalahan/exportr
|
41
88
|
licenses: []
|
42
89
|
post_install_message:
|
43
90
|
rdoc_options: []
|
@@ -56,9 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
103
|
- !ruby/object:Gem::Version
|
57
104
|
version: '0'
|
58
105
|
requirements: []
|
59
|
-
rubyforge_project:
|
106
|
+
rubyforge_project:
|
60
107
|
rubygems_version: 1.8.24
|
61
108
|
signing_key:
|
62
109
|
specification_version: 3
|
63
|
-
summary:
|
64
|
-
test_files:
|
110
|
+
summary: Ruby environment variable manager
|
111
|
+
test_files:
|
112
|
+
- spec/exportr_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
data/bin/exportr
DELETED
data/lib/exportr/base.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Exportr
|
2
|
-
|
3
|
-
module Base
|
4
|
-
|
5
|
-
# Default config file location.
|
6
|
-
CONFIG_FILE = 'config/exportr.yml'
|
7
|
-
|
8
|
-
SYSTEM_FILE_PATH = '/etc'
|
9
|
-
|
10
|
-
def self.extended base
|
11
|
-
constants.each do |const|
|
12
|
-
base.const_set const, const_get(const)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def rails_root
|
17
|
-
begin
|
18
|
-
return Dir.pwd if File.exists?('script/rails')
|
19
|
-
raise
|
20
|
-
rescue
|
21
|
-
Dir.chdir '..'
|
22
|
-
retry unless Dir.pwd == '/'
|
23
|
-
return false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def config_file
|
28
|
-
File.expand_path(CONFIG_FILE, rails_root)
|
29
|
-
end
|
30
|
-
|
31
|
-
def system_config_file
|
32
|
-
prefix = ENV['EXPORTR_PREFIX'] || SYSTEM_FILE_PATH
|
33
|
-
"#{prefix}/#{Rails.application.class.to_s.split('::')[0].downcase}_#{ENV['RAILS_ENV'] || 'development'}.yml"
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/lib/exportr/command/core.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
module Exportr
|
2
|
-
|
3
|
-
module Command
|
4
|
-
|
5
|
-
module Core
|
6
|
-
|
7
|
-
def add val
|
8
|
-
log
|
9
|
-
log "Adding #{val.to_a[0][0]}=#{val.to_a[0][1]} to your environment..."
|
10
|
-
write_config load_config.merge(val)
|
11
|
-
end
|
12
|
-
|
13
|
-
def remove val
|
14
|
-
log
|
15
|
-
log "Removing #{val.to_a[0][0]} from your environment..."
|
16
|
-
write_config load_config.reject { |k,v| k == val.to_a[0][0] }
|
17
|
-
end
|
18
|
-
|
19
|
-
def clear
|
20
|
-
log
|
21
|
-
log "Clearing environment variables..."
|
22
|
-
write_config Hash.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def list
|
26
|
-
log
|
27
|
-
log "Exportr Environment Variables"
|
28
|
-
log "--------------------------------------------------"
|
29
|
-
vars = load_config.to_a
|
30
|
-
vars.each { |var| log "#{var[0]}=#{var[1]}" }
|
31
|
-
log("none.") unless vars.any?
|
32
|
-
log
|
33
|
-
end
|
34
|
-
|
35
|
-
def version
|
36
|
-
log
|
37
|
-
log "Version #{Exportr::VERSION}"
|
38
|
-
log
|
39
|
-
end
|
40
|
-
|
41
|
-
def help
|
42
|
-
STDOUT.puts
|
43
|
-
STDOUT.puts parser.help
|
44
|
-
STDOUT.puts
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'exportr/base'
|
2
|
-
|
3
|
-
module Exportr
|
4
|
-
|
5
|
-
module Command
|
6
|
-
|
7
|
-
module Helpers
|
8
|
-
|
9
|
-
extend Exportr::Base
|
10
|
-
|
11
|
-
def log msg=nil
|
12
|
-
STDOUT.puts msg ? " | #{msg}" : ""
|
13
|
-
end
|
14
|
-
|
15
|
-
def error msg
|
16
|
-
STDERR.puts
|
17
|
-
STDERR.puts " | ERROR: #{msg}"
|
18
|
-
STDERR.puts
|
19
|
-
exit 1
|
20
|
-
end
|
21
|
-
|
22
|
-
def in_rails_application?
|
23
|
-
!!rails_root
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Exportr
|
2
|
-
|
3
|
-
module Command
|
4
|
-
|
5
|
-
module Messages
|
6
|
-
|
7
|
-
# Default error message if CLI is run outside rails
|
8
|
-
NOT_RAILS = 'Could not detect rails application.'
|
9
|
-
|
10
|
-
# Default error message if there is no config file present.
|
11
|
-
NO_CONFIG_FILE = 'You must run `rails generate exportr` first.'
|
12
|
-
|
13
|
-
def self.extended base
|
14
|
-
constants.each do |const|
|
15
|
-
base.const_set const, const_get(const)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
data/lib/exportr/command.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'exportr/base'
|
2
|
-
require 'exportr/command/core'
|
3
|
-
require 'exportr/command/helpers'
|
4
|
-
require 'exportr/command/messages'
|
5
|
-
require 'exportr/version'
|
6
|
-
require 'optparse'
|
7
|
-
require 'yaml'
|
8
|
-
|
9
|
-
module Exportr
|
10
|
-
|
11
|
-
module Command
|
12
|
-
|
13
|
-
extend Exportr::Base
|
14
|
-
extend Exportr::Command::Core
|
15
|
-
extend Exportr::Command::Helpers
|
16
|
-
extend Exportr::Command::Messages
|
17
|
-
|
18
|
-
def self.core_options
|
19
|
-
@global_options ||= []
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.core_option name, *args
|
23
|
-
core_options << { :name => name, :args => args }
|
24
|
-
end
|
25
|
-
|
26
|
-
core_option :add, '-a', '--add KEY=VALUE', 'Add environment variable'
|
27
|
-
core_option :remove, '-r', '--remove KEY', 'Remove environment variable'
|
28
|
-
core_option :clear, '-c', '--clear', 'Clear out all environment variables'
|
29
|
-
core_option :list, '-l', '--list', 'List all environment variables'
|
30
|
-
core_option :version, '-v', '--version', 'Get exportr version number'
|
31
|
-
core_option :help, '-h', '--help', 'Print this message'
|
32
|
-
|
33
|
-
def self.run *argv
|
34
|
-
error NOT_RAILS unless in_rails_application?
|
35
|
-
argv.any? ? parser.parse!(argv) : help
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.parser
|
39
|
-
OptionParser.new do |parser|
|
40
|
-
parser.banner = "Usage:\n exportr [options]"
|
41
|
-
parser.separator "\nOptions: "
|
42
|
-
core_options.each do |opt|
|
43
|
-
parser.on *opt[:args] do |val|
|
44
|
-
send(opt[:name], hashify(val)) rescue send opt[:name]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.read_config
|
51
|
-
error NO_CONFIG_FILE unless File.exists?(config_file)
|
52
|
-
File.read config_file
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.write_config vars
|
56
|
-
cm = comments
|
57
|
-
File.open config_file, 'w+' do |f|
|
58
|
-
f.write cm << "\n" << dump_config(vars)
|
59
|
-
end
|
60
|
-
log "Done."
|
61
|
-
log
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.load_config
|
65
|
-
YAML.load(read_config) || Hash.new
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.dump_config vars
|
69
|
-
YAML.dump(vars)
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.comments
|
73
|
-
read_config.match(/(^\#.*\n)+/).to_s
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.hashify str
|
77
|
-
arr = str.split('=') rescue []
|
78
|
-
hash = Hash.new
|
79
|
-
hash[arr[0]] = arr[1]
|
80
|
-
hash
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
data/lib/exportr/railtie.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'exportr/base'
|
2
|
-
|
3
|
-
module Exportr
|
4
|
-
|
5
|
-
class Railtie < Rails::Railtie
|
6
|
-
|
7
|
-
extend Exportr::Base
|
8
|
-
|
9
|
-
config.before_configuration do
|
10
|
-
|
11
|
-
if File.exists? config_file
|
12
|
-
config = YAML.load(File.open(config_file))
|
13
|
-
config.each_pair { |key,value| ENV[key] = value } if config
|
14
|
-
end
|
15
|
-
|
16
|
-
if File.exists? system_config_file
|
17
|
-
config = YAML.load(File.open(system_env_file))
|
18
|
-
config.each_pair { |key,value| ENV[key] = value } if config
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|