appenv 0.0.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '083eb5dee12cb821929f725c3f56912cf030d80211a7c1ccf9cf67c2fad7d9d1'
4
+ data.tar.gz: 9f10c7e9fb1d0f5ee285e0999c6e893b29c4844d610055be5036edc48f8731bd
5
+ SHA512:
6
+ metadata.gz: d3fbf92b0556ba4f81f1112681506b5771420ec2aeebfdc80907b424719a8b8a64d66715f46ff582554715285c459db76ec9b03906fe8e574479489a7fd8d0f7
7
+ data.tar.gz: 73ffa02c40985690c24ef753cda8e1ed4e3aec5a2168e5b30f189af99c62d7cad8c7e481c946dd85c56893392130f998a44dd63eac3afff039f34988260e1fac
@@ -3,11 +3,44 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
3
3
  def initialize(file = '.env', &blk)
4
4
  super(&nil)
5
5
  @file = file
6
+ expand(&blk)
7
+ end
8
+
9
+
10
+ # You can use `expand` to add more values to the environment after
11
+ # initialization. eg:
12
+ #
13
+ # # Create the environment:
14
+ # @env = AppEnv::Environment.new('test/data/env') { |env, src|
15
+ # env.var1 = src.var_one
16
+ # }
17
+ #
18
+ # # Later, expand it:
19
+ # @env.expand { |env, src|
20
+ # env.var2 = src.var_two
21
+ # }
22
+ #
23
+ def expand(&blk)
6
24
  source = _compile_source_env
7
25
  blk.call(self, source)
8
26
  end
9
27
 
10
28
 
29
+ # If you are computing a complex value (say, a conditional one), you might
30
+ # like to set the value via a block. eg:
31
+ #
32
+ # # Simple variable assignment:
33
+ # env.var1 = src.var_one
34
+ #
35
+ # # Variable assignment with `set`:
36
+ # env.set(:var2) {
37
+ # if abcd?
38
+ # 'xyz'
39
+ # else
40
+ # 'foo'
41
+ # end
42
+ # }
43
+ #
11
44
  def set(property, &blk)
12
45
  self.send("#{property}=", blk.call)
13
46
  end
@@ -25,10 +58,11 @@ class AppEnv::Environment < ActiveSupport::OrderedOptions
25
58
 
26
59
  def _source_env_from_file
27
60
  src = {}
28
- return src unless File.exists?(@file)
61
+ return src unless File.exist?(@file)
29
62
  File.open(@file, 'r').each_line { |ln|
30
63
  cln = ln.strip.sub(/^export\s+/, '')
31
64
  next if cln.match(/^#/)
65
+ next if cln.empty?
32
66
  if m = cln.match(/\A([A-Za-z_0-9]+)=(.*)\z/)
33
67
  k = m[1]
34
68
  v = m[2]
@@ -1,5 +1,5 @@
1
1
  module AppEnv
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '1.0.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,69 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joseph Pearson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- requirement: &9946620 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *9946620
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  description: Environment-variable compatible application configuration.
26
- email:
27
- - joseph@booki.sh
28
+ email: joseph@users.noreply.github.com
28
29
  executables: []
29
30
  extensions: []
30
31
  extra_rdoc_files: []
31
32
  files:
32
- - .gitignore
33
- - README.md
34
- - Rakefile
35
- - appenv.gemspec
36
33
  - lib/appenv.rb
37
34
  - lib/appenv/environment.rb
38
35
  - lib/appenv/version.rb
39
- - test/data/env
40
- - test/test_helper.rb
41
- - test/unit/test_environment.rb
42
- homepage: ''
43
- licenses: []
36
+ homepage: https://github.com/joseph/appenv
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
44
40
  post_install_message:
45
41
  rdoc_options: []
46
42
  require_paths:
47
43
  - lib
48
44
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - ">="
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
49
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
50
  requirements:
57
- - - ! '>='
51
+ - - ">="
58
52
  - !ruby/object:Gem::Version
59
53
  version: '0'
60
54
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 1.8.11
55
+ rubygems_version: 3.0.6
63
56
  signing_key:
64
- specification_version: 3
57
+ specification_version: 4
65
58
  summary: Application environment configuration
66
- test_files:
67
- - test/data/env
68
- - test/test_helper.rb
69
- - test/unit/test_environment.rb
59
+ test_files: []
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- .screenrc
data/README.md DELETED
@@ -1,35 +0,0 @@
1
- # APPENV
2
-
3
- A simple gem that gives you an application environment configuration object.
4
- Values are loaded from ENV or from an environment file such as `.env`.
5
-
6
- Similar to the `.env` feature in Foreman, but these values will be available
7
- to your application no matter how you launch it (script/rails, Passenger,
8
- Unicorn, rake, etc).
9
-
10
- For convenience, there is also compatibility with Bash-style environment
11
- declarations in your `.env` file; ie: `export ENV_VAR_NAME="foo"`.
12
-
13
- ## Example
14
-
15
- You'd typically create your configuration object in `config/application.rb`.
16
-
17
- ```ruby
18
- module ExampleProjectName
19
-
20
- Env = AppEnv::Environment.new { |env, src|
21
- env.domain = src.my_domain_variable || 'example.com'
22
- env.set(:access_codes) {
23
- src.access_codes ? src.access_codes.split : nil
24
- }
25
- }
26
-
27
- # class Application < Rails::Application
28
- # ... etc ...
29
- #
30
- # Your config is available globally in ExampleProjectName::Env.
31
- #
32
-
33
- end
34
-
35
- ```
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- Rake::TestTask.new { |t|
4
- t.libs << 'test'
5
- t.test_files = FileList['test/unit/test*.rb']
6
- t.verbose = true
7
- }
8
-
9
- desc("Run tests")
10
- task(:default => :test)
data/appenv.gemspec DELETED
@@ -1,18 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/appenv/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ['Joseph Pearson']
6
- gem.email = ['joseph@booki.sh']
7
- gem.description = 'Environment-variable compatible application configuration.'
8
- gem.summary = 'Application environment configuration'
9
- gem.homepage = ''
10
-
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = 'appenv'
15
- gem.require_paths = ['lib']
16
- gem.version = AppEnv::VERSION
17
- gem.add_dependency('activesupport')
18
- end
data/test/data/env DELETED
@@ -1,3 +0,0 @@
1
- VAR_ONE="foo"
2
- export VAR_TWO="bar"
3
- # VAR_THREE="garply"
data/test/test_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'appenv'
2
- require 'test/unit'
@@ -1,18 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AppEnv::TestEnvironment < Test::Unit::TestCase
4
-
5
- def test_sanity
6
- assert_nothing_raised {
7
- @env = AppEnv::Environment.new('test/data/env') { |env, src|
8
- env.var1 = src.var_one
9
- env.set(:var2) { src.var_two }
10
- env.var3 = src.var_three || 'grault'
11
- }
12
- }
13
- assert_equal('foo', @env.var1)
14
- assert_equal('bar', @env.var2)
15
- assert_equal('grault', @env.var3)
16
- end
17
-
18
- end