higo 0.0.1.alpha

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6ef0dc27690d5b9720eb4c3266c4bf653c35df9
4
+ data.tar.gz: d0437735de76419825f3e8eb3f32159c830039f1
5
+ SHA512:
6
+ metadata.gz: 4bdf1616d5634ef5e5955b12e6b1f5447ce76f1a0f9b56feb2e6cd8668da7cc504b08a4e906e3a8c67d78a88ad49ce4880b7b05d3bc4e1b28c15f67caabbf0e8
7
+ data.tar.gz: 32466bf5747e206bc9f0d64ce68d863b2a81949625cac0d1c9d6137e01fb663ab0cb9bff2b3e311fc2c3a9302727a2674ee970c982d902b4ce1eb0e79918cb21
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Higo
2
+
3
+ ## Get started
4
+ `gem install higo`
5
+
6
+ Detailed usage examples can be found in the `/examples` directory.
7
+
8
+ ## Gem Story - TL;DR
9
+ Higo creates 'config' objects dynamic using the well understood `configure` block:
10
+
11
+ class ConfigureFoo
12
+ configure do |conf|
13
+ conf.greatness = 'pending'
14
+ conf.host = Hostname.new
15
+ end
16
+ end
17
+
18
+ Except you don't _have_ to define those methods ahead of time.
19
+
20
+ `Higo` creates __getter__ `(greatness)`, __setter__ `(host=)`and __predicate__ methods `(host?)`.
21
+
22
+ ## Gem Story -v
23
+ `Higo` enables the developer to create `flexible` configuration objects. It returns a `Higo::Configurable` object with
24
+ getter, setter and predicate methods based on the values passed to the block.
25
+
26
+ Flexible meant two things (to me, at least). First, knowledge of the configuration values should not depend on static
27
+ methods definition. Second, I prefer configuration that accepts multiple formats (like text, YAML)that could come from
28
+ from remote sources.
29
+
30
+ I settled on the name after finding that [fig](https://github.com/mfoemmel/fig), [figgy](https://github.com/pd/figgy)
31
+ were taken. Sure I could've named it `figy`, but that would be too confusing. So I settled on `Higo`.
32
+
33
+
34
+ __Note__-if you already defined `method_missing` in your class `Higo` will honor that and that is likely not what you
35
+ want. Higo might now be right for you at this stage.
36
+
37
+ ### To Do List
38
+
39
+ * ~~Generate arbitrary configuration values~~
40
+ * Improve support for subclasses that define `method_missing`
41
+ * Read from an external source
42
+ * Improve documentation
43
+
44
+ ## Contributing
45
+ If you are developing against this gem (yay!), run `bundle exec rake -T` for list of rake tasks.
46
+
47
+ 1. Fork it ( https://github.com/rhodee/higo/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'test/test_*.rb'
6
+ end
7
+
8
+ namespace :stats do
9
+ Analyzers = [:flay, :flog, :reek]
10
+
11
+ desc 'Run flog to report your most tortured code'
12
+ task :flog do
13
+ puts "*" * 50
14
+ puts "Running flog..."
15
+ system './vendor/bundle/bin/flog -g lib/**'
16
+ puts " "
17
+ end
18
+
19
+ desc 'Run reek to examine ruby code for any code smells'
20
+ task :reek do
21
+ puts "*" * 50
22
+ puts "Running reek..."
23
+ system './vendor/bundle/bin/reek lib/**'
24
+ puts " "
25
+ end
26
+
27
+ desc 'Run flay for analyzing code for structural similarities.'
28
+ task :flay do
29
+ puts "*" * 50
30
+ puts "Running flay..."
31
+ system './vendor/bundle/bin/flay lib/**'
32
+ puts " "
33
+ end
34
+
35
+ desc 'Run tests and all analyzers'
36
+ task :all do
37
+ system 'bundle exec rake test'
38
+ Analyzers.each { |analyzer| Rake::Task["stats:#{analyzer}"].invoke }
39
+ end
40
+ end
data/higo.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'higo/version'
6
+
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
+
20
+ s.files = Dir[
21
+ "LICENSE",
22
+ "AUTHORS",
23
+ "README.md",
24
+ "Rakefile",
25
+ "lib/**/*.rb",
26
+ "*.gemspec",
27
+ "test/**/*.rb"
28
+ ]
29
+
30
+ s.add_development_dependency "yard", "~> 0.8.7"
31
+ s.add_development_dependency "pry", "~> 0.9"
32
+ s.add_development_dependency "bundler", "~> 1.5"
33
+ s.add_development_dependency "rake", "~> 10.1"
34
+ s.add_development_dependency "minitest", "~> 5.2"
35
+ s.add_development_dependency "reek", "~> 1.3"
36
+ s.add_development_dependency "flay", "~> 2.4"
37
+ s.add_development_dependency "flog", "~> 4.2"
38
+ end
@@ -0,0 +1,65 @@
1
+ # Module can be subclass or composed to yields a Configurable object
2
+ # that responds to any attributes defined inside the #configure block
3
+ #
4
+ module Higo
5
+ def self.included(mod)
6
+ mod.extend(Macros)
7
+ end
8
+
9
+ module Macros
10
+ def configure(&block)
11
+ configuration ||= Higo::Configurable.new
12
+ configuration.instance_eval(&block)
13
+ return configuration
14
+ end
15
+ end
16
+
17
+ class Configurable
18
+ # Takes any arbitrary code block which defines getter and setters and returns a Higo::Configurable
19
+ # object that returns instance variables, getter, setter and predicate methods
20
+ #
21
+ # @param [Proc]
22
+ # @return [Configurable] responds to getter, setter, predicate methods defined
23
+ def self.configure(&block)
24
+ configuration = generate_configurable
25
+ configuration.instance_eval(&block)
26
+ return configuration
27
+ end
28
+
29
+ def respond_to_missing?(method_name, include_private = false)
30
+ super unless self.instance_variables.include?(convert_method_to_symbol(method_name))
31
+ end
32
+
33
+ # If an existing class defines, method_missing that incantation is run, otherwise
34
+ # all unknown methods are defined as getter, setters and predicate methods
35
+ def method_missing(meth, *args, &block)
36
+
37
+ if defined?(super)
38
+ klass = self.class
39
+ super(meth, *args, &block) if respond_to?(meth)
40
+
41
+ ivar = convert_method_to_symbol(meth)
42
+ data = args.size == 1 ? args.first : args
43
+
44
+ klass.__send__(:attr_accessor, ivar)
45
+ klass.__send__(:define_method, "#{ivar}?", proc { !!data })
46
+
47
+ instance_variable_set("@#{ivar}", data)
48
+
49
+ self
50
+ else
51
+ super
52
+ end
53
+ end
54
+
55
+
56
+ private
57
+ def convert_method_to_symbol(meth)
58
+ meth.to_s.gsub('=', '').to_sym
59
+ end
60
+
61
+ def self.generate_configurable
62
+ configuration ||= Configurable.new
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ module Higo
2
+ module Version
3
+ Major = 0
4
+ Minor = 0
5
+ Tiny = 1
6
+ Pre = "alpha"
7
+
8
+ String = [Major, Minor, Tiny, Pre].compact.join(".")
9
+ end
10
+ end
data/lib/higo.rb ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright 2014 Denis Rhoden Jr.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+ #
23
+ # See https://github.com/rhodee/higo for updates.
24
+ #
25
+ module Higo
26
+ autoload :Version, 'higo/version'
27
+ autoload :Configurable, 'higo/configurable'
28
+ end
@@ -0,0 +1,13 @@
1
+ require_relative './test_helper'
2
+ require 'higo/configurable'
3
+
4
+ class TestConfigurable < Higo::TestCase
5
+
6
+ def test_config_methods
7
+ @configuration = Higo::Configurable.configure { |c| c.foo = 'meh' }
8
+
9
+ assert_includes @configuration.methods, :foo
10
+ assert_includes @configuration.methods, :foo?
11
+ assert_includes @configuration.methods, :foo=
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path("../lib/higo", File.dirname(__FILE__))
2
+
3
+ # Load support files
4
+ Dir.glob(File.expand_path('./support/*', File.dirname(__FILE__))) {|file| require file }
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest/pride'
8
+
9
+ module Higo
10
+ class TestCase < Minitest::Test
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require_relative './test_helper'
2
+ require 'higo/configurable'
3
+
4
+ class Configurator; include Higo; end
5
+
6
+ class TestHigoInheritance < Higo::TestCase
7
+
8
+ def test_config_methods
9
+ @configuration = Configurator.configure do |conf|
10
+ conf.username = 'meh'
11
+ conf.records = Object.new
12
+ end
13
+
14
+ assert_includes @configuration.methods, :username
15
+ assert_includes @configuration.methods, :records?
16
+ assert_includes @configuration.methods, :records=
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require_relative './test_helper'
2
+ require 'higo/configurable'
3
+
4
+ class Configurable < Higo::Configurable;end
5
+
6
+ class TestHigoSubClass < Higo::TestCase
7
+
8
+ def test_config_methods
9
+ @configuration = Configurable.configure do |conf|
10
+ conf.port = 8080
11
+ conf.hostname = 'testing'
12
+ conf.password = '$3(r3t'
13
+ end
14
+
15
+ assert_includes @configuration.methods, :port
16
+ assert_includes @configuration.methods, :password?
17
+ assert_includes @configuration.methods, :hostname=
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: higo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ platform: ruby
6
+ authors:
7
+ - rhodee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.7
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: reek
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: flay
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: flog
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.2'
125
+ description: " Configuration management gem. "
126
+ email:
127
+ - info@rhodee.us
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - README.md
133
+ - Rakefile
134
+ - higo.gemspec
135
+ - lib/higo.rb
136
+ - lib/higo/configurable.rb
137
+ - lib/higo/version.rb
138
+ - test/test_configurable.rb
139
+ - test/test_helper.rb
140
+ - test/test_higo_inheritance.rb
141
+ - test/test_higo_subclass.rb
142
+ homepage: https://github.com/rhodee/higo
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.3.1
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.2.0
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: A (soon) to be highly configurable configuration manager.
166
+ test_files: []
167
+ has_rdoc: