rbrc 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -24,9 +24,8 @@ Register a config file somewhere in your app
24
24
 
25
25
  require 'rbrc'
26
26
 
27
- register_config(:my_app)
27
+ Rbrc::Config.register(:my_app)
28
28
 
29
29
  Now you can access the config file values like this
30
30
 
31
- MyAppConfig.password #=> 'secret_password'
32
-
31
+ Rbrc::Config.my_app.password #=> 'secret_password'
data/lib/rbrc.rb CHANGED
@@ -1,8 +1,10 @@
1
- require 'rbrc/shortcut_class'
2
1
  require 'rbrc/registry'
3
2
  require 'rbrc/config'
4
3
 
5
4
  module Rbrc
6
5
  class ConfigFileDoesNotExistError < Exception
7
6
  end
7
+
8
+ class ConfigFileSecurityError < Exception
9
+ end
8
10
  end
data/lib/rbrc/config.rb CHANGED
@@ -3,11 +3,9 @@ require 'parseconfig'
3
3
 
4
4
  module Rbrc
5
5
  class Config
6
- def initialize(name)
6
+ def initialize(name, options={})
7
7
  @name = name
8
- raise ConfigFileDoesNotExistError unless File.exist?(file_path)
9
-
10
- init_shortcut_class
8
+ ensure_file_exists
11
9
  end
12
10
 
13
11
  def file_path
@@ -22,10 +20,26 @@ module Rbrc
22
20
  values[key.to_s]
23
21
  end
24
22
 
25
- def init_shortcut_class
26
- helper_name = "#{@name.to_s.camelize}Config".to_sym
27
- shortcut_class = Class.new(Rbrc::ShortcutClass)
28
- Object.const_set(helper_name, shortcut_class)
23
+ def ensure_file_exists
24
+ raise ConfigFileDoesNotExistError unless File.exist?(file_path)
25
+ end
26
+
27
+ def method_missing(sym, *args, &block)
28
+ return self[sym]
29
+ end
30
+
31
+ class << self
32
+
33
+ def register(config, options={})
34
+ Rbrc::Registry.register_config(config, options)
35
+ end
36
+
37
+ def method_missing(sym, *args, &block)
38
+ return Registry[sym] if Registry[sym]
39
+
40
+ super(sym, *args, &block)
41
+ end
42
+
29
43
  end
30
44
  end
31
45
  end
data/lib/rbrc/registry.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module Rbrc
2
2
  class Registry
3
3
  class << self
4
- def register_config(name)
4
+ def register_config(name, options={})
5
5
  @configs ||= {}
6
- @configs[name] = Config.new(name)
6
+ @configs[name] = Config.new(name, options)
7
7
  end
8
8
 
9
9
  def [](name)
data/lib/rbrc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rbrc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -2,45 +2,40 @@ require 'spec_helper'
2
2
 
3
3
  module Rbrc
4
4
  describe Config do
5
- before(:each) do
6
- # Note: FakeFS activated globally in spec_helper
7
- FileUtils.mkdir_p File.expand_path('~')
8
- FileUtils.touch File.expand_path('~/.foorc')
9
- FileUtils.touch File.expand_path('~/.barrc')
10
- end
11
-
12
- describe "#initialize" do
13
- it "should throw an error if the file doesn't exist" do
14
- FileUtils.rm File.expand_path('~/.foorc')
5
+ let(:root_path) { File.expand_path('../files', __FILE__) }
15
6
 
16
- lambda {
17
- Config.new(:foo)
18
- }.should raise_error Rbrc::ConfigFileDoesNotExistError
7
+ context "fake fs" do
8
+ before(:each) do
9
+ # Note: FakeFS activated globally in spec_helper
10
+ FileUtils.mkdir_p File.expand_path('~')
11
+ FileUtils.touch File.expand_path('~/.foorc')
12
+ FileUtils.touch File.expand_path('~/.barrc')
19
13
  end
20
14
 
21
- it "should activate a shortcut class for accessing config values globally" do
22
- FakeFS.deactivate!
23
- Config.any_instance.stubs(:file_path).returns('/Users/mike/work/rbrc/spec/files/foorc')
24
-
25
- Registry.register_config :foo
15
+ describe "#initialize" do
16
+ it "should throw an error if the file doesn't exist" do
17
+ FileUtils.rm File.expand_path('~/.foorc')
26
18
 
27
- FooConfig.should be_a ShortcutClass.class
19
+ lambda {
20
+ Config.new(:foo)
21
+ }.should raise_error Rbrc::ConfigFileDoesNotExistError
22
+ end
28
23
  end
29
- end
30
24
 
31
- describe "#file_path" do
32
- it "should return the path to the config file" do
33
- config = Config.new(:foo)
34
- relative_path = config.file_path.split('/').last
25
+ describe "#file_path" do
26
+ it "should return the path to the config file" do
27
+ config = Config.new(:foo)
28
+ relative_path = config.file_path.split('/').last
35
29
 
36
- relative_path.should eq '.foorc'
30
+ relative_path.should eq '.foorc'
31
+ end
37
32
  end
38
33
  end
39
34
 
40
35
  describe "#values" do
41
36
  it "should return values from the config file" do
42
37
  FakeFS.deactivate!
43
- Config.any_instance.stubs(:file_path).returns('/Users/mike/work/rbrc/spec/files/foorc')
38
+ Config.any_instance.stubs(:file_path).returns("#{root_path}/foorc")
44
39
 
45
40
  config = Config.new(:foo)
46
41
  expected_values = {
@@ -54,12 +49,42 @@ module Rbrc
54
49
  describe "#[]" do
55
50
  it "should return for specified config key" do
56
51
  FakeFS.deactivate!
57
- Config.any_instance.stubs(:file_path).returns('/Users/mike/work/rbrc/spec/files/foorc')
52
+ Config.any_instance.stubs(:file_path).returns("#{root_path}/foorc")
58
53
 
59
54
  Registry.register_config :foo
60
55
 
61
- FooConfig.moof.should == 'doof'
62
- FooConfig.foof.should == 'toof'
56
+ Config.foo['moof'].should == 'doof'
57
+ Config.foo['foof'].should == 'toof'
58
+ end
59
+ end
60
+
61
+ describe "#method_missing" do
62
+ it "should serve up each config as an named attribute" do
63
+ FakeFS.deactivate!
64
+ Config.any_instance.stubs(:file_path).returns("#{root_path}/foorc")
65
+
66
+ Config.foo.moof.should eq 'doof'
67
+ Config.foo.foof.should eq 'toof'
68
+ end
69
+ end
70
+
71
+ describe "self#method_missing" do
72
+ it "should serve up each config as an named attribute" do
73
+ FakeFS.deactivate!
74
+ Config.any_instance.stubs(:file_path).returns("#{root_path}/foorc")
75
+
76
+ Config.foo.should be_a Config
77
+ Config.foo.should be_a Config
78
+ end
79
+ end
80
+
81
+ describe "self#register" do
82
+ it "should expose a shortcut to Registry.register_config" do
83
+ FakeFS.deactivate!
84
+ Config.any_instance.stubs(:file_path).returns("#{root_path}/foorc")
85
+
86
+ Config.register(:foo)
87
+ Registry[:foo].should be_a Config
63
88
  end
64
89
  end
65
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parseconfig
16
- requirement: &70154352504120 !ruby/object:Gem::Requirement
16
+ requirement: &70113739622120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.5.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70154352504120
24
+ version_requirements: *70113739622120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70154352502920 !ruby/object:Gem::Requirement
27
+ requirement: &70113739621360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70154352502920
35
+ version_requirements: *70113739621360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &70154352501640 !ruby/object:Gem::Requirement
38
+ requirement: &70113739620640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.6.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70154352501640
46
+ version_requirements: *70113739620640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70154352500820 !ruby/object:Gem::Requirement
49
+ requirement: &70113739592820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70154352500820
57
+ version_requirements: *70113739592820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-rspec
60
- requirement: &70154352499360 !ruby/object:Gem::Requirement
60
+ requirement: &70113739591960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.4.5
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70154352499360
68
+ version_requirements: *70113739591960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakefs
71
- requirement: &70154352497460 !ruby/object:Gem::Requirement
71
+ requirement: &70113739591220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70154352497460
79
+ version_requirements: *70113739591220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: mocha
82
- requirement: &70154352495680 !ruby/object:Gem::Requirement
82
+ requirement: &70113739590600 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 0.10.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70154352495680
90
+ version_requirements: *70113739590600
91
91
  description: App config helpers for ruby apps.
92
92
  email:
93
93
  - mikebannister@gmail.com
@@ -97,7 +97,6 @@ extra_rdoc_files: []
97
97
  files:
98
98
  - lib/rbrc/config.rb
99
99
  - lib/rbrc/registry.rb
100
- - lib/rbrc/shortcut_class.rb
101
100
  - lib/rbrc/version.rb
102
101
  - lib/rbrc.rb
103
102
  - Rakefile
@@ -120,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
119
  version: '0'
121
120
  segments:
122
121
  - 0
123
- hash: -2253627055374088253
122
+ hash: -3776148695996531253
124
123
  required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  none: false
126
125
  requirements:
@@ -129,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
128
  version: '0'
130
129
  segments:
131
130
  - 0
132
- hash: -2253627055374088253
131
+ hash: -3776148695996531253
133
132
  requirements: []
134
133
  rubyforge_project:
135
134
  rubygems_version: 1.8.10
@@ -1,26 +0,0 @@
1
- module Rbrc
2
- class ShortcutClass
3
- class << self
4
- def method_missing(sym, *args, &block)
5
- @sym = sym
6
- if config_exists? and
7
- return config[sym]
8
- end
9
- super(sym, *args, &block)
10
- end
11
-
12
- # get :Foo from FooConfig
13
- def config_name
14
- self.name.slice(0..-7).underscore.to_sym
15
- end
16
-
17
- def config
18
- Registry[config_name]
19
- end
20
-
21
- def config_exists?
22
- !!config
23
- end
24
- end
25
- end
26
- end