herokuconf 0.0.1 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d11d494b1a7bdd768e47fa15f3eacb2302523c4
4
- data.tar.gz: eb886dc7d75bec157080b7d0f149ccfe58f34c5d
3
+ metadata.gz: 898c4fd09b882a3e199aa0b05eb8d3ecaf42e385
4
+ data.tar.gz: 867acce0a8ca10a653e8a6e28024ef03c232c803
5
5
  SHA512:
6
- metadata.gz: f3d5e0968225074bfd1bd0232f5646a25a66e9d7200898fe006be7e86616e15435e080fb8664b293536f7abbac775656cdfa6a005f940af33e5f18d82376f4b3
7
- data.tar.gz: a5666680388f4b2705b8819cf53736e7c2d697e855aab01c948156d74e35a45f67b7624e4af10225a54dc7ddf1a00930103fe51d575d26ef846621c3466853b6
6
+ metadata.gz: 8ad6fa33a8535b5b2e4c18cc747b623c2199b319e3d37732fa2455d16a0ad5f6ea9be5509ec7689b30fefb6e6d4d5ee7d688cde96ffa35c798d575957a6a4e6c
7
+ data.tar.gz: 982da23a89c50aa2df008fd27b9b1f938279d09182a973ff48427f962259e624eb28b33e73d1c209e139a2ae2f4f0976bf9bcac5b078b81640cba43edd7ec0b3
data/herokuconf.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'herokuconf'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.6'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
 
6
6
  s.summary = 'Configure local environment based on Heroku config variables'
data/lib/herokuconf.rb CHANGED
@@ -1,13 +1,47 @@
1
+ require 'heroku-api'
2
+ require 'netrc'
3
+
1
4
  ##
2
5
  # Base module for HerokuConf
3
6
  module HerokuConf
4
7
  class << self
5
- ##
6
- # Insert a helper .new() method for creating a new App object
7
- def new(*args)
8
- self::App.new(*args)
8
+ DEFAULT_OPTIONS = {
9
+ app: nil,
10
+ keys: nil
11
+ }
12
+
13
+ def configure!(params = {})
14
+ return if ENV['DYNO']
15
+ app, keys = DEFAULT_OPTIONS.dup.merge!(params).values_at(:app, :keys)
16
+ pairs = config_vars(app)
17
+ pairs.select! { |k, _| keys.include? k } if keys
18
+ pairs.each { |k, v| ENV[k] = v }
19
+ end
20
+
21
+ private
22
+
23
+ def config_vars(app = nil)
24
+ app ||= parse_app
25
+ client.get_config_vars(app).body
26
+ end
27
+
28
+ def parse_app
29
+ remotes.first[1].split('/').last.split('.').first
30
+ end
31
+
32
+ def remotes
33
+ remotes = `git remote -v`.split("\n").map(&:split)
34
+ remotes.select! { |x| x.first == 'heroku' && x.last == '(push)' }
35
+ fail('No app found') unless remotes.size == 1
36
+ remotes
37
+ end
38
+
39
+ def client
40
+ @client ||= Heroku::API.new(api_key: api_key)
41
+ end
42
+
43
+ def api_key
44
+ @api_key ||= Netrc.read['api.heroku.com'].password
9
45
  end
10
46
  end
11
47
  end
12
-
13
- require 'herokuconf/app'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herokuconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
@@ -124,7 +124,6 @@ files:
124
124
  - Rakefile
125
125
  - herokuconf.gemspec
126
126
  - lib/herokuconf.rb
127
- - lib/herokuconf/app.rb
128
127
  - spec/herokuconf_spec.rb
129
128
  - spec/spec_helper.rb
130
129
  homepage: https://github.com/akerl/herokuconf
@@ -1,51 +0,0 @@
1
- require 'netrc'
2
- require 'heroku-api'
3
-
4
- module HerokuConf
5
- ##
6
- # App object for parsing Heroku configs
7
- class App
8
- def initialize(params = {})
9
- @app = params[:app]
10
- end
11
-
12
- def configure!(keys = nil)
13
- pairs = config_vars
14
- pairs.select! { |k, _| keys.include? k } if keys
15
- pairs.each { |k, v| ENV[k] = v }
16
- end
17
-
18
- private
19
-
20
- def config_vars
21
- client.get_config_vars(app).body
22
- end
23
-
24
- def app
25
- @app ||= parse_app
26
- end
27
-
28
- def parse_app
29
- remotes.first[1].split('/').last.split('.').first
30
- end
31
-
32
- def remotes
33
- @remote ||= parse_remotes
34
- end
35
-
36
- def parse_remotes
37
- remotes = `git remote -v`.split("\n").map(&:split)
38
- remotes.select! { |x| x.first == 'heroku' && x.last == '(push)' }
39
- fail('No app found') unless remotes.size == 1
40
- remotes
41
- end
42
-
43
- def client
44
- @client ||= Heroku::API.new(api_key: api_key)
45
- end
46
-
47
- def api_key
48
- @api_key ||= Netrc.read['api.heroku.com'].password
49
- end
50
- end
51
- end