foundry 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9da30abaa99f3fd6c765f67591499dc5cca98f12
4
- data.tar.gz: 6df1988b72d7e206e11253cd80e6d1eed20ac506
3
+ metadata.gz: fb2577df8898406d373fe649df69d6fcb30f9688
4
+ data.tar.gz: 1bf538e9a2cefd8a68a474ac36c73a18afd3b10c
5
5
  SHA512:
6
- metadata.gz: 4e427ccece01e33d3b1387246a92a73ff9c4d316ad5d77651fd1d67df0a95fbeddabd94bd2b152110f4d3f6e4aba8f2f374b2cb0c873bef1d7a975aadd1cd141
7
- data.tar.gz: 1fab1178b3d77026e47e205a004ddb0c430172853e6b334c5b648cfeb642b3eef2b8f2a31a1a2480737f5041a74aaa377c6c2dca33dde602a4d7d743b59db310
6
+ metadata.gz: 0b7c6975739a40247f16b952dcc2623c1fd35fbfdb7a6e10adc3892cb4fec25cc6715593314d2e21f4054493a1f5c517102b12ea15a7beceac5d5bdee05a5b8a
7
+ data.tar.gz: a666555baaae3f83aba7a2aa881bb94ab11fbf8a7c52d45fff7b25d76f81a1991ea21ab333ccef254e190b5bf0cd3a563f9abbcefdc903b40fa2a8cfcde9da93
data/README.md CHANGED
@@ -5,6 +5,18 @@
5
5
 
6
6
  An application configuration gem that aims to keep it simple
7
7
 
8
+ Let's face it, there are a number of problems when application/environment
9
+ configuration logic is too tightly coupled with the configuration-data itself.
10
+ This gem aims to keep it simple and fully decouple the two concerns.
11
+
12
+ Features:
13
+
14
+ * Can load YAML from a local-file
15
+ * Can load YAML from a HTTP/HTTPS endpoint
16
+ * Supports Basic Authentication for HTTP{,S} endpoints
17
+ * Supports ERB interpolation
18
+ * Returns an easy to navigate object-graph
19
+
8
20
  ## Installation
9
21
 
10
22
  Add this line to your application's Gemfile:
@@ -24,25 +36,42 @@ Or install it yourself as:
24
36
  Loading from a local-file:
25
37
 
26
38
  ```ruby
27
- Foundry::Configurator.configure(:file_name => 'path-to-local-file')
39
+ config = Foundry::Configurator.configure(:file_name => 'path-to-local-file')
28
40
  ```
29
41
 
30
42
  Loading from a HTTP/HTTPS endpoint:
31
43
 
32
44
  ```ruby
33
- Foundry::Configurator.configure(:uri => 'http-or-https-endpoint')
45
+ config = Foundry::Configurator.configure(:uri => 'http-or-https-endpoint')
34
46
  ```
35
47
 
36
48
  Loading from a HTTP/HTTPS endpoint using "Basic Authentication":
37
49
 
38
50
  ```ruby
39
- Foundry::Configurator.configure(
51
+ config = Foundry::Configurator.configure(
40
52
  :uri => 'http-or-https-endpoint',
41
53
  :username => 'basic-auth-username',
42
54
  :password => 'basic-auth-password'
43
55
  )
44
56
  ```
45
57
 
58
+ Using the "config" object (defined above):
59
+
60
+ ```ruby
61
+ # The examples below assume that the following YAML was loaded by a call to
62
+ # "Foundry::Configurator.configure" and into a variable named "config"
63
+ #
64
+ # ---
65
+ # some_key:
66
+ # some_nested_key: value
67
+
68
+ # Fetch a value using dot-notation
69
+ value = config.some_key.some_nested_key
70
+
71
+ # Fetch a value by key
72
+ value = config['some_key']['some_nested_key']
73
+ ```
74
+
46
75
  ## Contributing
47
76
 
