higo 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +17 -6
- data/higo.gemspec +12 -12
- data/lib/higo/transport/file.rb +9 -1
- data/lib/higo/transport/web.rb +16 -13
- data/lib/higo/version.rb +1 -1
- data/test/test_helper.rb +1 -0
- data/test/test_web_transport.rb +7 -12
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97469ec0b1755c63561a9d6ce00050a887074baf
|
4
|
+
data.tar.gz: 4621abc05548852b449bbd54ca1a2522e6368e0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f52d1347c109186ca7a1bea428662ae88272e4e5afbc573eecb5e7f37804743bdebf6633e54b441ed1fde09d10c43b0dfb99a921d85922a2c26b229c0bfc8c1
|
7
|
+
data.tar.gz: dbd6dcb639cd8cc2661f7780f661274e8bace6c1c8f27d96674f9a0d33a25f2a7f2fba50e26d8d9229483ea145c2409e2cdc7ee1c4f27ba2a172b530dd350e95
|
data/README.md
CHANGED
@@ -1,24 +1,34 @@
|
|
1
1
|
# Higo
|
2
2
|
|
3
3
|
## Get started
|
4
|
+
|
5
|
+
Rubygems:
|
6
|
+
|
4
7
|
`gem install higo`
|
5
8
|
|
6
|
-
|
9
|
+
Gemfile:
|
10
|
+
|
11
|
+
`gem 'higo'`
|
12
|
+
|
13
|
+
Detailed usage examples can be found in the `/examples` directory. Supports reading from ruby objects and text files, JSON support coming soon.
|
14
|
+
|
7
15
|
Documentation can be found [here](http://www.rubydoc.info/github/rhodee/higo/master).
|
8
16
|
|
9
17
|
## Gem Story - TL;DR
|
10
|
-
Higo creates
|
18
|
+
Higo creates configuration objects dynamically. It also plays nice with methods you define. It can be subclassed or
|
19
|
+
included as a module. Define settings in the block, pass values from a relative, dynamic file or URL path. All the same.
|
20
|
+
|
21
|
+
require 'higo'
|
11
22
|
|
12
|
-
class
|
23
|
+
class Configurable < Higo::Configurable
|
13
24
|
configure do |conf|
|
14
25
|
conf.greatness = 'pending'
|
15
26
|
conf.host = Hostname.new
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
`Higo` creates __getter__ `(greatness)`, __setter__ `(host=)`and __predicate__ methods `(host?)`.
|
30
|
+
The `configure` block returns an instance of `Higo::Configurable`. The values themselves held instance variables.
|
31
|
+
No need to define accessors ahead of time. `Higo` creates __getter__ `greatness()`, __setter__ `host=(val)`and __predicate__ methods `host?`.
|
22
32
|
|
23
33
|
## Gem Story -v
|
24
34
|
`Higo` enables the developer to create `flexible` configuration objects. It returns a `Higo::Configurable` object with
|
@@ -39,6 +49,7 @@ want. Higo might not be right for you at this stage.
|
|
39
49
|
|
40
50
|
* ~~Generate arbitrary configuration values~~
|
41
51
|
* Improve support for subclasses that define `method_missing`
|
52
|
+
* Add support for JSON files
|
42
53
|
* ~~Read from an external source~~
|
43
54
|
* Improve documentation
|
44
55
|
|
data/higo.gemspec
CHANGED
@@ -5,18 +5,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'higo/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name
|
9
|
-
s.version
|
10
|
-
s.authors
|
11
|
-
s.email
|
12
|
-
s.summary
|
13
|
-
s.description
|
14
|
-
s.homepage
|
15
|
-
s.license
|
16
|
-
s.test_files
|
17
|
-
s.require_paths
|
18
|
-
s.platform
|
19
|
-
|
8
|
+
s.name = "higo"
|
9
|
+
s.version = Higo::Version::String
|
10
|
+
s.authors = ["rhodee"]
|
11
|
+
s.email = ["info@rhodee.us"]
|
12
|
+
s.summary = %q{ A dyanmic configuration object creator. Reads from local files, remote resources or PORO. }
|
13
|
+
s.description = %q{ Configuration management gem. }
|
14
|
+
s.homepage = "https://github.com/rhodee/higo"
|
15
|
+
s.license = "MIT"
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.required_ruby_version = '>= 2.0.0'
|
20
20
|
s.files = Dir[
|
21
21
|
"LICENSE",
|
22
22
|
"AUTHORS",
|
data/lib/higo/transport/file.rb
CHANGED
@@ -13,10 +13,18 @@ module Higo
|
|
13
13
|
|
14
14
|
def self.transport(path)
|
15
15
|
file = new(path)
|
16
|
-
file._raw_file =
|
16
|
+
file._raw_file = file.call
|
17
17
|
file
|
18
18
|
end
|
19
19
|
|
20
|
+
def call
|
21
|
+
Fiber.new do
|
22
|
+
::File.open(path, 'r') do |f|
|
23
|
+
f.readlines.map
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
20
28
|
def finish
|
21
29
|
_raw_file.resume.map do |val|
|
22
30
|
responses.merge!(Hash[*process_value(val)])
|
data/lib/higo/transport/web.rb
CHANGED
@@ -13,24 +13,31 @@ module Higo
|
|
13
13
|
|
14
14
|
def self.transport(url)
|
15
15
|
request = new(url)
|
16
|
-
request._raw_data =
|
17
|
-
http = Net::HTTP.new(request.path.host, request.path.port)
|
18
|
-
http.use_ssl = true if request.path.port == 443
|
19
|
-
http.request(Net::HTTP::Get.new(request.path.to_s))
|
20
|
-
end
|
16
|
+
request._raw_data = request.call
|
21
17
|
request
|
22
18
|
end
|
23
19
|
|
24
|
-
def
|
25
|
-
|
20
|
+
def call
|
21
|
+
Fiber.new do
|
22
|
+
http = Net::HTTP.new(path.host, path.port)
|
23
|
+
http.use_ssl = true if path.port == 443
|
24
|
+
http.request(Net::HTTP::Get.new(path.to_s))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def finish(data=nil)
|
29
|
+
result = data.respond_to?(:resume) ? data.resume : self._raw_data.resume
|
30
|
+
raise 'Provide an object that responds to resume' if data.nil?
|
26
31
|
temp_file = Tempfile.new([self.path.host.tr('.',''), ::Pathname.new(self.path.to_s).extname])
|
27
|
-
|
28
|
-
|
32
|
+
|
33
|
+
if success?(result.code) && result.body.bytesize > 0
|
34
|
+
::File.open(temp_file.path, 'w') { |f| f.write(result.body) }
|
29
35
|
response = Transport::File.transport(path: temp_file.path).finish
|
30
36
|
temp_file.unlink
|
31
37
|
else
|
32
38
|
raise 'No Data at endpoint'
|
33
39
|
end
|
40
|
+
|
34
41
|
response
|
35
42
|
rescue => e
|
36
43
|
raise e if e.class == SocketError
|
@@ -52,10 +59,6 @@ module Higo
|
|
52
59
|
def status_code(code)
|
53
60
|
Integer(code) rescue nil
|
54
61
|
end
|
55
|
-
|
56
|
-
def value(code, value)
|
57
|
-
{":#{code}" => value}
|
58
|
-
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
end
|
data/lib/higo/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/test_web_transport.rb
CHANGED
@@ -2,17 +2,8 @@ require_relative './test_helper'
|
|
2
2
|
require 'higo/transport/web'
|
3
3
|
|
4
4
|
class TestWebTransport < Higo::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@web_request = Higo::Transport::Web.new(path: 'https://gist.githubusercontent.com/rhodee/9732239/raw/356c3877c5055a19b11ed6ed083387c7cd78cdf7/test.txt')
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
@web_request = nil
|
12
|
-
end
|
13
|
-
|
14
5
|
def test_transport_retrieval
|
15
|
-
assert
|
6
|
+
assert Higo::Transport::Web.new(path: 'https://wwww.pathtoconfiguration.com').path.to_s =~ /http/
|
16
7
|
end
|
17
8
|
|
18
9
|
def test_resource_path_error
|
@@ -20,7 +11,11 @@ class TestWebTransport < Higo::TestCase
|
|
20
11
|
end
|
21
12
|
|
22
13
|
def test_file_read
|
23
|
-
|
24
|
-
|
14
|
+
url = 'https://secret.configuration.com/plain_config.txt'
|
15
|
+
request = Higo::Transport::Web.new(path: url)
|
16
|
+
rsp = StubResponse.new(200, "user=foo\njoy='code'")
|
17
|
+
payload = Fiber.new { rsp }
|
18
|
+
|
19
|
+
refute_equal true, request.finish(payload).empty?
|
25
20
|
end
|
26
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: higo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rhodee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -156,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 2.0.0
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
162
|
- - ">="
|
@@ -164,9 +164,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.2.
|
167
|
+
rubygems_version: 2.2.0
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
|
-
summary: A
|
170
|
+
summary: A dyanmic configuration object creator. Reads from local files, remote resources
|
171
|
+
or PORO.
|
171
172
|
test_files: []
|
172
173
|
has_rdoc:
|