bragi-app 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +8 -9
  2. data/lib/app.rb +17 -13
  3. data/test/app_test.rb +4 -0
  4. metadata +3 -3
data/README.rdoc CHANGED
@@ -72,13 +72,12 @@ For new projects:
72
72
  Configure:
73
73
 
74
74
  # config/environment.rb
75
- config.gem "stephencelis-app", :lib => "app",
76
- :source => "http://gems.github.com",
77
- :version => ">= 0.2.2"
75
+ config.gem "app"
76
+
78
77
 
79
78
  And install:
80
79
 
81
- % sudo rake gems:install
80
+ % rake gems:install
82
81
 
83
82
 
84
83
  === Or as a plugin:
@@ -117,11 +116,11 @@ Namespaces avoid collisions:
117
116
 
118
117
  (c) 2009-* Stephen Celis, stephen@stephencelis.com.
119
118
 
120
- Permission is hereby granted, free of charge, to any person obtaining a copy
121
- of this software and associated documentation files (the "Software"), to deal
122
- in the Software without restriction, including without limitation the rights
123
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
124
- copies of the Software, and to permit persons to whom the Software is
119
+ Permission is hereby granted, free of charge, to any person obtaining a copy
120
+ of this software and associated documentation files (the "Software"), to deal
121
+ in the Software without restriction, including without limitation the rights
122
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
123
+ copies of the Software, and to permit persons to whom the Software is
125
124
  furnished to do so, subject to the following conditions:
126
125
 
127
126
  The above copyright notice and this permission notice shall be included in all
data/lib/app.rb CHANGED
@@ -2,9 +2,10 @@
2
2
  #
3
3
  # What would your app be without it? Still an app, but without App.
4
4
  module App
5
- VERSION = "0.2.2"
5
+ VERSION = "0.2.5"
6
+ HASH_KLASS = Object.const_defined?("HashWithIndifferentAccess") ? HashWithIndifferentAccess : Hash
6
7
 
7
- @@config = {} # Initialize.
8
+ @@config = HASH_KLASS.new # Initialize.
8
9
  class << self
9
10
  # Returns the application configuration hash, as defined in
10
11
  # "config/app.yml".
@@ -21,6 +22,7 @@ module App
21
22
  #
22
23
  # App.apis("flickr")
23
24
  def config(*args)
25
+ read_config unless @@config
24
26
  @@config if args.empty?
25
27
  args.inject(@@config) { |config, arg| config && config[arg] }
26
28
  end
@@ -35,16 +37,18 @@ module App
35
37
  def method_missing(method, *args)
36
38
  self[method.to_s, *args] || self[method, *args]
37
39
  end
38
- end
39
-
40
- begin
41
- raw = File.read Rails.root.join("config", "#{name.underscore}.yml")
42
- all = YAML.load ERB.new(raw).result
43
- @@config = all[Rails.env] || all
44
- @@config.freeze
45
- rescue Errno::ENOENT => e
46
40
 
47
- puts '** App: no file "config/app.yml". Run `script/generate app_config`.'
41
+ def read_config
42
+ begin
43
+ raw = File.read Rails.root.join("config", "#{name.underscore}.yml")
44
+ all = HASH_KLASS.new.merge(YAML.load ERB.new(raw).result)
45
+ @@config = all[Rails.env] || all
46
+ @@config.freeze
47
+ rescue Errno::ENOENT => e
48
+ puts '** App: no file "config/app.yml". Run `script/generate app_config`.'
49
+ raise e
50
+ end
51
+ end
48
52
  end
49
53
  end
50
54
 
@@ -65,11 +69,11 @@ unless __FILE__ == "(eval)"
65
69
 
66
70
  # Recognize all parents.
67
71
  line = name.split "::"
68
- line.inject line.shift do |parentage, descendant|
72
+ line.inject do |parentage, descendant|
69
73
  eval "module #{parentage}; end"
70
74
  "#{parentage}::#{descendant}"
71
75
  end
72
76
 
73
77
  eval File.read(__FILE__).sub("module App", "module #{name}")
74
78
  end
75
- end
79
+ end
data/test/app_test.rb CHANGED
@@ -65,4 +65,8 @@ class AppTest < ActiveSupport::TestCase
65
65
  test "should ignore null nested keys" do
66
66
  assert_nil App.config("missing_scope", "nested_missing_key")
67
67
  end
68
+
69
+ test "should be indifferent to class of key if possible" do
70
+ assert_equal App['welcome_message'], App[:welcome_message]
71
+ end
68
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bragi-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Celis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-06-02 00:00:00 -07:00
13
+ date: 2009-06-02 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements: []
72
72
 
73
73
  rubyforge_project: app
74
- rubygems_version: 1.2.0
74
+ rubygems_version: 1.3.1
75
75
  signing_key:
76
76
  specification_version: 3
77
77
  summary: Move the config out of your app, and into App