48
77
  1. Fork it ( http://github.com/jzaleski/foundry/fork )
data/TODO CHANGED
@@ -1,2 +1 @@
1
- * Consider using `Hashie` instead of `OpenStruct`
2
1
  * Add support for other source-file types (JSON? XML (::shiver::)?)
data/foundry.gemspec CHANGED
@@ -8,20 +8,12 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Foundry::VERSION
9
9
  gem.authors = ['Jonathan W. Zaleski']
10
10
  gem.email = ['JonathanZaleski@gmail.com']
11
- gem.summary = %{An application configuration gem that aims to keep it simple}
12
- gem.description = <<-EOL
11
+ gem.summary = 'An application configuration gem that aims to keep it simple'
12
+ gem.description = <<-DESCRIPTION
13
13
  Let's face it, there are a number of problems when application/environment
14
14
  configuration logic is too tightly coupled with the configuration-data itself.
15
15
  This gem aims to keep it simple and fully decouple the two concerns.
16
-
17
- Features:
18
-
19
- * Can load YAML from a local-file
20
- * Can load YAML from a HTTP/HTTPS endpoint
21
- * Supports Basic Authentication for HTTP{,S} endpoints
22
- * Supports ERB interpolation
23
- * Returns an easy to navigate object-graph
24
- EOL
16
+ DESCRIPTION
25
17
  gem.homepage = 'https://github.com/jzaleski/foundry'
26
18
  gem.license = 'MIT'
27
19
 
@@ -2,7 +2,7 @@ module Foundry
2
2
  class Configurator
3
3
  class << self
4
4
  def configure(opts={})
5
- ostructify(
5
+ structify(
6
6
  load_yaml(
7
7
  evaluate_erb(
8
8
  load_by_filename_or_uri(opts)
@@ -31,16 +31,16 @@ module Foundry
31
31
  YAML.load(str)
32
32
  end
33
33
 
34
- def ostructify(object)
34
+ def structify(object)
35
35
  case object
36
36
  when Array
37
37
  object.map do |value|
38
- ostructify(value)
38
+ structify(value)
39
39
  end
40
40
  when Hash
41
- OpenStruct.new.tap do |ostruct|
41
+ Foundry::HashStruct.new.tap do |hash_struct|
42
42
  object.each do |key, value|
43
- ostruct.public_send("#{key}=", ostructify(value))
43
+ hash_struct[key] = structify(value)
44
44
  end
45
45
  end
46
46
  else
@@ -0,0 +1,10 @@
1
+ module Foundry
2
+ class HashStruct < OpenStruct
3
+ def [](key)
4
+ public_send(key.to_sym)
5
+ end
6
+ def []=(key, value)
7
+ public_send("#{key.to_sym}=", value)
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Foundry
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/foundry.rb CHANGED
@@ -6,6 +6,7 @@ require 'uri'
6
6
  require 'yaml'
7
7
 
8
8
  require 'foundry/configurator'
9
+ require 'foundry/hash_struct'
9
10
  require 'foundry/loaders/file'
10
11
  require 'foundry/loaders/uri'
11
12
  require 'foundry/version'
@@ -42,8 +42,8 @@ describe Foundry::Configurator do
42
42
  YAML
43
43
  }
44
44
  expect(subject.configure(:file_name => '')).to eq(
45
- OpenStruct.new(
46
- 'root' => OpenStruct.new(
45
+ Foundry::HashStruct.new(
46
+ 'root' => Foundry::HashStruct.new(
47
47
  'erb' => 6,
48
48
  'float' => 123.0,
49
49
  'integer' => 42,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foundry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan W. Zaleski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-08 00:00:00.000000000 Z
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,14 +70,6 @@ description: |2
70
70
  Let's face it, there are a number of problems when application/environment
71
71
  configuration logic is too tightly coupled with the configuration-data itself.
72
72
  This gem aims to keep it simple and fully decouple the two concerns.
73
-
74
- Features:
75
-
76
- * Can load YAML from a local-file
77
- * Can load YAML from a HTTP/HTTPS endpoint
78
- * Supports Basic Authentication for HTTP{,S} endpoints
79
- * Supports ERB interpolation
80
- * Returns an easy to navigate object-graph
81
73
  email:
82
74
  - JonathanZaleski@gmail.com
83
75
  executables: []
@@ -94,6 +86,7 @@ files:
94
86
  - foundry.gemspec
95
87
  - lib/foundry.rb
96
88
  - lib/foundry/configurator.rb
89
+ - lib/foundry/hash_struct.rb
97
90
  - lib/foundry/loaders/file.rb
98
91
  - lib/foundry/loaders/uri.rb
99
92
  - lib/foundry/version.rb
@@ -121,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
114
  version: '0'
122
115
  requirements: []
123
116
  rubyforge_project:
124
- rubygems_version: 2.2.2
117
+ rubygems_version: 2.3.0
125
118
  signing_key:
126
119
  specification_version: 4
127
120
  summary: An application configuration gem that aims to keep it simple