configuratrilla 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ require "configuratrilla/nil"
2
+ require "configuratrilla/config"
3
+ require "configuratrilla/version"
@@ -0,0 +1,39 @@
1
+ module Configuratrilla
2
+ class Config
3
+
4
+ def initialize(parent = nil, &block)
5
+ @parent = parent
6
+ @values = {}
7
+ instance_eval(&block) if block_given?
8
+ end
9
+
10
+ def to_ary(*args)
11
+ raise NoMethodError
12
+ end
13
+
14
+ def to_hash
15
+ @values.inject({}) do |memo,(k,v)|
16
+ memo.merge(k => v.is_a?(Configuratrilla::Config) ? v.to_hash : v)
17
+ end
18
+ end
19
+
20
+ def method_missing(method_id, *args, &block)
21
+ raise "Too many arguments" if args.size > 1
22
+ if method_id.to_s[-1, 1] == "="
23
+ @values.merge!({method_id.to_s[0..-2] => args.first})
24
+ args.first
25
+ elsif args.size == 1
26
+ @values.merge!({method_id.to_s => args.first})
27
+ args.first
28
+ elsif block_given?
29
+ new_conf = self.class.new(self)
30
+ @values.merge!({method_id.to_s => new_conf})
31
+ new_conf.instance_eval(&block)
32
+ elsif @values.keys.include? method_id.to_s
33
+ @values[method_id.to_s]
34
+ else
35
+ Nil.new(self, method_id.to_s)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ module Configuratrilla
2
+ class Nil
3
+ def initialize(parent, method)
4
+ @parent = parent
5
+ @previous_method = method
6
+ end
7
+
8
+ def inspect
9
+ self.to_s
10
+ end
11
+
12
+ %w{nil? rationalize to_a to_c to_f to_i to_r | & ^ == != ! === eql? equal? to_ary}.each do |m|
13
+ define_method m do |*args|
14
+ nil.send(m,*args)
15
+ end
16
+ end
17
+
18
+ def method_missing(method_id, *args, &block)
19
+ new_conf = @parent.class.new(@parent)
20
+ values = @parent.instance_variable_get(:@values)
21
+ values.merge!(@previous_method => new_conf)
22
+ new_conf.public_send(method_id, *args, &block)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Configuratrilla
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configuratrilla
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anton Versal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Allows to set configuration files with ruby in free and easy style.
15
+ email: ant.ver@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/configuratrilla/config.rb
21
+ - lib/configuratrilla/nil.rb
22
+ - lib/configuratrilla/version.rb
23
+ - lib/configuratrilla.rb
24
+ homepage: http://github.com/antonversal/configuratrilla
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.25
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: New elastic way to create configuration
48
+ test_files: []