exportr 0.0.3 → 0.1.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.
data/README CHANGED
@@ -4,7 +4,7 @@ Simple.
4
4
 
5
5
  Gemfile:
6
6
 
7
- gem 'exportr', :git => 'git://github.com/richardcalahan/exportr.git'
7
+ gem 'exportr'
8
8
 
9
9
  CLI:
10
10
 
data/bin/exportr CHANGED
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
4
- $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
3
+ require 'exportr/command'
5
4
 
6
- require 'exportr'
7
-
8
- puts "exportr rules"
5
+ Exportr::Command.run *ARGV
data/exportr.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
22
+ #s.add_development_dependency "optparse"
23
+ # s.add_runtime_dependency "optparse"
24
+
24
25
  end
@@ -0,0 +1,76 @@
1
+ require 'optparse'
2
+ require 'exportr/config'
3
+ require 'exportr/error_messages'
4
+ require 'exportr/helpers'
5
+
6
+ module Exportr
7
+
8
+ module Command
9
+
10
+ extend Exportr::Config
11
+ extend Exportr::ErrorMessages
12
+ extend Exportr::Helpers
13
+
14
+ global_option :add, '-a', '--add VAR', 'Add environment variable'
15
+ global_option :remove, '-r', '--remove VAR', 'Remove environment variable'
16
+
17
+ def self.run *argv
18
+ error not_root unless at_root?
19
+ parser.parse! argv
20
+ end
21
+
22
+ def self.add val
23
+ vars = load_config
24
+ vars.merge! val
25
+ write_config vars
26
+ end
27
+
28
+ def self.remove val
29
+ vars = load_config
30
+ write_config vars.reject { |k,v| k == val.to_a[0][0] }
31
+ end
32
+
33
+ def self.parser
34
+ OptionParser.new do |parser|
35
+ global_options.each do |opt|
36
+ parser.on *opt[:args] do |val|
37
+ send opt[:name], hashify(val)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.read_config
44
+ error no_config_file unless File.exists?(config_file)
45
+ File.read config_file
46
+ end
47
+
48
+ def self.write_config vars
49
+ cm = comments
50
+ File.open config_file, 'w+' do |f|
51
+ f.write cm << "\n" << dump_config(vars)
52
+ end
53
+ end
54
+
55
+ def self.load_config
56
+ YAML.load(read_config) || Hash.new
57
+ end
58
+
59
+ def self.dump_config vars
60
+ YAML.dump(vars)
61
+ end
62
+
63
+ def self.comments
64
+ read_config.match(/(^\#.*\n)+/).to_s
65
+ end
66
+
67
+ def self.hashify str
68
+ arr = str.split '='
69
+ hash = Hash.new
70
+ hash[arr[0]] = arr[1]
71
+ hash
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,19 @@
1
+ module Exportr
2
+
3
+ module Config
4
+
5
+ def global_options
6
+ @global_options ||= []
7
+ end
8
+
9
+ def global_option name, *args
10
+ global_options << { :name => name, :args => args }
11
+ end
12
+
13
+ def config_file
14
+ "config/exportr.yml"
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,15 @@
1
+ module Exportr
2
+
3
+ module ErrorMessages
4
+
5
+ def not_root
6
+ "You must run exportr from the root of your application."
7
+ end
8
+
9
+ def no_config_file
10
+ "You must run `rails generate exportr` first. "
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ module Exportr
2
+
3
+ module Helpers
4
+
5
+ def error msg
6
+ puts "ERROR: " << msg
7
+ exit 1
8
+ end
9
+
10
+ def at_root?
11
+ !!Dir.new(Dir.pwd).collect.detect { |f| f == 'Gemfile' }
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Exportr
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -8,6 +8,7 @@ class ExportrGenerator < Rails::Generators::Base
8
8
  end
9
9
 
10
10
  def mod_gitignore
11
+ return if File.read("#{Rails.root}/.gitignore").match(/config\/exportr.yml/)
11
12
  File.open("#{Rails.root}/.gitignore", 'a+') do |f|
12
13
  f.puts
13
14
  f.puts
@@ -1,7 +1,6 @@
1
1
  # This file is loaded at app initialization to set app specific environment variables
2
2
  # set environment variables in the format [KEY]: [VALUE], each separated by a newline
3
-
4
- # Examples:
3
+ #
5
4
  # FACEBOOK_APP_KEY: '234443366312034'
6
5
  # S3_BUCKET: 'myapp-production'
7
6
 
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.0.3
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,10 @@ files:
27
27
  - bin/exportr
28
28
  - exportr.gemspec
29
29
  - lib/exportr.rb
30
+ - lib/exportr/command.rb
31
+ - lib/exportr/config.rb
32
+ - lib/exportr/error_messages.rb
33
+ - lib/exportr/helpers.rb
30
34
  - lib/exportr/version.rb
31
35
  - lib/generators/exportr/exportr_generator.rb
32
36
  - lib/generators/exportr/templates/exportr.rb