fun_with_configurations 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -1
- data/README.rdoc +28 -0
- data/VERSION +1 -1
- data/lib/fun_with/configurations/config.rb +0 -20
- data/lib/fun_with/configurations/config_api.rb +47 -0
- data/lib/fun_with/configurations/{module_includes.rb → gem_api.rb} +2 -1
- data/lib/fun_with/configurations/loader_style.rb +21 -0
- data/lib/fun_with/configurations/object_methods.rb +32 -0
- data/lib/fun_with_configurations.rb +4 -9
- data/test/test_loading_from_file.rb +1 -5
- data/test/test_setup_basics.rb +4 -3
- metadata +12 -4
- data/lib/fun_with/configurations/object.rb +0 -35
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGQ3MzlhYzM1NWY2MDBlZTEyMzE5YTIyNDBlNzkzNDM4YmFlN2FmOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDYwNWJhNmU0MDRiMjg5NDg0MzcwMDNlMWZhYzhjM2QwM2ZhZWIwYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTMzOTc4ODA1MmMxMmFiZDY5ZTU3OWI5MjEzZjQyODdjNDNiNDA3MWYyM2Nl
|
10
|
+
NjJjMzIzMzY5N2QzOWU1ZGM1MzUwOGI3M2U2MDVkNDI5MjExMWY4OTBkZWUz
|
11
|
+
MmE2NmE4YTcyOTM4MDZjODZiNmFhOGU0MmQ1YzVjZjJlNWQ1MDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGZjMTc4ZTI5NTU1NDU5YzQyNjA4Yzg4MjIyODFjYjg5NTFjMTY0YTgxZTU4
|
14
|
+
YzdkNjZmMjA2MjY1ZWVhYjZlMmJlYzIwOWZmNDg0M2JiNmU5ODYwNzExOTIz
|
15
|
+
M2M1NmMyOTA3YTk0M2MwY2YxYWI4OTM4Mzc2MzQ2MjJiMTIwMTg=
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -162,6 +162,34 @@ Basically, this is meant to spare you from typing the longhand form:
|
|
162
162
|
|
163
163
|
|
164
164
|
|
165
|
+
|
166
|
+
|
167
|
+
== FunWith::Patterns::Loader integration
|
168
|
+
|
169
|
+
To use configurations with the Loader pattern:
|
170
|
+
|
171
|
+
require 'fun_with_configurations'
|
172
|
+
require 'fun_with_patterns'
|
173
|
+
|
174
|
+
class Computer
|
175
|
+
attr_accessor :label
|
176
|
+
|
177
|
+
# Look up individual configurations via Computer[:bob_system]
|
178
|
+
loader_pattern_configure( :bracketwise_lookup,
|
179
|
+
:warn_on_key_change, # Warn if an existing lookup key is overwritten
|
180
|
+
{ :key => :label, # Key is found by calling method label()
|
181
|
+
:style => FunWith::Configurations::LoadingStyle } ) # Interprets the file as a FWC::Config
|
182
|
+
end
|
183
|
+
|
184
|
+
Computer.loader_pattern_load_from_dir( "~/.config/computers" ) # loads all the configurations in the directory
|
185
|
+
puts Computer[:bob_system].memory # ==> "4GB"
|
186
|
+
|
187
|
+
Internally, the LoadingStyle simply offloads the loading work to Config.from_file(), so any valid configuration format will do (.rb, .yaml).
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
165
193
|
== Contributing to fun_with_configurations
|
166
194
|
|
167
195
|
[Boilerplate from Jeweler. Seems reasonable.]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
@@ -60,13 +60,6 @@ module FunWith
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.key_check( sym )
|
64
|
-
@reserved_symbols ||= Config.instance_methods - self.fwc_overridden_methods
|
65
|
-
|
66
|
-
raise KeyError.new("#{sym} is not a symbol") unless sym.is_a?(Symbol)
|
67
|
-
raise KeyError.new("#{sym} is reserved for use by Hash") if @reserved_symbols.include?( sym )
|
68
|
-
end
|
69
|
-
|
70
63
|
def try( *keys )
|
71
64
|
(t = TryObject.new( self )).tap do
|
72
65
|
for key in keys
|
@@ -120,19 +113,6 @@ module FunWith
|
|
120
113
|
end
|
121
114
|
end
|
122
115
|
|
123
|
-
def self.from_hash( hash )
|
124
|
-
(config = self.new).tap do
|
125
|
-
for k, v in hash
|
126
|
-
config.send( k, v.is_a?( Hash ) ? self.from_hash( v ) : v )
|
127
|
-
end
|
128
|
-
end
|
129
|
-
config
|
130
|
-
end
|
131
|
-
|
132
|
-
def self.fwc_overridden_methods
|
133
|
-
ConfigOverriddenMethods.instance_methods.grep( /[^=]$/ )
|
134
|
-
end
|
135
|
-
|
136
116
|
def fwc_overridden_methods
|
137
117
|
self.class.fwc_overridden_methods
|
138
118
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Configurations
|
3
|
+
# methods on the FunWith::Configurations::Config class itself.
|
4
|
+
module ConfigAPI
|
5
|
+
def key_check( sym )
|
6
|
+
@reserved_symbols ||= Config.instance_methods - self.fwc_overridden_methods
|
7
|
+
|
8
|
+
raise KeyError.new("#{sym} is not a symbol") unless sym.is_a?(Symbol)
|
9
|
+
raise KeyError.new("#{sym} is reserved for use by Hash") if @reserved_symbols.include?( sym )
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def from_file( file )
|
14
|
+
file = file.fwf_filepath
|
15
|
+
|
16
|
+
case file.ext
|
17
|
+
when "rb"
|
18
|
+
self.new do
|
19
|
+
eval( file.read )
|
20
|
+
end
|
21
|
+
when "yml", "yaml"
|
22
|
+
self.from_yaml( file.read )
|
23
|
+
else
|
24
|
+
warn( "Unknown filetype: #{file.ext} (file:#{file}}). Returning empty config." )
|
25
|
+
self.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def from_hash( hash )
|
30
|
+
(config = self.new).tap do
|
31
|
+
for k, v in hash
|
32
|
+
config.send( k, v.is_a?( Hash ) ? self.from_hash( v ) : v )
|
33
|
+
end
|
34
|
+
end
|
35
|
+
config
|
36
|
+
end
|
37
|
+
|
38
|
+
def from_yaml( yaml_string )
|
39
|
+
self.from_hash( Psych.load( yaml_string ) )
|
40
|
+
end
|
41
|
+
|
42
|
+
def fwc_overridden_methods
|
43
|
+
ConfigOverriddenMethods.instance_methods.grep( /[^=]$/ )
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module FunWith
|
2
2
|
module Configurations
|
3
|
-
module
|
3
|
+
module GemAPI
|
4
4
|
def configure( object, config = nil, &block )
|
5
5
|
if block_given?
|
6
6
|
object.install_fwc_config( config, &block )
|
@@ -20,6 +20,7 @@ module FunWith
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
#
|
23
24
|
protected
|
24
25
|
def configuration_argument_type?( arg )
|
25
26
|
case arg
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# For integrating with FunWith::Patterns::LoaderPattern
|
2
|
+
# See README for example usage
|
3
|
+
module FunWith
|
4
|
+
module Configurations
|
5
|
+
module LoadingStyle
|
6
|
+
# Default behavior: read the file, evaluate it, expect a ruby object
|
7
|
+
# of the class that the loader pattern is installed on. If anything goes
|
8
|
+
# wrong (file no exist, syntax error), returns a nil.
|
9
|
+
#
|
10
|
+
# Override in your class if you need your files translated
|
11
|
+
# into objects differently.
|
12
|
+
def loader_pattern_load_item( file )
|
13
|
+
self.loader_pattern_rescue_failing_item_load( file ) do
|
14
|
+
obj = Config.from_file( file )
|
15
|
+
|
16
|
+
return obj
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module FunWith
|
2
|
+
module Configurations
|
3
|
+
module ObjectMethods
|
4
|
+
def install_fwc_config( config = nil, &block )
|
5
|
+
extend FunWith::Configurations::Configurable
|
6
|
+
self.config = config || FunWith::Configurations::Config.new( &block )
|
7
|
+
self.config.fwc_configured_object = self
|
8
|
+
self.config
|
9
|
+
end
|
10
|
+
|
11
|
+
def install_fwc_config_from_file( file )
|
12
|
+
config = FunWith::Configurations::Config.from_file( file )
|
13
|
+
self.install_fwc_config( config )
|
14
|
+
self.fwc_configuration_file = file
|
15
|
+
self.config
|
16
|
+
end
|
17
|
+
|
18
|
+
def install_fwc_config_from_hash( hash )
|
19
|
+
config = FunWith::Configurations::Config.from_hash( hash )
|
20
|
+
self.install_fwc_config( config )
|
21
|
+
self.config
|
22
|
+
end
|
23
|
+
|
24
|
+
def install_fwc_config_from_yaml( yaml_string )
|
25
|
+
config = Config.from_yaml( yaml_string )
|
26
|
+
self.install_fwc_config( config )
|
27
|
+
self.config
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -1,10 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'fun_with_gems'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
FunWith::Files::RootPath.rootify( FunWith::Configurations, __FILE__.fwf_filepath.dirname.up )
|
9
|
-
FunWith::Configurations.root( "lib", "fun_with", "configurations" ).requir
|
10
|
-
FunWith::Configurations.extend( FunWith::Configurations::ModuleIncludes )
|
3
|
+
FunWith::Gems.make_gem_fun( "FunWith::Configurations" )
|
4
|
+
FunWith::Configurations::Config.extend( FunWith::Configurations::ConfigAPI )
|
5
|
+
Object.send(:include, FunWith::Configurations::ObjectMethods)
|
data/test/test_setup_basics.rb
CHANGED
@@ -2,9 +2,10 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestSetupBasics < FunWith::Configurations::TestCase
|
4
4
|
context "testing basics" do
|
5
|
-
context "FunWith::Configurations module"
|
6
|
-
|
7
|
-
|
5
|
+
context "FunWith::Configurations module" do
|
6
|
+
should "respond to :configure" do
|
7
|
+
assert FunWith::Configurations.respond_to?(:configure)
|
8
|
+
end
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
metadata
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_with_configurations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fun_with_gems
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.2
|
17
20
|
- - ~>
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: '0.0'
|
@@ -21,6 +24,9 @@ dependencies:
|
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.2
|
24
30
|
- - ~>
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: '0.0'
|
@@ -49,11 +55,13 @@ extra_rdoc_files:
|
|
49
55
|
files:
|
50
56
|
- ./lib/fun_with/configurations/chain_error.rb
|
51
57
|
- ./lib/fun_with/configurations/config.rb
|
58
|
+
- ./lib/fun_with/configurations/config_api.rb
|
52
59
|
- ./lib/fun_with/configurations/config_overridden_methods.rb
|
53
60
|
- ./lib/fun_with/configurations/configurable.rb
|
61
|
+
- ./lib/fun_with/configurations/gem_api.rb
|
54
62
|
- ./lib/fun_with/configurations/key_error.rb
|
55
|
-
- ./lib/fun_with/configurations/
|
56
|
-
- ./lib/fun_with/configurations/
|
63
|
+
- ./lib/fun_with/configurations/loader_style.rb
|
64
|
+
- ./lib/fun_with/configurations/object_methods.rb
|
57
65
|
- ./lib/fun_with/configurations/try_object.rb
|
58
66
|
- ./lib/fun_with/configurations/try_result.rb
|
59
67
|
- ./lib/fun_with_configurations.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
def install_fwc_config( config = nil, &block )
|
3
|
-
extend FunWith::Configurations::Configurable
|
4
|
-
self.config = config || FunWith::Configurations::Config.new( nil, &block )
|
5
|
-
self.config.fwc_configured_object = self
|
6
|
-
self.config
|
7
|
-
end
|
8
|
-
|
9
|
-
def install_fwc_config_from_file( file )
|
10
|
-
file = file.fwf_filepath
|
11
|
-
|
12
|
-
case file.ext
|
13
|
-
when "rb"
|
14
|
-
self.install_fwc_config do
|
15
|
-
eval( file.read )
|
16
|
-
end
|
17
|
-
when "yml", "yaml"
|
18
|
-
self.install_fwc_config_from_yaml( file.read )
|
19
|
-
end
|
20
|
-
|
21
|
-
self.fwc_configuration_file = file
|
22
|
-
self.config
|
23
|
-
end
|
24
|
-
|
25
|
-
def install_fwc_config_from_hash( hash )
|
26
|
-
self.install_fwc_config( FunWith::Configurations::Config.from_hash( hash ) )
|
27
|
-
self.config
|
28
|
-
end
|
29
|
-
|
30
|
-
def install_fwc_config_from_yaml( yaml_string )
|
31
|
-
self.install_fwc_config_from_hash( Psych.load( yaml_string ) )
|
32
|
-
self.config
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|