sheriff 0.0.1

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/CHANGELOG.txt ADDED
File without changes
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 "shoulda", ">= 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,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.2)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Anthony Navarre & Jesse Trimble
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
+ = sheriff
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to sheriff
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 Anthony Navarre & Jesse Trimble. See LICENSE.txt for
18
+ further details.
19
+
data/ROADMAP.txt ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,54 @@
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 = "sheriff"
16
+ gem.homepage = "http://github.com/anthonynavarre/sheriff"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Utility for hiding and showing features based on context}
19
+ gem.description = %Q{Sheriff allows you to define "FeatureSets" and designate
20
+ under which contexts the FeatureSet should be visible (eg: a specific view or controller)}
21
+ gem.email = "me@anthonynavarre.com"
22
+ gem.authors = ["Anthony Navarre", "Jesse Trimble"]
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 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "sheriff #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,48 @@
1
+ module Sheriff
2
+
3
+ class << self
4
+ @@defined_feature_sets = []
5
+
6
+ def defined_feature_sets
7
+ @@defined_feature_sets
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def defined_feature_sets
14
+ Sheriff.defined_feature_sets
15
+ end
16
+
17
+ end
18
+
19
+ def self.included(base)
20
+ base.extend ClassMethods
21
+ end
22
+
23
+ def self.define(feature_set_name)
24
+ raise Sheriff::FeatureSet::AlreadyDefinedError.new("Feature Set #{feature_set_name} already defined") if Sheriff.defined_feature_sets.map(&:name).include?(feature_set_name)
25
+ Sheriff.defined_feature_sets << Sheriff::FeatureSet.new(feature_set_name)
26
+ end
27
+
28
+ def self.find(name)
29
+ Sheriff.defined_feature_sets.select {|fs| fs.name == name}.first
30
+ end
31
+
32
+ attr_accessor :visible
33
+ alias :visible? :visible
34
+
35
+ def feature_set
36
+ Sheriff.defined_feature_sets
37
+ end
38
+
39
+ def initialize
40
+ @visible = true
41
+ end
42
+ end
43
+
44
+ if Module.const_defined? 'ActionController'
45
+ class ActionController::Base
46
+ include Sheriff
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+ class Sheriff::Context
2
+
3
+ def initialize
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Sheriff
2
+ class FeatureSet
3
+ class AlreadyDefinedError < RuntimeError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ module Sheriff
2
+
3
+ class FeatureSet
4
+
5
+ attr_reader :name
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ end
11
+
12
+ end
data/lib/sheriff.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'sheriff/api'
2
+ require 'sheriff/context'
3
+ require 'sheriff/feature_set'
4
+ require 'sheriff/errors'
5
+
data/test/helper.rb ADDED
@@ -0,0 +1,23 @@
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 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'sheriff'
16
+
17
+ class Test::Unit::TestCase
18
+
19
+ def deny(condition)
20
+ assert ! condition
21
+ end
22
+
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ class SheriffTest < Test::Unit::TestCase
4
+
5
+ context 'delicious bacon-wrapped context of chocolatey goodness' do
6
+
7
+ setup do
8
+ Sheriff.defined_feature_sets.clear
9
+ end
10
+
11
+ should 'have no defined features' do
12
+ deny Sheriff.defined_feature_sets.any?
13
+ end
14
+
15
+ should 'be able to define a feature' do
16
+ Sheriff.define :share
17
+ assert Sheriff.defined_feature_sets.map(&:name).include? :share
18
+ end
19
+
20
+ context 'with a defined feature' do
21
+ setup do
22
+ Sheriff.define :share
23
+ end
24
+
25
+ should 'raise when redefining the same feature' do
26
+ assert_raise Sheriff::FeatureSet::AlreadyDefinedError do
27
+ Sheriff.define :share
28
+ end
29
+ end
30
+
31
+ should 'be able to find a feature set' do
32
+ assert Sheriff.find(:share),
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sheriff
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Anthony Navarre
13
+ - Jesse Trimble
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-11 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ prerelease: false
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 0
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 5
59
+ - 2
60
+ version: 1.5.2
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rcov
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: *id004
77
+ description: |-
78
+ Sheriff allows you to define "FeatureSets" and designate
79
+ under which contexts the FeatureSet should be visible (eg: a specific view or controller)
80
+ email: me@anthonynavarre.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.rdoc
88
+ files:
89
+ - .document
90
+ - CHANGELOG.txt
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.rdoc
95
+ - ROADMAP.txt
96
+ - Rakefile
97
+ - VERSION
98
+ - lib/sheriff.rb
99
+ - lib/sheriff/api.rb
100
+ - lib/sheriff/context.rb
101
+ - lib/sheriff/errors.rb
102
+ - lib/sheriff/feature_set.rb
103
+ - test/helper.rb
104
+ - test/test_sheriff.rb
105
+ has_rdoc: true
106
+ homepage: http://github.com/anthonynavarre/sheriff
107
+ licenses:
108
+ - MIT
109
+ post_install_message:
110
+ rdoc_options: []
111
+
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3703422532125167574
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.7
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Utility for hiding and showing features based on context
138
+ test_files:
139
+ - test/helper.rb
140
+ - test/test_sheriff.rb