exportr 0.2.6 → 0.2.7

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.
data/README.md CHANGED
@@ -13,8 +13,10 @@ Exportr helps you manage *local* environment variables. Each set is scoped to a
13
13
  ### Setup
14
14
 
15
15
  Add the gem to your Gemfile.
16
-
17
- gem 'exportr'
16
+
17
+ group :development do
18
+ gem 'exportr'
19
+ end
18
20
 
19
21
  Install it!
20
22
 
@@ -0,0 +1,37 @@
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_env_file
32
+ "#{SYSTEM_FILE_PATH}/#{Rails.application.class.to_s.split('::')[0].downcase}.yml"
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,52 @@
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
+
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,23 @@
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
@@ -1,5 +1,7 @@
1
- require 'exportr/config'
2
- require 'exportr/helpers'
1
+ require 'exportr/base'
2
+ require 'exportr/command/core'
3
+ require 'exportr/command/helpers'
4
+ require 'exportr/command/messages'
3
5
  require 'exportr/version'
4
6
  require 'optparse'
5
7
  require 'yaml'
@@ -7,75 +9,37 @@ require 'yaml'
7
9
  module Exportr
8
10
 
9
11
  module Command
10
-
11
- extend Exportr::Helpers
12
- extend Exportr::Config
13
12
 
14
- def self.global_options
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
15
19
  @global_options ||= []
16
20
  end
17
21
 
18
- def self.global_option name, *args
19
- global_options << { :name => name, :args => args }
22
+ def self.core_option name, *args
23
+ core_options << { :name => name, :args => args }
20
24
  end
21
25
 
22
- global_option :add, '-a', '--add KEY=VALUE', 'Add environment variable'
23
- global_option :remove, '-r', '--remove KEY', 'Remove environment variable'
24
- global_option :clear, '-c', '--clear', 'Clear out all environment variables'
25
- global_option :list, '-l', '--list', 'List all environment variables'
26
- global_option :version, '-v', '--version', 'Get exportr version number'
27
- global_option :help, '-h', '--help', 'Print this message'
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'
28
32
 
29
33
  def self.run *argv
30
34
  error NOT_RAILS unless in_rails_application?
31
35
  argv.any? ? parser.parse!(argv) : help
32
36
  end
33
37
 
34
- def self.add val
35
- log
36
- log "Adding #{val.to_a[0][0]}=#{val.to_a[0][1]} to your environment..."
37
- write_config load_config.merge(val)
38
- end
39
-
40
- def self.remove val
41
- log
42
- log "Removing #{val.to_a[0][0]} from your environment..."
43
- write_config load_config.reject { |k,v| k == val.to_a[0][0] }
44
- end
45
-
46
- def self.clear
47
- log
48
- log "Clearing environment variables..."
49
- write_config Hash.new
50
- end
51
-
52
- def self.list
53
- log
54
- log "Exportr Environment Variables"
55
- log "--------------------------------------------------"
56
- vars = load_config.to_a
57
- vars.each { |var| log "#{var[0]}=#{var[1]}" }
58
- log("none.") unless vars.any?
59
- log
60
- end
61
-
62
- def self.version
63
- log
64
- log "Version #{Exportr::VERSION}"
65
- log
66
- end
67
-
68
- def self.help
69
- STDOUT.puts
70
- STDOUT.puts parser.help
71
- STDOUT.puts
72
- end
73
-
74
38
  def self.parser
75
39
  OptionParser.new do |parser|
76
40
  parser.banner = "Usage:\n exportr [options]"
77
41
  parser.separator "\nOptions: "
78
- global_options.each do |opt|
42
+ core_options.each do |opt|
79
43
  parser.on *opt[:args] do |val|
80
44
  send(opt[:name], hashify(val)) rescue send opt[:name]
81
45
  end
@@ -1,16 +1,23 @@
1
- require 'exportr/helpers'
1
+ require 'exportr/base'
2
2
 
3
3
  module Exportr
4
4
 
5
5
  class Railtie < Rails::Railtie
6
6
 
7
- extend Exportr::Helpers
7
+ extend Exportr::Base
8
8
 
9
9
  config.before_initialize do
10
+
10
11
  if File.exists? config_file
11
12
  config = YAML.load(File.open(config_file))
12
13
  config.each_pair { |key,value| ENV[key] = value } if config
13
14
  end
15
+
16
+ if File.exists? system_env_file
17
+ config = YAML.load(File.open(system_env_file))
18
+ config.each_pair { |key,value| ENV[key] = value } if config
19
+ end
20
+
14
21
  end
15
22
 
16
23
  end
@@ -1,3 +1,3 @@
1
1
  module Exportr
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/lib/exportr.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'exportr/version'
2
1
  require 'exportr/railtie'
2
+ require 'exportr/version'
3
3
 
4
4
  module Exportr; 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.2.6
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-11 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helps manage rails application specific environment variables for multiple
15
15
  apps in development.
@@ -28,9 +28,11 @@ files:
28
28
  - bin/exportr
29
29
  - exportr.gemspec
30
30
  - lib/exportr.rb
31
+ - lib/exportr/base.rb
31
32
  - lib/exportr/command.rb
32
- - lib/exportr/config.rb
33
- - lib/exportr/helpers.rb
33
+ - lib/exportr/command/core.rb
34
+ - lib/exportr/command/helpers.rb
35
+ - lib/exportr/command/messages.rb
34
36
  - lib/exportr/railtie.rb
35
37
  - lib/exportr/version.rb
36
38
  - lib/generators/exportr/exportr_generator.rb
@@ -55,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  version: '0'
56
58
  requirements: []
57
59
  rubyforge_project: exportr
58
- rubygems_version: 1.8.6
60
+ rubygems_version: 1.8.24
59
61
  signing_key:
60
62
  specification_version: 3
61
63
  summary: Rails environment variable manager
@@ -1,22 +0,0 @@
1
- module Exportr
2
-
3
- module Config
4
-
5
- # Default config file location.
6
- CONFIG_FILE = 'config/exportr.yml'
7
-
8
- # Default error message if CLI is run from anywhere but the root
9
- NOT_RAILS = 'Could not detect rails application.'
10
-
11
- # Default error message if there is no config file present.
12
- NO_CONFIG_FILE = 'You must run `rails generate exportr` first.'
13
-
14
- def self.extended base
15
- constants.each do |const|
16
- base.const_set const, const_get(const)
17
- end
18
- end
19
-
20
- end
21
-
22
- end
@@ -1,39 +0,0 @@
1
- require 'exportr/config'
2
-
3
- module Exportr
4
-
5
- module Helpers
6
-
7
- extend Exportr::Config
8
-
9
- def log msg=nil
10
- STDOUT.puts msg ? " | #{msg}" : ""
11
- end
12
-
13
- def error msg
14
- STDERR.puts " | ERROR: #{msg}"
15
- exit 1
16
- end
17
-
18
- def in_rails_application?
19
- !!rails_root
20
- end
21
-
22
- def rails_root
23
- begin
24
- return Dir.pwd if File.exists?('script/rails')
25
- raise
26
- rescue
27
- Dir.chdir '..'
28
- retry unless Dir.pwd == '/'
29
- return false
30
- end
31
- end
32
-
33
- def config_file
34
- File.expand_path(CONFIG_FILE, rails_root)
35
- end
36
-
37
- end
38
-
39
- end