optionsful 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -44,16 +44,22 @@ Link: "<http://localhost:3000/api/posts/1/comments>; type=text/html; rel=help"
44
44
  </pre>
45
45
  ~Note the empty line which is part of the HTTP protocol.~
46
46
 
47
- h3. Well, I agree. Telnet is the geekest way.. ;-)
47
+ h3. I agree. Telnet is the geekest way.. ;-)
48
48
 
49
- This is for testing purposes. You would like better to use an HTTP client software. I use "HTTP Client":http://ditchnet.org/httpclient/ on Mac OS X. And on real life, There is a lot of possible usage scenarios.
49
+ For testing purposes you would like better using an HTTP client software.
50
+ I use "HTTP Client":http://ditchnet.org/httpclient/ on my Mac OS X and "cURL":http://curl.haxx.se/ anywhere else.
51
+ And on real life, you are free to create your own usage scenario.
50
52
 
51
53
  h1. INSTALLATION:
52
54
 
53
55
  # Change directory to your Ruby on Rails web application,
54
- # Add gem dependency to @config/application.rb@:
55
- <pre>config.gem "optionsful"</pre>
56
- # To install it, run @rake gems:install@ or:
56
+ # Add gem dependency to @Gemfile@:
57
+ <pre>gem 'optionsful'</pre>
58
+ # Add it to the stack at @config/application.rb@:
59
+ <pre>class Application < Rails::Application
60
+ config.middleware.use ::Baurets::Optionsful::Server
61
+ ...</pre>
62
+ # To install it, run @bundle install@ or:
57
63
  <pre>$ gem install optionsful</pre>
58
64
  # Enjoy! And give feedback! :)
59
65
 
@@ -71,33 +77,40 @@ h2. Setting up the @Link@ header
71
77
 
72
78
  h3. Possible values and effects: (the bold values are the default ones)
73
79
 
74
- ** @link@
75
- *** *false*: Do not include any "Link" header in the response.
76
- *** true: Do include it. Build the URI based on the 'host', 'base_path', and 'propagate' values, explained below.
80
+ * @link@
81
+ ** *false*: Do not include any "Link" header in the response.
82
+ ** true: Do include it. Build the URI based on the 'host', 'base_path', and 'propagate' values, explained below.
77
83
 
