stephencelis-app 0.1.2 → 0.2.0
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/History.txt +12 -0
- data/Manifest.txt +3 -2
- data/README.rdoc +12 -0
- data/generators/app_config/app_config_generator.rb +26 -1
- data/generators/app_config/templates/app.yml +1 -3
- data/install.rb +1 -1
- data/lib/app.rb +38 -17
- data/test/app_test.rb +34 -29
- data/test/fixtures/app.yml +9 -0
- data/test/fixtures/app/authenticate.yml +4 -0
- data/test/fixtures/app/authenticate/basic/config.yml +3 -0
- metadata +7 -6
- data/init.rb +0 -3
- data/uninstall.rb +0 -7
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 0.2.0 / 2009-04-17
|
2
|
+
|
3
|
+
* 2 major enhancements
|
4
|
+
|
5
|
+
* Option to modular configuration files (from "config/app/**/*.yml").
|
6
|
+
* App.name is now App.to_s (overriding the name is cool, but dangerous).
|
7
|
+
|
8
|
+
* 1 minor enhancement
|
9
|
+
|
10
|
+
* Removed superfluous "init" and "uninstall" files (handle load errors more
|
11
|
+
gracefully in "app", and let "script/destroy" do its thing).
|
12
|
+
|
1
13
|
=== 0.1.2 / 2009-04-02
|
2
14
|
|
3
15
|
* 1 minor enhancement
|
data/Manifest.txt
CHANGED
@@ -4,8 +4,9 @@ README.rdoc
|
|
4
4
|
Rakefile
|
5
5
|
generators/app_config/app_config_generator.rb
|
6
6
|
generators/app_config/templates/app.yml
|
7
|
-
init.rb
|
8
7
|
install.rb
|
9
8
|
lib/app.rb
|
10
9
|
test/app_test.rb
|
11
|
-
|
10
|
+
test/fixtures/app/authenticate/basic/config.yml
|
11
|
+
test/fixtures/app/authenticate.yml
|
12
|
+
test/fixtures/app.yml
|
data/README.rdoc
CHANGED
@@ -47,6 +47,18 @@ Sugar, sugar, sugar.
|
|
47
47
|
|
48
48
|
Let's not overdo it, though. <tt>App.apis.flickr</tt> just doesn't look right.
|
49
49
|
|
50
|
+
If your "app.yml" gets out of hand, modularize:
|
51
|
+
|
52
|
+
# config/app/authenticate.yml
|
53
|
+
---
|
54
|
+
username: password
|
55
|
+
|
56
|
+
# (elsewhere)
|
57
|
+
App::Authenticate["username"] # => "password"
|
58
|
+
|
59
|
+
|
60
|
+
Namespaces avoid collisions.
|
61
|
+
|
50
62
|
|
51
63
|
== REQUIREMENTS
|
52
64
|
|
@@ -1,7 +1,32 @@
|
|
1
1
|
class AppConfigGenerator < Rails::Generator::Base
|
2
2
|
def manifest
|
3
3
|
record do |m|
|
4
|
-
|
4
|
+
if ARGV.empty?
|
5
|
+
if File.exist? Rails.root.join("config", "app.yml")
|
6
|
+
show_banner
|
7
|
+
else
|
8
|
+
m.file "app.yml", "config/app.yml"
|
9
|
+
end
|
10
|
+
else
|
11
|
+
ARGV.each do |arg|
|
12
|
+
path = "config/app/#{arg.underscore}"
|
13
|
+
m.directory File.dirname(path)
|
14
|
+
m.file "app.yml", "#{path}.yml"
|
15
|
+
end
|
16
|
+
end
|
5
17
|
end
|
6
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def show_banner
|
23
|
+
puts "App: you already have an app.yml!"
|
24
|
+
puts
|
25
|
+
puts " Remember to pass arguments to generate new configurations:"
|
26
|
+
puts " script/generate app_config apis/twitter"
|
27
|
+
puts
|
28
|
+
puts " Generates:"
|
29
|
+
puts " config/app/apis"
|
30
|
+
puts " config/app/apis/twitter.yml"
|
31
|
+
end
|
7
32
|
end
|
data/install.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
$stdout.puts 'Run `script/generate app_config` to generate "config/app.yml".'
|
data/lib/app.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# App is your app.
|
2
2
|
#
|
3
|
-
# What would your app be without it? Still an app, but without
|
3
|
+
# What would your app be without it? Still an app, but without App.
|
4
4
|
module App
|
5
|
-
VERSION = "0.
|
6
|
-
|
7
|
-
raw_config = File.read Rails.root.join("config", "app.yml")
|
8
|
-
@@config = YAML.load(ERB.new(raw_config).result)[Rails.env].freeze
|
5
|
+
VERSION = "0.2.0"
|
9
6
|
|
7
|
+
@@config = {} # Initialize.
|
10
8
|
class << self
|
11
9
|
# Returns the application configuration hash, as defined in
|
12
10
|
# "config/app.yml".
|
@@ -26,20 +24,10 @@ module App
|
|
26
24
|
@@config if args.empty?
|
27
25
|
args.inject(@@config) { |config, arg| config[arg] }
|
28
26
|
end
|
29
|
-
|
30
|
-
alias [] config
|
31
|
-
alias __name__ name
|
32
|
-
|
33
|
-
# Returns the name of the web application, which can be overridden in
|
34
|
-
# "config/app.yml".
|
35
|
-
#
|
36
|
-
# To return the name of the module, use <tt>App.__name__</tt>.
|
37
|
-
def name
|
38
|
-
@@name ||= method_missing(:name) || File.basename(Rails.root)
|
39
|
-
end
|
27
|
+
alias [] config
|
40
28
|
|
41
29
|
def inspect
|
42
|
-
"
|
30
|
+
"#<#{name}: #{config.inspect}>"
|
43
31
|
end
|
44
32
|
|
45
33
|
private
|
@@ -48,4 +36,37 @@ module App
|
|
48
36
|
self[method.to_s, *args] || self[method, *args]
|
49
37
|
end
|
50
38
|
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
raw = File.read Rails.root.join("config", "#{name.underscore}.yml")
|
42
|
+
@@config = YAML.load(ERB.new(raw).result)[Rails.env]
|
43
|
+
rescue Errno::ENOENT => e
|
44
|
+
puts '** App: no file "config/app.yml". Run `script/generate app_config`.'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
unless __FILE__ == "(eval)"
|
49
|
+
module App
|
50
|
+
class << self
|
51
|
+
# Returns the name of the web application, which can be overridden in
|
52
|
+
# "config/app.yml".
|
53
|
+
def to_s
|
54
|
+
File.basename(Rails.root)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Iterate through other App configs and namespace them.
|
60
|
+
Dir[Rails.root.join("config", "app", "**/*.yml")].sort.each do |config|
|
61
|
+
name = config.gsub(/#{Rails.root.join("config")}\/|\.yml/) {}.classify
|
62
|
+
|
63
|
+
# Recognize all parents.
|
64
|
+
line = name.split("::")
|
65
|
+
line.inject(line.shift) do |parentage, descendant|
|
66
|
+
eval "module #{parentage}; end"
|
67
|
+
"#{parentage}::#{descendant}"
|
68
|
+
end
|
69
|
+
|
70
|
+
eval File.read(__FILE__).sub "module App", "module #{name}"
|
71
|
+
end
|
51
72
|
end
|
data/test/app_test.rb
CHANGED
@@ -5,38 +5,29 @@ require 'active_support/test_case'
|
|
5
5
|
require 'mocha'
|
6
6
|
require 'erb'
|
7
7
|
|
8
|
-
# Mock
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
# Mock!
|
9
|
+
module Rails
|
10
|
+
def self.root
|
11
|
+
self
|
12
|
+
end
|
13
|
+
def self.join(*args)
|
14
|
+
args.shift # No "config" dir, OK?
|
15
|
+
File.expand_path File.join(File.dirname(__FILE__), "fixtures", *args)
|
16
|
+
end
|
17
|
+
def self.env
|
18
|
+
"development"
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
---
|
22
|
-
development:
|
23
|
-
loaded_at: <%= Time.now.iso8601 %>
|
24
|
-
username: Stephen
|
25
|
-
password: frobozz
|
26
|
-
apis:
|
27
|
-
braintree:
|
28
|
-
:login: testapi
|
29
|
-
:password: password1
|
30
|
-
YAML
|
31
|
-
|
22
|
+
# And load!
|
32
23
|
require 'app'
|
33
24
|
|
34
25
|
class AppTest < ActiveSupport::TestCase
|
35
|
-
test "
|
36
|
-
assert_equal "
|
37
|
-
assert_equal "
|
38
|
-
assert_equal "
|
39
|
-
assert_equal "
|
26
|
+
test "should access many ways" do
|
27
|
+
assert_equal "Welcome!", App.config["welcome_message"]
|
28
|
+
assert_equal "Welcome!", App.config("welcome_message")
|
29
|
+
assert_equal "Welcome!", App["welcome_message"]
|
30
|
+
assert_equal "Welcome!", App.welcome_message
|
40
31
|
|
41
32
|
assert_equal "testapi", App.config["apis"]["braintree"][:login]
|
42
33
|
assert_equal "testapi", App.config("apis", "braintree", :login)
|
@@ -44,12 +35,26 @@ class AppTest < ActiveSupport::TestCase
|
|
44
35
|
assert_equal "testapi", App.apis("braintree", :login)
|
45
36
|
end
|
46
37
|
|
47
|
-
test "
|
38
|
+
test "should parse ERB" do
|
48
39
|
assert_instance_of Time, App.loaded_at
|
49
40
|
end
|
50
41
|
|
51
|
-
test "
|
42
|
+
test "should accept boolean keys" do
|
43
|
+
assert !App.process_payments?
|
44
|
+
end
|
45
|
+
|
46
|
+
test "should infer App.name" do
|
52
47
|
File.stubs(:basename).returns "root"
|
53
|
-
assert_equal "root", App.
|
48
|
+
assert_equal "root", App.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
test "should namespace configs" do
|
52
|
+
assert_instance_of Module, App::Authenticate
|
53
|
+
assert_equal "frobozz", App::Authenticate["Stephen"]
|
54
|
+
end
|
55
|
+
|
56
|
+
test "should nest multiple levels of configs" do
|
57
|
+
assert_instance_of Module, App::Authenticate::Basic::Config
|
58
|
+
assert_equal :basic, App::Authenticate::Basic::Config.authentication_type
|
54
59
|
end
|
55
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stephencelis-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Celis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: 1.12.0
|
24
24
|
version:
|
25
25
|
description: Move the config out of your app, and into App. Sure, it's been done before, and others will do it again, but this is my way, and I like it.
|
26
26
|
email:
|
@@ -39,11 +39,12 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- generators/app_config/app_config_generator.rb
|
41
41
|
- generators/app_config/templates/app.yml
|
42
|
-
- init.rb
|
43
42
|
- install.rb
|
44
43
|
- lib/app.rb
|
45
44
|
- test/app_test.rb
|
46
|
-
-
|
45
|
+
- test/fixtures/app/authenticate/basic/config.yml
|
46
|
+
- test/fixtures/app/authenticate.yml
|
47
|
+
- test/fixtures/app.yml
|
47
48
|
has_rdoc: true
|
48
49
|
homepage:
|
49
50
|
post_install_message:
|
@@ -69,7 +70,7 @@ requirements: []
|
|
69
70
|
rubyforge_project: app
|
70
71
|
rubygems_version: 1.2.0
|
71
72
|
signing_key:
|
72
|
-
specification_version:
|
73
|
+
specification_version: 3
|
73
74
|
summary: Move the config out of your app, and into App
|
74
75
|
test_files: []
|
75
76
|
|
data/init.rb
DELETED