dacs 0.3.0 → 0.3.1

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Devver, Inc.
1
+ Copyright (c) 2009, 2010 Devver, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -109,8 +109,11 @@ module Dacs
109
109
  defaults_source = DefaultSource.new(@defaults)
110
110
  file_source = FileSource.new(config_path, @environment)
111
111
  env_source = EnvironmentSource.new(env_var_prefix)
112
-
113
- load_values!(self.class.schema, env_source, file_source, defaults_source)
112
+ sources = []
113
+ sources << env_source
114
+ sources << file_source if file_source.readable?
115
+ sources << defaults_source
116
+ load_values!(self.class.schema, *sources)
114
117
  verify_no_missing_required_values!
115
118
  end
116
119
 
@@ -124,7 +127,8 @@ module Dacs
124
127
 
125
128
  def source(key)
126
129
  assert_key_defined!(key)
127
- configured_value.source.to_s
130
+ # TODO is there a simpler way?
131
+ Hash.instance_method(:[]).bind(self.class.instance).call(key).source.to_s
128
132
  end
129
133
 
130
134
  def [](key)
@@ -204,6 +208,16 @@ module Dacs
204
208
  end
205
209
  logger.info "Starter config file created at #{config_path}. " +
206
210
  "Please customize it to your needs."
211
+ rescue SystemCallError => error
212
+ # NOTE It is important to catch system call errors here, rather than using
213
+ # path.writable? checks. Read-only filesystems report files as having the
214
+ # "write" bit set even though writing isn't actually
215
+ # permitted. E.g. the filesystem used on Heroku. The first we'll find out
216
+ # that it's a read-only filesystem is when we try to write to it.
217
+ logger.info <<"END"
218
+ Unable to write starter config file to #{path}. The error was:
219
+ '#{error.message}'
220
+ END
207
221
  end
208
222
 
209
223
  def starter_config_content
@@ -1,8 +1,13 @@
1
1
  require 'pathname'
2
2
  require 'yaml'
3
+ require 'forwardable'
3
4
 
4
5
  module Dacs
5
6
  class FileSource
7
+ extend Forwardable
8
+
9
+ def_delegators :@path, :readable?, :exist?
10
+
6
11
  def initialize(config_path, environment)
7
12
  @path = Pathname(config_path)
8
13
  @environment = environment.to_s
@@ -28,6 +28,38 @@ module Dacs
28
28
  end
29
29
  end
30
30
 
31
+ def self.it_should_not_choke_on_file_source
32
+ it "should not write an example config file" do
33
+ AppConfig.init!(@app_name, :logger => @logger)
34
+ AppConfig.instance
35
+ (@construct+'config'+'foo_app.yml').should_not exist
36
+ end
37
+
38
+ it "should not raise an error" do
39
+ lambda do
40
+ AppConfig.init!(@app_name, :logger => @logger)
41
+ AppConfig.instance
42
+ end.should_not raise_error
43
+ end
44
+ end
45
+
46
+ context "when first initialized in a read-only filesystem" do
47
+ before do
48
+ @construct.chmod(0444)
49
+ end
50
+
51
+ it_should_not_choke_on_file_source
52
+ end
53
+
54
+ context "when first initialized with a read-only config dir" do
55
+ before do
56
+ config_dir = @construct.directory 'config'
57
+ config_dir.chmod(0444)
58
+ end
59
+
60
+ it_should_not_choke_on_file_source
61
+ end
62
+
31
63
  context "given a config file lacking the expected environment key" do
32
64
  append_before :each do
33
65
  @construct.file("config/foo_app.yml") do |f|
@@ -173,7 +205,7 @@ module Dacs
173
205
  YAML.dump({
174
206
  'development'=>{
175
207
  'bar' => 'file_bar',
176
- 'baz' => 'file_buz'
208
+ 'baz' => 'file_baz'
177
209
  }
178
210
  },
179
211
  f)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dacs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devver, Inc.
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-14 00:00:00 -05:00
12
+ date: 2010-03-22 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency