dungeon_master 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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "useragent-fl", "0.4.3"
4
+ gem "redis", "2.2.2"
5
+ gem "yajl-ruby", "0.8.3"
6
+
7
+ group :development do
8
+ gem "rspec", "~> 2.3.0"
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ gem "rcov", ">= 0"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
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.9.2)
11
+ rcov (0.9.10)
12
+ redis (2.2.2)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+ useragent-fl (0.4.3)
22
+ yajl-ruby (0.8.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ jeweler (~> 1.5.2)
30
+ rcov
31
+ redis (= 2.2.2)
32
+ rspec (~> 2.3.0)
33
+ useragent-fl (= 0.4.3)
34
+ yajl-ruby (= 0.8.3)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 James Golick
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
+ = dungeon_master
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to dungeon_master
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 James Golick. 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 = "dungeon_master"
16
+ gem.homepage = "http://github.com/jamesgolick/dungeon_master"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Fuck gem summaries.}
19
+ gem.description = %Q{Fuck gem descriptions.}
20
+ gem.email = "jamesgolick@gmail.com"
21
+ gem.authors = ["James Golick"]
22
+
23
+ gem.add_runtime_dependency "useragent-fl", "0.4.3"
24
+ gem.add_runtime_dependency "redis", "2.2.2"
25
+ gem.add_runtime_dependency "yajl-ruby", "0.8.3"
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 = "dungeon_master #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dungeon_master}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["James Golick"]
12
+ s.date = %q{2011-08-26}
13
+ s.description = %q{Fuck gem descriptions.}
14
+ s.email = %q{jamesgolick@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "dungeon_master.gemspec",
29
+ "lib/dungeon_master.rb",
30
+ "spec/dungeon_master_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/jamesgolick/dungeon_master}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.5.2}
37
+ s.summary = %q{Fuck gem summaries.}
38
+ s.test_files = [
39
+ "spec/dungeon_master_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<useragent-fl>, ["= 0.4.3"])
48
+ s.add_runtime_dependency(%q<redis>, ["= 2.2.2"])
49
+ s.add_runtime_dependency(%q<yajl-ruby>, ["= 0.8.3"])
50
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ s.add_runtime_dependency(%q<useragent-fl>, ["= 0.4.3"])
55
+ s.add_runtime_dependency(%q<redis>, ["= 2.2.2"])
56
+ s.add_runtime_dependency(%q<yajl-ruby>, ["= 0.8.3"])
57
+ else
58
+ s.add_dependency(%q<useragent-fl>, ["= 0.4.3"])
59
+ s.add_dependency(%q<redis>, ["= 2.2.2"])
60
+ s.add_dependency(%q<yajl-ruby>, ["= 0.8.3"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ s.add_dependency(%q<useragent-fl>, ["= 0.4.3"])
66
+ s.add_dependency(%q<redis>, ["= 2.2.2"])
67
+ s.add_dependency(%q<yajl-ruby>, ["= 0.8.3"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<useragent-fl>, ["= 0.4.3"])
71
+ s.add_dependency(%q<redis>, ["= 2.2.2"])
72
+ s.add_dependency(%q<yajl-ruby>, ["= 0.8.3"])
73
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
74
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
76
+ s.add_dependency(%q<rcov>, [">= 0"])
77
+ s.add_dependency(%q<useragent-fl>, ["= 0.4.3"])
78
+ s.add_dependency(%q<redis>, ["= 2.2.2"])
79
+ s.add_dependency(%q<yajl-ruby>, ["= 0.8.3"])
80
+ end
81
+ end
82
+
@@ -0,0 +1,50 @@
1
+ require "useragent"
2
+ require "yajl"
3
+
4
+ module DungeonMaster
5
+ Browser = Struct.new(:browser, :version)
6
+
7
+ class Decider
8
+ def initialize(redis = $redis)
9
+ @redis = redis
10
+ end
11
+
12
+ def activate(browser, min_version, group = "main")
13
+ @redis.sadd("dungeon_master/groups", group)
14
+ @redis.sadd("dungeon_master/active/#{group}", "#{browser}/#{min_version}")
15
+ end
16
+
17
+ def active?(user_agent, group = "main")
18
+ current_browser = UserAgent.parse(user_agent)
19
+ supported_browsers(group).any? do |browser|
20
+ current_browser >= browser
21
+ end
22
+ end
23
+
24
+ def groups
25
+ @redis.smembers("dungeon_master/groups")
26
+ end
27
+
28
+ def supported_browsers(group = "main")
29
+ @redis.smembers("dungeon_master/active/#{group}").map do |string|
30
+ browser_version = string.split("/")
31
+ Browser.new(browser_version.first, browser_version.last)
32
+ end
33
+ end
34
+ end
35
+
36
+ module Helpers
37
+ def dungeon_master_json
38
+ memberships = Hash[*dungeon_master.groups.map do |group|
39
+ [group, dungeon_master.active?(request.env["HTTP_USER_AGENT"])]
40
+ end.flatten]
41
+
42
+ Yajl::Encoder.encode(memberships)
43
+ end
44
+
45
+ def dungeon_master
46
+ $dm ||
47
+ raise("Override this method to return your instance of DungeonMaster::Decider")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "DungeonMaster::Decider" do
4
+ it "activates browsers by minimum version" do
5
+ @decider = DungeonMaster::Decider.new($redis)
6
+ @decider.activate("Firefox", "3.5")
7
+ @decider.should be_active("Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.9.0.2) Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.8")
8
+ @decider.should_not be_active("Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.9.0.2) Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.2")
9
+
10
+ @decider.activate("Chrome", "13.0.782.215")
11
+ @decider.should be_active("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1")
12
+ @decider.should_not be_active("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.213 Safari/535.1")
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'dungeon_master'
5
+ require 'redis'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.before do
13
+ $redis = Redis.new(:db => 15)
14
+ $redis.flushdb
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dungeon_master
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - James Golick
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-26 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 9
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 3
34
+ version: 0.4.3
35
+ name: useragent-fl
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :runtime
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 2
49
+ - 2
50
+ version: 2.2.2
51
+ name: redis
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ type: :runtime
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - "="
60
+ - !ruby/object:Gem::Version
61
+ hash: 57
62
+ segments:
63
+ - 0
64
+ - 8
65
+ - 3
66
+ version: 0.8.3
67
+ name: yajl-ruby
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ prerelease: false
71
+ type: :development
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 2
80
+ - 3
81
+ - 0
82
+ version: 2.3.0
83
+ name: rspec
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ prerelease: false
87
+ type: :development
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 23
94
+ segments:
95
+ - 1
96
+ - 0
97
+ - 0
98
+ version: 1.0.0
99
+ name: bundler
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ prerelease: false
103
+ type: :development
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ hash: 7
110
+ segments:
111
+ - 1
112
+ - 5
113
+ - 2
114
+ version: 1.5.2
115
+ name: jeweler
116
+ version_requirements: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ prerelease: false
119
+ type: :development
120
+ requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ name: rcov
130
+ version_requirements: *id007
131
+ - !ruby/object:Gem::Dependency
132
+ prerelease: false
133
+ type: :runtime
134
+ requirement: &id008 !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - "="
138
+ - !ruby/object:Gem::Version
139
+ hash: 9
140
+ segments:
141
+ - 0
142
+ - 4
143
+ - 3
144
+ version: 0.4.3
145
+ name: useragent-fl
146
+ version_requirements: *id008
147
+ - !ruby/object:Gem::Dependency
148
+ prerelease: false
149
+ type: :runtime
150
+ requirement: &id009 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - "="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 2
158
+ - 2
159
+ - 2
160
+ version: 2.2.2
161
+ name: redis
162
+ version_requirements: *id009
163
+ - !ruby/object:Gem::Dependency
164
+ prerelease: false
165
+ type: :runtime
166
+ requirement: &id010 !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - "="
170
+ - !ruby/object:Gem::Version
171
+ hash: 57
172
+ segments:
173
+ - 0
174
+ - 8
175
+ - 3
176
+ version: 0.8.3
177
+ name: yajl-ruby
178
+ version_requirements: *id010
179
+ description: Fuck gem descriptions.
180
+ email: jamesgolick@gmail.com
181
+ executables: []
182
+
183
+ extensions: []
184
+
185
+ extra_rdoc_files:
186
+ - LICENSE.txt
187
+ - README.rdoc
188
+ files:
189
+ - .document
190
+ - .rspec
191
+ - Gemfile
192
+ - Gemfile.lock
193
+ - LICENSE.txt
194
+ - README.rdoc
195
+ - Rakefile
196
+ - VERSION
197
+ - dungeon_master.gemspec
198
+ - lib/dungeon_master.rb
199
+ - spec/dungeon_master_spec.rb
200
+ - spec/spec_helper.rb
201
+ has_rdoc: true
202
+ homepage: http://github.com/jamesgolick/dungeon_master
203
+ licenses:
204
+ - MIT
205
+ post_install_message:
206
+ rdoc_options: []
207
+
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ none: false
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ hash: 3
216
+ segments:
217
+ - 0
218
+ version: "0"
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ none: false
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ hash: 3
225
+ segments:
226
+ - 0
227
+ version: "0"
228
+ requirements: []
229
+
230
+ rubyforge_project:
231
+ rubygems_version: 1.5.2
232
+ signing_key:
233
+ specification_version: 3
234
+ summary: Fuck gem summaries.
235
+ test_files:
236
+ - spec/dungeon_master_spec.rb
237
+ - spec/spec_helper.rb