envie 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.5.2)
27
+ rcov
28
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Guilherme Silveira
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = envie
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to envie
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Guilherme Silveira. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "envie"
16
+ gem.homepage = "http://github.com/caelum/envie"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Simple api on feature toggle}
19
+ gem.description = %Q{Simple api on feature toggle}
20
+ gem.email = "guilherme.silveira@caelum.com.br"
21
+ gem.authors = ["Guilherme Silveira"]
22
+ gem.version = "0.1.0"
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "envie #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/lib/envie.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'envie/env'
2
+ require 'envie/featurable'
3
+ module Envie
4
+ class << self
5
+
6
+ attr_reader :current
7
+
8
+ def all
9
+ @envs ||= {}
10
+ end
11
+
12
+ def method_missing(name)
13
+ at(name)
14
+ end
15
+
16
+ def at(name)
17
+ all[name] ||= Env.new
18
+ end
19
+
20
+ def has?(name)
21
+ @current.has?(name)
22
+ end
23
+
24
+ def use(name)
25
+ @current = at(name)
26
+ end
27
+
28
+ end
29
+
30
+ Envie.use :production
31
+ end
32
+
33
+ class Object
34
+ include Envie::Featurable
35
+ end
data/lib/envie/env.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Envie
2
+ class Env
3
+
4
+ def features
5
+ @features ||= []
6
+ end
7
+
8
+ def with(feature)
9
+ features << feature
10
+ self
11
+ end
12
+
13
+ def has?(name)
14
+ features.include?(name) || (@parent && @parent.has?(name))
15
+ end
16
+
17
+ def derive(child)
18
+ Envie.at(child).from(self)
19
+ end
20
+
21
+ def from(parent)
22
+ @parent = parent
23
+ self
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Envie
2
+ module Featurable
3
+ def feature(name)
4
+ if Envie.has?(name)
5
+ yield
6
+ else
7
+ nil
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Envie do
4
+
5
+ context "when using features" do
6
+ it "should make them available at production" do
7
+ Envie.production.with(:products)
8
+ Envie.production.has?(:products).should be_true
9
+
10
+ Envie.has?(:products).should be_true
11
+ Envie.has?(:open_id).should be_false
12
+
13
+ feature(:products) do
14
+ "do something"
15
+ end.should == "do something"
16
+
17
+ feature(:open_id) do
18
+ "do something"
19
+ end.should be_nil
20
+ end
21
+
22
+ context "after deriving a child enviroment" do
23
+
24
+ it "should register it globally" do
25
+ Envie.production.with(:products).derive(:test)
26
+ Envie.test.has?(:products).should be_true
27
+ end
28
+
29
+ end
30
+
31
+ context "and using children enviroments" do
32
+
33
+ it "should make them available" do
34
+ production = Envie.production.with(:planets)
35
+ homolog = production.derive(:homolog).with(:openid)
36
+ homolog.derive(:development).with(:jquery)
37
+
38
+ Envie.has?(:jquery).should be_false
39
+
40
+ Envie.use(:homolog)
41
+ Envie.has?(:planets).should be_true
42
+ Envie.has?(:openid).should be_true
43
+ Envie.has?(:jquery).should be_false
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'envie'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Envie::Env do
4
+
5
+ context "when adding features" do
6
+ it "should have them available" do
7
+ prod = Envie::Env.new.with(:products)
8
+ prod.has?(:products).should be_true
9
+ prod.has?(:clients).should be_false
10
+ end
11
+
12
+ it "should have them available out of its parents" do
13
+ child = Envie::Env.new.with(:products).derive(:child)
14
+ child.has?(:products).should be_true
15
+ end
16
+
17
+ it "should have them available out of its parents" do
18
+ child = Envie::Env.new.with(:products).derive(:child).with(:oauth)
19
+ child.has?(:oauth).should be_true
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Envie do
4
+
5
+ context "using envie" do
6
+
7
+ it "should not duplicate environments at each call" do
8
+ Envie.extra.should == Envie.extra
9
+ end
10
+
11
+ it "using should change current the one" do
12
+ Envie.use(:extra)
13
+ Envie.current.should == Envie.extra
14
+ end
15
+
16
+ it "should check with the current scope" do
17
+ Envie.current.should_receive(:has?).with(:magic).and_return(true)
18
+ Envie.has?(:magic).should == true
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Envie::Featurable do
4
+
5
+ context "when in the wrong scope" do
6
+ it "should not invoke its block" do
7
+ Envie.should_receive(:has?).with(:non_existing).and_return(false)
8
+ Object.new.extend(Envie::Featurable).feature(:non_existing) do
9
+ fail "should never invoke because the feature is not available"
10
+ end
11
+ end
12
+ end
13
+
14
+ context "when in the correct scope" do
15
+ it "should invoke its block" do
16
+ Envie.should_receive(:has?).with(:existing).and_return(true)
17
+ Object.new.extend(Envie::Featurable).feature(:existing) do
18
+ "executed!"
19
+ end.should == "executed!"
20
+ end
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envie
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Guilherme Silveira
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-03 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 0
33
+ version: 2.3.0
34
+ requirement: *id001
35
+ prerelease: false
36
+ name: rspec
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ requirement: *id002
51
+ prerelease: false
52
+ name: bundler
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 7
61
+ segments:
62
+ - 1
63
+ - 5
64
+ - 2
65
+ version: 1.5.2
66
+ requirement: *id003
67
+ prerelease: false
68
+ name: jeweler
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirement: *id004
81
+ prerelease: false
82
+ name: rcov
83
+ description: Simple api on feature toggle
84
+ email: guilherme.silveira@caelum.com.br
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files:
90
+ - LICENSE.txt
91
+ - README.rdoc
92
+ files:
93
+ - .document
94
+ - .rspec
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.rdoc
99
+ - Rakefile
100
+ - lib/envie.rb
101
+ - lib/envie/env.rb
102
+ - lib/envie/featurable.rb
103
+ - spec/acceptance_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/unit/env_spec.rb
106
+ - spec/unit/envie_spec.rb
107
+ - spec/unit/featurable_spec.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/caelum/envie
110
+ licenses:
111
+ - MIT
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.4.1
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Simple api on feature toggle
142
+ test_files:
143
+ - spec/acceptance_spec.rb
144
+ - spec/spec_helper.rb
145
+ - spec/unit/env_spec.rb
146
+ - spec/unit/envie_spec.rb
147
+ - spec/unit/featurable_spec.rb