Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Adding support for header and url based versioning. Adding ActiveMode…
Browse files Browse the repository at this point in the history
…l::Validations to validate config values
  • Loading branch information
Brian Ploetz committed Dec 9, 2011
1 parent 0ba0d67 commit 8e0c2dd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ PATH
remote: .
specs:
versionist (0.1.0)
activemodel (~> 3.0)
activesupport (~> 3.0)

GEM
remote: http://rubygems.org/
specs:
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activesupport (3.1.3)
multi_json (~> 1.0)
builder (3.0.0)
diff-lcs (1.1.3)
i18n (0.6.0)
json (1.6.3)
multi_json (1.0.4)
rake (0.9.2)
Expand Down
9 changes: 5 additions & 4 deletions lib/versionist.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'versionist/railtie' if defined?(Rails) && Rails::VERSION::MAJOR == 3

require 'active_support'

module Versionist
class Configuration
attr_accessor :vendor_name
attr_accessor :default_version
end
extend ActiveSupport::Autoload

autoload :Configuration

def self.configuration
@@configuration ||= Configuration.new
Expand Down
14 changes: 14 additions & 0 deletions lib/versionist/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'active_model'

module Versionist
class Configuration
include ActiveModel::Validations
include ActiveModel::Validations::HelperMethods

attr_accessor :versioning_scheme
validates_inclusion_of :versioning_scheme, :in => %W( header url )

attr_accessor :vendor_name
attr_accessor :default_version
end
end
22 changes: 22 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,39 @@
context ".configure" do
before :each do
Versionist.configure do |config|
config.versioning_scheme = "header"
config.vendor_name = "mydomain.com"
config.default_version = "v1"
end
end

it "should configure the versioning_scheme" do
Versionist.configuration.versioning_scheme.should == "header"
end

it "should configure the vendor_name" do
Versionist.configuration.vendor_name.should == "mydomain.com"
end

it "should configure the default_version" do
Versionist.configuration.default_version.should == "v1"
end

it "should validate versioning_scheme" do
Versionist.configure do |config|
config.versioning_scheme = "bogus"
end
Versionist.configuration.valid?.should == false

Versionist.configure do |config|
config.versioning_scheme = "header"
end
Versionist.configuration.valid?.should == true

Versionist.configure do |config|
config.versioning_scheme = "url"
end
Versionist.configuration.valid?.should == true
end
end
end
1 change: 1 addition & 0 deletions versionist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = '>= 1.3.6'

s.add_dependency('activesupport', '~> 3.0')
s.add_dependency('activemodel', '~> 3.0')

s.add_development_dependency('rake', '>= 0.9.2')
s.add_development_dependency('rspec', '2.7.0')
Expand Down

0 comments on commit 8e0c2dd

Please sign in to comment.