78
- ** @host@
79
- *** *auto*: Use the application's own address and port.
80
- *** private.mycompany.com: point it to another location. For instance: www.baurets.net. (Do not include http://).
84
+ * @host@
85
+ ** *auto*: Use the application's own address and port.
86
+ ** private.mycompany.com: point it to another location. For instance: www.baurets.net. (Do not include http://).
81
87
 
82
88
 
83
- ** @base_path@
84
- *** the path to be appended to the host. Default is */api*.
85
- *** to disable it, use @/@
86
- *** Example: /my_company/my_project/resources/api
89
+ * @base_path@
90
+ ** the path to be appended to the host. Default is */api*.
91
+ ** to disable it, use @/@
92
+ ** Example: /my_company/my_project/resources/api
87
93
 
88
- ** @propagate@
89
- *** false: Do not append the request's path info to the URI.
90
- *** *true*: Do append it, as it is.
94
+ * @propagate@
95
+ ** false: Do not append the request's path info to the URI.
96
+ ** *true*: Do append it, as it is.
91
97
 
92
- Generated Link example:
93
- (link: true, host: auto)
98
+ * Generated Link example:
99
+ (*link: true*, *host: auto*)
94
100
  <pre>Link: "<http://localhost:3000/api/posts/1/comments>; type=text/html; rel=help"</pre>
95
- * *Note*: @Allow@ and @Link@ are expected headers on a response to an HTTP OPTIONS request.
101
+
102
+ * *Note*: @Allow@ *and* @Link@ *are expected headers on a response to an HTTP OPTIONS request.*
96
103
 
97
104
  h2. KNOWN ISSUES
98
105
  * Rails route recognition still need some work
99
106
  * Platform: *Rails 3.0.0.rc* !!!
100
107
 
108
+ h2. Development notes
109
+
110
+ * To bleed on the edge, at your Rails 3 application's @Gemfile@:
111
+ <pre>gem 'optionsful', :path => "~/your_workspace/optionsful/"</pre>
112
+
113
+
101
114
  h2. Get involved
102
115
  * Mailing list: http://groups.google.com/group/optionsful
103
116
  * Bug tracker : http://kayaman.lighthouseapp.com/projects/56438-optionsful/overview
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "optionsful"
8
8
  gem.summary = %Q{Support HTTP OPTIONS verb on your Rails 3 app.}
9
- gem.description = %Q{Help building RESTful web services by supporting the HTTP OPTIONS verb on Ruby on Rails applications.}
9
+ gem.description = %Q{Build RESTful web services supporting the HTTP OPTIONS verb on Ruby on Rails applications.}
10
10
  gem.email = "kayaman@baurets.net"
11
11
  gem.homepage = "http://github.com/kayaman/optionsful"
12
12
  gem.authors = ["Marco Antonio Gonzalez Junior"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -0,0 +1,33 @@
1
+ require 'yaml'
2
+
3
+ module Baurets
4
+ module Optionsful
5
+ class Configurator
6
+
7
+ DEFAULT = { :link => false, :host => 'auto', :base_path => "/api", :propagate => true }
8
+
9
+ def configure!
10
+ file = File.join(Rails.root, 'config', 'optionsful.yml')
11
+ configuration = load_yaml(file, Rails.env.to_sym) if File.exist?(file)
12
+ configuration = DEFAULT if configuration.nil?
13
+ configuration
14
+ end
15
+
16
+ private
17
+
18
+ def load_yaml(file, environment)
19
+ configuration = nil
20
+ begin
21
+ envs = YAML::load_file(file)
22
+ raise "Could not parse the YAML." if (envs.empty? or (not envs.kind_of?(Hash)))
23
+ envs = envs.symbolize_keys if envs
24
+ configuration = envs[environment].symbolize_keys if (envs && envs[environment])
25
+ rescue
26
+ configuration = nil
27
+ end
28
+ configuration
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -7,7 +7,7 @@ module Baurets
7
7
  #
8
8
  def initialize(app)
9
9
  @app = app
10
- @config = Config.new
10
+ @config = Configurator.new.configure!
11
11
  end
12
12
 
13
13
  ##
@@ -36,29 +36,29 @@ module Baurets
36
36
  unless allows.empty?
37
37
  headers.merge!({"Allow" => allows})
38
38
  status = 204
39
- if @config.link == true
39
+ if @config[:link] == true
40
40
  headers.merge!({"Link" => build_link_header})
41
41
  end
42
42
  else
43
43
  status = 404
44
- body = "Not found"
44
+ body = "Not found."
45
45
  end
46
46
  [status, headers, body]
47
47
  end
48
48
 
49
49
  def build_link_header
50
50
  link = ""
51
- if @config.host == "auto"
51
+ if @config[:host] == "auto"
52
52
  server_name = @env["SERVER_NAME"]
53
53
  server_port = @env["SERVER_PORT"]
54
54
  link = "\"<http://#{server_name}:#{server_port}"
55
55
  else
56
- link = "\"<http://#{@config.host}"
56
+ link = "\"<http://#{@config[:host]}"
57
57
  end
58
- unless @config.base_path.empty?
59
- link += @config.base_path unless @config.base_path == "/"
58
+ unless @config[:base_path].empty?
59
+ link += @config[:base_path] unless @config[:base_path] == "/"
60
60
  end
61
- if @config.propagate == true
61
+ if @config[:propagate] == true
62
62
  link += @env["PATH_INFO"]
63
63
  end
64
64
  link += ">; type=text/html; rel=help\""
data/lib/optionsful.rb CHANGED
@@ -1,7 +1,3 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
-
5
1
  ##
6
2
  # Baurets Software
7
3
  # kayaman@baurets.net
@@ -10,12 +6,15 @@ module Baurets
10
6
  module Optionsful
11
7
  autoload :Server, 'baurets/optionsful/server'
12
8
  autoload :Introspections, 'baurets/optionsful/introspections'
13
- autoload :Config, 'baurets/optionsful/config'
9
+ autoload :Configurator, 'baurets/optionsful/configurator'
14
10
 
15
11
  LIB_ROOT = File.dirname(__FILE__)
16
12
  end
17
13
  end
18
14
 
15
+
16
+ require 'rubygems'
17
+ require 'rake'
19
18
  unless Rake::Task.task_defined? "optionsful:yml"
20
19
  load File.join(Baurets::Optionsful::LIB_ROOT, '..', 'tasks', 'optionsful.rake')
21
20
  end
data/optionsful.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{optionsful}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marco Antonio Gonzalez Junior"]
12
12
  s.date = %q{2010-08-07}
13
- s.description = %q{Help building RESTful web services by supporting the HTTP OPTIONS verb on Ruby on Rails applications.}
13
+ s.description = %q{Build RESTful web services supporting the HTTP OPTIONS verb on Ruby on Rails applications.}
14
14
  s.email = %q{kayaman@baurets.net}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -27,17 +27,20 @@ Gem::Specification.new do |s|
27
27
  "features/optionsful.feature",
28
28
  "features/step_definitions/optionsful3_steps.rb",
29
29
  "features/support/env.rb",
30
- "lib/baurets/optionsful/config.rb",
30
+ "lib/baurets/optionsful/configurator.rb",
31
31
  "lib/baurets/optionsful/introspections.rb",
32
32
  "lib/baurets/optionsful/server.rb",
33
33
  "lib/optionsful.rb",
34
34
  "optionsful.gemspec",
35
35
  "rails/init.rb",
36
- "samples/optionsful.yml.sample",
36
+ "samples/optionsful.yml",
37
37
  "samples/optionsful_bug.yml",
38
38
  "samples/optionsful_true.yml",
39
+ "samples/optionsful_true_custom.yml",
40
+ "samples/optionsful_true_custom_base_path.yml",
41
+ "samples/optionsful_true_custom_propagate.yml",
39
42
  "spec/fake_app.rb",
40
- "spec/optionsful_config_spec.rb",
43
+ "spec/optionsful_configurator_spec.rb",
41
44
  "spec/optionsful_server_spec.rb",
42
45
  "spec/spec.opts",
43
46
  "spec/spec_helper.rb",
@@ -51,7 +54,7 @@ Gem::Specification.new do |s|
51
54
  s.summary = %q{Support HTTP OPTIONS verb on your Rails 3 app.}
52
55
  s.test_files = [
53
56
  "spec/fake_app.rb",
54
- "spec/optionsful_config_spec.rb",
57
+ "spec/optionsful_configurator_spec.rb",
55
58
  "spec/optionsful_server_spec.rb",
56
59
  "spec/spec_helper.rb"
57
60
  ]
@@ -0,0 +1,13 @@
1
+ # Optionsful custom settings
2
+
3
+ development: &default
4
+ link: false
5
+ host: auto
6
+ base_path: /api
7
+ propagate: true
8
+
9
+ test:
10
+ <<: *default
11
+
12
+ production:
13
+ <<: *default
@@ -1,20 +1,11 @@
1
- # Optionsful custom settings
2
-
3
- # Link header configuration
4
- development:
5
- link: true
6
- host: auto
7
- base_path: /api
8
- propagate: true
1
+ development:
2
+ <<: *test
9
3
 
10
- test:
4
+ test: &test
11
5
  link: true
12
6
  host: auto
13
7
  base_path: /api
14
8
  propagate: false
15
9
 
16
10
  production:
17
- link: true
18
- host: auto
19
- base_path: /api
20
- propagate: false
11
+ <<: *test
@@ -0,0 +1,11 @@
1
+ development:
2
+ <<: *test
3
+
4
+ test: &test
5
+ link: true
6
+ host: www.baurets.net
7
+ base_path: /api
8
+ propagate: false
9
+
10
+ production:
11
+ <<: *test
@@ -0,0 +1,11 @@
1
+ development:
2
+ <<: *test
3
+
4
+ test: &test
5
+ link: true
6
+ host: www.baurets.net
7
+ base_path: /private/api
8
+ propagate: false
9
+
10
+ production:
11
+ <<: *test
@@ -0,0 +1,11 @@
1
+ development:
2
+ <<: *test
3
+
4
+ test: &test
5
+ link: true
6
+ host: www.baurets.net
7
+ base_path: /api
8
+ propagate: true
9
+
10
+ production:
11
+ <<: *test
data/spec/fake_app.rb CHANGED
@@ -2,5 +2,7 @@ require 'rubygems'
2
2
  require 'rails'
3
3
 
4
4
  class FakeApp < Rails::Application
5
+
6
+ Rails.env = "test"
5
7
 
6
8
  end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Baurets::Optionsful::Configurator do
4
+
5
+ include Rack::Test::Methods
6
+
7
+ context "Configuration do handle the custom settings" do
8
+
9
+ describe "if no directions were explicitly given, act as using the default settings" do
10
+
11
+ before do
12
+ delete_configuration_file
13
+ end
14
+
15
+ it "the Link header generation must be disabled" do
16
+ configuration[:link].should be false
17
+ end
18
+
19
+ end
20
+
21
+ describe "when there is a custom configuration file, load the settings from it" do
22
+
23
+ before(:each) do
24
+ FileUtils.rm [File.join(Rails.root, 'config', 'optionsful.yml')] if File.exist? File.join(Rails.root, 'config', 'optionsful.yml')
25
+ end
26
+
27
+ it "by default, the Link header generation must be disabled" do
28
+ simulate_rake_yml_task
29
+ configuration[:link].should be false
30
+ end
31
+
32
+ it "the Link header generation must be disabled (file looks corrupted!)" do
33
+ FileUtils.cp File.join(Rails.root, 'samples', 'optionsful_bug.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
34
+ configuration[:link].should be false
35
+ end
36
+
37
+ it "the Link header generation must be enabled" do
38
+ FileUtils.cp File.join(Rails.root, 'samples', 'optionsful_true.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
39
+ configuration[:link].should be true
40
+ end
41
+
42
+ it "if the Link header generation is enabled, host value must be set" do
43
+ FileUtils.cp File.join(Rails.root, 'samples', 'optionsful_true.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
44
+ configuration[:link].should be true
45
+ configuration[:host].empty?.should_not be true
46
+ end
47
+
48
+ it "if the Link header generation is enabled, host value accepts 'auto'" do
49
+ FileUtils.cp File.join(Rails.root, 'samples', 'optionsful_true.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
50
+ configuration[:link].should be true
51
+ configuration[:host].empty?.should_not be true
52
+ configuration[:host].should == "auto"
53
+ end
54
+
55
+ after(:each) do
56
+ delete_configuration_file
57
+ end
58
+
59
+ after(:all) do
60
+ FileUtils.rm [File.join(Rails.root, 'config', 'optionsful.yml')] if File.exist? File.join(Rails.root, 'config', 'optionsful.yml')
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -398,11 +398,10 @@ describe "Optionsful" do
398
398
  rails_app.routes.draw do
399
399
  resources :posts
400
400
  end
401
- ::Baurets::Optionsful::Config.new
401
+ delete_configuration_file
402
402
  end
403
403
 
404
404
  it "if no directions were given" do
405
- Baurets::Optionsful::Config.new(nil, {:link => false})
406
405
  response = http_options_request("/posts")
407
406
  validate_response(response)
408
407
  response[0].should be 204
@@ -421,51 +420,60 @@ describe "Optionsful" do
421
420
  rails_app.routes.draw do
422
421
  resources :posts
423
422
  end
423
+ delete_configuration_file
424
+ end
425
+
426
+ before(:each) do
427
+ delete_configuration_file
424
428
  end
425
429
 
426
430
  it "the Link header MUST be quoted if it contains a semicolon or comma" do
427
- Baurets::Optionsful::Config.new(nil, {:link => true})
431
+ copy_configuration_file('optionsful_true.yml')
428
432
  response = http_options_request("/posts")
429
433
  validate_response(response)
430
434
  response[0].should be 204
431
435
  link = response[1]["Link"]
432
436
  link.should match /\A\".+\"\z/
433
437
  end
434
-
438
+
435
439
  it "the Link header may use its very current host" do
436
- Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'auto'})
440
+ copy_configuration_file('optionsful_true.yml')
437
441
  response = http_options_request("/posts")
438
442
  validate_response(response)
439
443
  response[0].should be 204
440
444
  link = response[1]["Link"]
441
445
  link.should match /\A\"<http:\/\/localhost.+\"\z/
442
446
  end
443
-
447
+
444
448
  it "the Link header may use a custom host value" do
445
- Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'www.baurets.net'})
449
+ copy_configuration_file('optionsful_true_custom.yml')
446
450
  response = http_options_request("/posts")
447
451
  validate_response(response)
448
452
  response[0].should be 204
449
453
  link = response[1]["Link"]
450
454
  link.should match /\A\"<http:\/\/www.baurets.net.+\"\z/
451
455
  end
452
-
456
+
453
457
  it "the Link header may use a custom base path value" do
454
- Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'www.baurets.net', :base_path => "/private/api/"})
458
+ copy_configuration_file('optionsful_true_custom_base_path.yml')
455
459
  response = http_options_request("/posts")
456
460
  validate_response(response)
457
461
  response[0].should be 204
458
462
  link = response[1]["Link"]
459
- link.should match /\A\"<http:\/\/www.baurets.net\/private\/api\/.+\"\z/
463
+ link.should match /\A\"<http:\/\/www.baurets.net\/private\/api.+\"\z/
460
464
  end
461
-
465
+
462
466
  it "the Link header may propagate original path info" do
463
- Baurets::Optionsful::Config.new(nil, {:link => true, :host => 'www.baurets.net', :base_path => "/private/api/", :propagate => true})
467
+ copy_configuration_file('optionsful_true_custom_propagate.yml')
464
468
  response = http_options_request("/posts")
465
469
  validate_response(response)
466
470
  response[0].should be 204
467
471
  link = response[1]["Link"]
468
- link.should match /\A\"<http:\/\/www.baurets.net\/private\/api\/\/posts.+\"\z/
472
+ link.should match /\A\"<http:\/\/www.baurets.net\/api\/posts.+\"\z/
473
+ end
474
+
475
+ after(:each) do
476
+ delete_configuration_file
469
477
  end
470
478
 
471
479
  after(:all) do
data/spec/spec_helper.rb CHANGED
@@ -80,4 +80,22 @@ DEFAULT_ENV = { "rack.version" => Rack::VERSION, "rack.input" => StringIO.new, "
80
80
  def rails_app
81
81
  app = FakeApp.initialize!
82
82
  app
83
- end
83
+ end
84
+
85
+ def configuration
86
+ configurator = Baurets::Optionsful::Configurator.new
87
+ configuration = configurator.configure!
88
+ configuration
89
+ end
90
+
91
+ def delete_configuration_file
92
+ FileUtils.rm [File.join(Rails.root, 'config', 'optionsful.yml')] if File.exist? File.join(Rails.root, 'config', 'optionsful.yml')
93
+ end
94
+
95
+ def copy_configuration_file(name)
96
+ FileUtils.cp File.join(Rails.root, 'samples', name), File.join(Rails.root, 'config', 'optionsful.yml')
97
+ end
98
+
99
+ def simulate_rake_yml_task
100
+ FileUtils.cp File.join(Rails.root, 'samples', 'optionsful.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
101
+ end
@@ -2,10 +2,10 @@ require 'fileutils'
2
2
  require 'rake'
3
3
 
4
4
  namespace :optionsful do
5
- desc "Install 'config/optionsful.yml'"
5
+ desc "Enable Optionsful custom configurations by creating the file 'config/optionsful.yml'"
6
6
  task :yml do
7
- FileUtils.cp File.join(Baurets::Optionsful::LIB_ROOT, '..','samples', 'optionsful.yml.sample'), File.join(Rails.root, 'config', 'optionsful.yml')
8
- puts "\nNow you are able to configure Link hader generation settings"
9
- puts "\nEdit the file 'config/optionsful.yml' on your Rails application."
7
+ FileUtils.cp File.join(Baurets::Optionsful::LIB_ROOT, '..','samples', 'optionsful.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
8
+ puts "\nNow you are able to configure Optionsful Link hader generation settings"
9
+ puts "\nEdit the file 'config/optionsful.yml' at your Rails 3 application."
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optionsful
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marco Antonio Gonzalez Junior
@@ -79,7 +79,7 @@ dependencies:
79
79
  version: 3.0.0.rc
80
80
  type: :runtime
81
81
  version_requirements: *id004
82
- description: Help building RESTful web services by supporting the HTTP OPTIONS verb on Ruby on Rails applications.
82
+ description: Build RESTful web services supporting the HTTP OPTIONS verb on Ruby on Rails applications.
83
83
  email: kayaman@baurets.net
84
84
  executables: []
85
85
 
@@ -99,17 +99,20 @@ files:
99
99
  - features/optionsful.feature
100
100
  - features/step_definitions/optionsful3_steps.rb
101
101
  - features/support/env.rb
102
- - lib/baurets/optionsful/config.rb
102
+ - lib/baurets/optionsful/configurator.rb
103
103
  - lib/baurets/optionsful/introspections.rb
104
104
  - lib/baurets/optionsful/server.rb
105
105
  - lib/optionsful.rb
106
106
  - optionsful.gemspec
107
107
  - rails/init.rb
108
- - samples/optionsful.yml.sample
108
+ - samples/optionsful.yml
109
109
  - samples/optionsful_bug.yml
110
110
  - samples/optionsful_true.yml
111
+ - samples/optionsful_true_custom.yml
112
+ - samples/optionsful_true_custom_base_path.yml
113
+ - samples/optionsful_true_custom_propagate.yml
111
114
  - spec/fake_app.rb
112
- - spec/optionsful_config_spec.rb
115
+ - spec/optionsful_configurator_spec.rb
113
116
  - spec/optionsful_server_spec.rb
114
117
  - spec/spec.opts
115
118
  - spec/spec_helper.rb
@@ -150,6 +153,6 @@ specification_version: 3
150
153
  summary: Support HTTP OPTIONS verb on your Rails 3 app.
151
154
  test_files:
152
155
  - spec/fake_app.rb
153
- - spec/optionsful_config_spec.rb
156
+ - spec/optionsful_configurator_spec.rb
154
157
  - spec/optionsful_server_spec.rb
155
158
  - spec/spec_helper.rb
@@ -1,49 +0,0 @@
1
-
2
- require 'yaml'
3
-
4
- module Baurets
5
- module Optionsful
6
- class Config
7
-
8
- DEFAULT = { :link => false, :host => 'auto', :base_path => "/api", :propagate => true }
9
-
10
- def initialize(file = nil, options = {})
11
- if file.nil?
12
- file = File.join(Rails.root, 'config', 'optionsful.yml')
13
- end
14
- config = load_yaml(file, get_env)
15
- config = DEFAULT if config.nil? or config.empty?
16
- config.merge!(options) unless options.empty?
17
- @config = config
18
- config
19
- end
20
-
21
- def get_env
22
- :test if Rails.env.test?
23
- :development if Rails.env.development?
24
- :production if Rails.env.production?
25
- end
26
-
27
- def load_yaml(file, environment)
28
- config = nil
29
- if File.exist?(file)
30
- begin
31
- envs = YAML::load_file(file)
32
- raise "Could not parse the YAML." if (envs.empty? or (not envs.kind_of?(Hash)))
33
- envs = envs.symbolize_keys if envs
34
- config = envs[environment].symbolize_keys if (envs && envs[environment])
35
- rescue
36
- config = nil
37
- end
38
- config
39
- end
40
-
41
- end
42
-
43
- def method_missing(name, *args)
44
- return @config[name.to_sym]
45
- end
46
-
47
- end
48
- end
49
- end
@@ -1,20 +0,0 @@
1
- # Optionsful custom settings
2
-
3
- # Link header configuration
4
- development:
5
- link: false
6
- host: auto
7
- base_path: /api
8
- propagate: true
9
-
10
- test:
11
- link: false
12
- host: auto
13
- base_path: /api
14
- propagate: false
15
-
16
- production:
17
- link: false
18
- host: auto
19
- base_path: /api
20
- propagate: false
@@ -1,76 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Baurets::Optionsful::Config do
4
-
5
- include Rack::Test::Methods
6
-
7
- context "Config carries specific settings" do
8
-
9
- describe "when there's NO custom config file, use expected default settings" do
10
-
11
- it "the Link header generation must be disabled" do
12
- config = Baurets::Optionsful::Config.new("file_error.txt")
13
- config.link.should be false
14
- end
15
-
16
- end
17
-
18
- describe "when there is a custom config file, load the settings from it" do
19
-
20
- before(:each) do
21
- @config = nil
22
- end
23
-
24
- it "the Link header generation must be disabled" do
25
- @config = Baurets::Optionsful::Config.new()
26
- @config.link.should be false
27
- end
28
-
29
- it "the Link header generation must be disabled (file found but looks corrupted!)" do
30
- FileUtils.cp File.join(Rails.root, 'samples', 'optionsful_bug.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
31
- @config = Baurets::Optionsful::Config.new
32
- @config.link.should == false
33
- end
34
-
35
- it "the Link header generation must be disabled (file given but looks corrupted!)" do
36
- @config = Baurets::Optionsful::Config.new(File.join(Rails.root, 'samples', 'optionsful_bug.yml'))
37
- @config.link.should be false
38
- end
39
-
40
- it "the Link header generation must be enabled" do
41
- @config = Baurets::Optionsful::Config.new(nil, {:link => true})
42
- @config.link.should be true
43
- end
44
-
45
- it "the Link header generation must be enabled (file found)" do
46
- FileUtils.cp File.join(Rails.root, 'samples', 'optionsful_true.yml'), File.join(Rails.root, 'config', 'optionsful.yml')
47
- @config = Baurets::Optionsful::Config.new()
48
- @config.link.should be true
49
- end
50
-
51
- it "if the Link header generation is enabled, host value must be set" do
52
- @config = Baurets::Optionsful::Config.new(File.join(Rails.root, 'samples', 'optionsful_true.yml'))
53
- @config.link.should be true
54
- @config.host.empty?.should_not be true
55
- end
56
-
57
- it "if the Link header generation is enabled, host value accepts 'auto'" do
58
- @config = Baurets::Optionsful::Config.new(File.join(File.dirname(__FILE__), 'config', 'optionsful_host_auto.yml'))
59
- @config.link.should be true
60
- @config.host.should == "auto"
61
- end
62
-
63
- after(:each) do
64
- FileUtils.rm [File.join(Rails.root, 'config', 'optionsful.yml')] if File.exist? File.join(Rails.root, 'config', 'optionsful.yml')
65
- @config = nil
66
- end
67
-
68
- after(:all) do
69
- FileUtils.rm [File.join(Rails.root, 'config', 'optionsful.yml')] if File.exist? File.join(Rails.root, 'config', 'optionsful.yml')
70
- @config = nil
71
- end
72
-
73
- end
74
-
75
- end
76
- end