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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e64120e8327764a40c07d0d79c7efc78a1c4922d
4
- data.tar.gz: 45fa3ad29a672badfa2e76936d92b027dec63a04
3
+ metadata.gz: 97469ec0b1755c63561a9d6ce00050a887074baf
4
+ data.tar.gz: 4621abc05548852b449bbd54ca1a2522e6368e0f
5
5
  SHA512:
6
- metadata.gz: 642bd77bd34f6661554ce6d06a9936a0d20229f2a4523d81f002666e612789c4810bf91a1d875b57ed17e250f1c0d862290421b297801426d44cd2b5733e2cee
7
- data.tar.gz: 1db2709a88a6d3c6746386ab75ce7d0e621217dad1c155c71f81a7aecfdf8bc78133bcb6b28d149a719e4702a37651402e0ce92c778ede8f6722491dc40f3279
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
- Detailed usage examples can be found in the `/examples` directory.
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 'config' objects dynamic using the well understood `configure` block:
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 ConfigureFoo
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
- Except you don't _have_ to define those methods ahead of time.
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 = "higo"
9
- s.version = Higo::Version::String
10
- s.authors = ["rhodee"]
11
- s.email = ["info@rhodee.us"]
12
- s.summary = %q{ A (soon) to be highly configurable configuration manager. }
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
-
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",
@@ -13,10 +13,18 @@ module Higo
13
13
 
14
14
  def self.transport(path)
15
15
  file = new(path)
16
- file._raw_file = Fiber.new { ::File.open(file.path, 'r') { |f| f.readlines.map } }
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)])
@@ -13,24 +13,31 @@ module Higo
13
13
 
14
14
  def self.transport(url)
15
15
  request = new(url)
16
- request._raw_data = Fiber.new do
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 finish
25
- data = _raw_data.resume
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
- if success?(data.code) && data.body.bytesize > 0
28
- ::File.open(temp_file.path, 'w') { |f| f.write(data.body) }
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
@@ -2,7 +2,7 @@ module Higo
2
2
  module Version
3
3
  Major = 0
4
4
  Minor = 0
5
- Tiny = 1
5
+ Tiny = 2
6
6
  Pre = nil
7
7
 
8
8
  String = [Major, Minor, Tiny, Pre].compact.join(".")
data/test/test_helper.rb CHANGED
@@ -8,5 +8,6 @@ require 'minitest/pride'
8
8
 
9
9
  module Higo
10
10
  class TestCase < Minitest::Test
11
+ StubResponse = Struct.new(:code, :body)
11
12
  end
12
13
  end
@@ -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 @web_request.path.to_s =~ /http/
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
- results = Higo::Transport::Web.transport(path: @web_request.path.to_s).finish
24
- refute_equal true, results.empty?
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.1
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-24 00:00:00.000000000 Z
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: '0'
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.2
167
+ rubygems_version: 2.2.0
168
168
  signing_key:
169
169
  specification_version: 4
170
- summary: A (soon) to be highly configurable configuration manager.
170
+ summary: A dyanmic configuration object creator. Reads from local files, remote resources
171
+ or PORO.
171
172
  test_files: []
172
173
  has_rdoc: