gaston 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 448908b2f49f029a5590af530a114fe3cb68fb44
4
- data.tar.gz: f958ef1aacd78fd6c977327fffbd384bf9f082e2
3
+ metadata.gz: 8a7ca490d6511962c5dce0fed59d3c09ff58bd16
4
+ data.tar.gz: b1b049947299d61791c885b2c615c934757f50ac
5
5
  SHA512:
6
- metadata.gz: 180fff0d9bcb83766a71520174c3f23819f968f9dc99e971bf5b9369dd5c5bc592608af4bb534368307703817da5a1a804252883f14b2227630444a938fae823
7
- data.tar.gz: 755f344be0866784bc3ec9fe04c5c75007c814ab1cde44256643c0e73b0c65f567367ea3b44be1f8f6fc535e17fe4a7229a6e2f0be49613df05dcba1ed827eb3
6
+ metadata.gz: 9777bf0fe380c53fd6e74346ccd271b8f5a71e866099512ffd8558b18097c8e93af0db91937ca553de5cfc0ec4b1f3b344db58940a3322aae51cffc65f331897
7
+ data.tar.gz: 1e98991a1df38789c6a944b1ce98507d9c1b8875f504387e6c15ae18c325d7c0f7b7fa314068c04a8c7d4138d69fd93a48a52133febeda2b2fe2bbec672f399d
data/lib/gaston.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
2
  require 'yaml'
3
3
  require 'singleton'
4
+ require 'inflecto'
4
5
 
5
6
  class Gaston
6
7
  include Singleton
7
- require 'gaston/configuration'
8
- require 'gaston/store'
9
- require 'gaston/parse'
8
+ require_relative 'gaston/configuration'
9
+ require_relative 'gaston/builder'
10
+ require_relative 'gaston/parse'
10
11
  if defined?(Rails) && defined?(Rails::Generators)
11
12
  require 'gaston/generators/gaston/config_generator'
12
13
  end
@@ -17,7 +18,7 @@ class Gaston
17
18
  # @since 0.0.1
18
19
  #
19
20
  def store
20
- @store ||= Gaston::Store.new(hash_from_files)
21
+ @store ||= Gaston::Builder.new(self.class, hash_from_files)
21
22
  end
22
23
 
23
24
  class << self
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ class Gaston
3
+ class Builder
4
+ class << self
5
+ def new(parent, hash={})
6
+ hash.each_with_object({}) do |(key, store), hsh|
7
+ if store.is_a?(Hash)
8
+ camelize = Inflecto.camelize(key)
9
+ klass = if parent.const_defined? camelize, false
10
+ Inflecto.constantize("#{parent}::#{camelize}")
11
+ else
12
+ parent.const_set camelize, Class.new(Hash)
13
+ end
14
+ store = klass[Gaston::Builder.new(klass, store)]
15
+ end
16
+ if parent.instance_methods.include? key.to_sym
17
+ warn "#{key} method already exists on #{parent}, value: #{store}"
18
+ else
19
+ hsh[key] = store
20
+ parent.send(:define_method, key, -> { store })
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class Gaston
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaston
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chatgris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-02 00:00:00.000000000 Z
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: inflecto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -33,12 +47,12 @@ files:
33
47
  - LICENSE
34
48
  - README.md
35
49
  - lib/gaston.rb
50
+ - lib/gaston/builder.rb
36
51
  - lib/gaston/configuration.rb
37
52
  - lib/gaston/generators/gaston/config_generator.rb
38
53
  - lib/gaston/generators/templates/_gaston.rb
39
54
  - lib/gaston/generators/templates/gaston/.gitkeep
40
55
  - lib/gaston/parse.rb
41
- - lib/gaston/store.rb
42
56
  - lib/gaston/version.rb
43
57
  homepage: http://chatgris.github.com/Gaston
44
58
  licenses: []
@@ -64,3 +78,4 @@ signing_key:
64
78
  specification_version: 4
65
79
  summary: Dead simple Ruby config store.
66
80
  test_files: []
81
+ has_rdoc:
data/lib/gaston/store.rb DELETED
@@ -1,42 +0,0 @@
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.each do |key, value|
13
- if hash.respond_to? key
14
- warn "#{key} method already exists on Hash, value: #{value}"
15
- else
16
- value.is_a?(Hash) ? self[key] = self.class.new(value) : self[key] = value
17
- end
18
- end
19
- end
20
-
21
- # Search into store for value.
22
- #
23
- # @param [ String || Symbol ] key store.
24
- #
25
- # @since 0.0.1
26
- #
27
- def method_missing(method, *args, &block)
28
- return self[method.to_s] if has_key? method.to_s
29
- return self[method.to_sym] if has_key? method.to_sym
30
- super
31
- end
32
-
33
- # Implement respond_to?
34
- #
35
- # @since 0.0.1
36
- #
37
- def respond_to?(method)
38
- has_key?(method.to_s) || has_key?(method.to_sym) || super
39
- end
40
-
41
- end # Store
42
- end #Gaston