gaston 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gaston.rb ADDED
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require 'yaml'
3
+ require 'singleton'
4
+
5
+ class Gaston
6
+ include Singleton
7
+ require 'gaston/configuration'
8
+ require 'gaston/store'
9
+
10
+ # Parse yml config files, merge them, and store into
11
+ # gaston::Store
12
+ #
13
+ # @since 0.0.1
14
+ #
15
+ def store
16
+ @store ||= Gaston::Store.new (files.inject({}) {|hash, config|
17
+ parse = YAML.load_file(config)[env]
18
+ hash.merge(parse) if parse
19
+ })
20
+ end
21
+
22
+ class << self
23
+
24
+ def retrieve
25
+ self.instance.store
26
+ end
27
+
28
+ # Define a configure block.
29
+ #
30
+ # Delegates to Gaston::Configuration
31
+ #
32
+ # @example Define the option.
33
+ # Gaston.configure do |config|
34
+ # config.env = :test
35
+ # config.files = Dir[Rails.root.join("config/libraries/**/*.rb"]
36
+ # end
37
+ #
38
+ # @param [ Proc ] block The block getting called.
39
+ #
40
+ # @since 0.0.1
41
+ #
42
+ def configure(&block)
43
+ Gaston::Configuration.configure(&block)
44
+ end
45
+ end # self
46
+
47
+ private
48
+
49
+ # List config files.
50
+ #
51
+ # @since 0.0.1
52
+ #
53
+ def files
54
+ Gaston::Configuration.files
55
+ end
56
+
57
+ # Current enironment.
58
+ #
59
+ # @since 0.0.1
60
+ #
61
+ def env
62
+ Gaston::Configuration.env.to_sym
63
+ end
64
+
65
+ end # Gaston
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ class Gaston
3
+ class Configuration
4
+
5
+ class << self
6
+
7
+ attr_accessor :files, :env
8
+
9
+ # Define a configure block.
10
+ #
11
+ # @example
12
+ # Gaston.configure do |config|
13
+ # config.env = :test
14
+ # config.files = Dir[Rails.root.join("config/libraries/**/*.rb"]
15
+ # end
16
+ #
17
+ # @param [ Proc ] block The block getting called.
18
+ #
19
+ # @since 0.0.1
20
+ #
21
+ def configure(&block)
22
+ default_values!
23
+ yield self
24
+ end
25
+
26
+ private
27
+
28
+ # Set default values
29
+ #
30
+ # @since 0.0.1
31
+ #
32
+ def default_values!
33
+ @files = []
34
+ @env = :development
35
+ end
36
+
37
+ end # self
38
+ end # Configuration
39
+ end #Gaston
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ class Gaston
3
+ class Store < Hash
4
+
5
+ # Initialize Store.
6
+ #
7
+ # @param [ Hash ] Hash config to be stored.
8
+ #
9
+ # @since 0.0.1
10
+ #
11
+ def initialize(hash)
12
+ hash ||= {}
13
+ hash.each do |key, value|
14
+ value.is_a?(Hash) ? self[key] = Gaston::Store.new(value) : self[key] = value
15
+ end
16
+ end
17
+
18
+ # Search into store for value.
19
+ #
20
+ # @param [ String || Symbol ] key store.
21
+ #
22
+ # @since 0.0.1
23
+ #
24
+ def method_missing(method, *args, &block)
25
+ return self[method.to_s] if has_key? method.to_s
26
+ return self[method.to_sym] if has_key? method.to_sym
27
+ super(method, *args, &block)
28
+ end
29
+
30
+ # Implement respond_to?
31
+ #
32
+ # @since 0.0.1
33
+ #
34
+ def respond_to?(method)
35
+ has_key?(method.to_s) || has_key?(method.to_sym) || super(method)
36
+ end
37
+
38
+ end # Store
39
+ end #Gaston
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ class Gaston
3
+ VERSION = "0.0.1"
4
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gaston
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chatgris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-28 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &20411480 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '2.6'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *20411480
26
+ description: ! '[Dead simple Ruby config store.]'
27
+ email: jboyer@af83.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/gaston.rb
33
+ - lib/gaston/configuration.rb
34
+ - lib/gaston/store.rb
35
+ - lib/gaston/version.rb
36
+ has_rdoc: true
37
+ homepage: https://github.com/chatgris/gaston
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.6.2
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: ! '[Dead simple Ruby config store.]'
61
+ test_files: []