sinatra-config-file 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +42 -0
  2. data/lib/sinatra/config_file.rb +22 -0
  3. metadata +102 -0
@@ -0,0 +1,42 @@
1
+ Sinatra::ConfigFile
2
+ ===================
3
+
4
+ Adds YAML config file support to [Sinatra](http://sinatrarb.com).
5
+
6
+ Config files are expected to represent hashes. When parsing such a config file it will use set to store that value,
7
+ ignoring those directly defined in the app (not those defined by the class it inherits from, i.e. Sinatra::Base or
8
+ Sinatra::BigBand).
9
+
10
+ BigBand
11
+ -------
12
+
13
+ Sinatra::ConfigFile is part of the [BigBand](http://github.com/rkh/big_band) stack.
14
+ Check it out if you are looking for other fancy Sinatra extensions.
15
+
16
+ Example
17
+ -------
18
+
19
+ require "sinatra"
20
+ require "sinatra/config_file"
21
+
22
+ configure do
23
+ set :foo, "bar"
24
+ config_file "settings.yml" # general settings
25
+ config_file "#{environment}.settings.yml" # environment specific settings
26
+ foo # => "bar" (no matter what you put in your config file)
27
+ end
28
+
29
+ Now you could write in your settings.yml:
30
+
31
+ ---
32
+ server: [thin, webrick] # use only thin or webrick for #run!
33
+ public: /var/www # load public files from /var/www
34
+ port: 8080 # run on port 8080
35
+ foo: baz
36
+ database:
37
+ adapter: sqlite
38
+
39
+ In you development.settings.yml:
40
+
41
+ database:
42
+ db_file: development.db
@@ -0,0 +1,22 @@
1
+ require "sinatra/base"
2
+ require "sinatra/sugar"
3
+ require "yaml"
4
+
5
+ module Sinatra
6
+ module ConfigFile
7
+ def self.registered(klass)
8
+ klass.register Sugar
9
+ end
10
+
11
+ def config_file(*paths)
12
+ paths.each do |pattern|
13
+ files = root_glob(pattern.to_s)
14
+ files.each { |f| YAML.load_file(f).each_pair { |k,v| set k, v unless methods(false).any? { |m| m.to_s = k.to_s } } }
15
+ warn "WARNING: could not load config file #{pattern}" if files.empty?
16
+ end
17
+ end
18
+ end
19
+
20
+ register ConfigFile
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-config-file
3
+ version: &id001 !ruby/object:Gem::Version
4
+ version: 0.4.0.a
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-15 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: monkey-lib
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - *id001
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: sinatra-sugar
26
+ type: :runtime
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "="
31
+ - *id001
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: sinatra-test-helper
35
+ type: :development
36
+ version_requirement:
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "="
40
+ - *id001
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: sinatra
44
+ type: :runtime
45
+ version_requirement:
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.9.4
51
+ version:
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ type: :development
55
+ version_requirement:
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.0
61
+ version:
62
+ description: Load Sinatra settings from a yaml file (part of BigBand).
63
+ email: konstantin.mailinglists@googlemail.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files: []
69
+
70
+ files:
71
+ - lib/sinatra/config_file.rb
72
+ - README.md
73
+ has_rdoc: yard
74
+ homepage: http://github.com/rkh/sinatra-config-file
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">"
91
+ - !ruby/object:Gem::Version
92
+ version: 1.3.1
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.5
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Load Sinatra settings from a yaml file (part of BigBand).
101
+ test_files: []
102
+