composition_engine 0.0.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,20 @@
1
+ source :rubygems
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
+
9
+ group :test do
10
+ gem "sinatra"
11
+ end
12
+
13
+ group :development do
14
+ gem "sqlite3"
15
+ gem "rspec", ">= 2.0"
16
+ gem "bundler", ">= 1.0.0"
17
+ gem "jeweler"
18
+ gem "rcov"
19
+ gem "cucumber"
20
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (2.1.2)
5
+ cucumber (0.10.2)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (>= 1.1.2)
8
+ gherkin (>= 2.3.5)
9
+ json (>= 1.4.6)
10
+ term-ansicolor (>= 1.0.5)
11
+ diff-lcs (1.1.2)
12
+ gherkin (2.3.7)
13
+ json (>= 1.4.6)
14
+ git (1.2.5)
15
+ jeweler (1.6.2)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ json (1.5.1)
20
+ rack (1.3.1)
21
+ rake (0.9.2)
22
+ rcov (0.9.9)
23
+ rspec (2.3.0)
24
+ rspec-core (~> 2.3.0)
25
+ rspec-expectations (~> 2.3.0)
26
+ rspec-mocks (~> 2.3.0)
27
+ rspec-core (2.3.1)
28
+ rspec-expectations (2.3.0)
29
+ diff-lcs (~> 1.1.2)
30
+ rspec-mocks (2.3.0)
31
+ sinatra (1.2.6)
32
+ rack (~> 1.1)
33
+ tilt (< 2.0, >= 1.2.2)
34
+ sqlite3 (1.3.3)
35
+ term-ansicolor (1.0.5)
36
+ tilt (1.3.2)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (>= 1.0.0)
43
+ cucumber
44
+ jeweler
45
+ rcov
46
+ rspec (>= 2.0)
47
+ sinatra
48
+ sqlite3
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 John Wilkinson
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
+ = composition_engine
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to composition_engine
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 John Wilkinson. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "composition_engine"
18
+ gem.homepage = "http://github.com/jcwilk/composition_engine"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{composition_engine gem}
21
+ gem.description = %Q{gem for participating in the composition_engine composition}
22
+ gem.email = "jcwilk@gmail.com"
23
+ gem.authors = ["John Wilkinson"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ require 'cucumber/rake/task'
40
+ Cucumber::Rake::Task.new(:features)
41
+
42
+ task :default => :spec
43
+
44
+ require 'rdoc/task'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "composition_engine #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,71 @@
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{composition_engine}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{John Wilkinson}]
12
+ s.date = %q{2011-07-18}
13
+ s.description = %q{gem for participating in the composition_engine composition}
14
+ s.email = %q{jcwilk@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
+ "composition_engine.gemspec",
29
+ "features/composition_engine.feature",
30
+ "features/step_definitions/composition_engine_steps.rb",
31
+ "features/support/env.rb",
32
+ "lib/composition_engine.rb",
33
+ "spec/composition_engine_spec.rb",
34
+ "spec/database.yml",
35
+ "spec/spec_helper.rb",
36
+ "spec/support/game.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/jcwilk/composition_engine}
39
+ s.licenses = [%q{MIT}]
40
+ s.require_paths = [%q{lib}]
41
+ s.rubygems_version = %q{1.8.4}
42
+ s.summary = %q{composition_engine gem}
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, [">= 2.0"])
50
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<sqlite3>, [">= 0"])
56
+ s.add_dependency(%q<rspec>, [">= 2.0"])
57
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, [">= 0"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ s.add_dependency(%q<cucumber>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<sqlite3>, [">= 0"])
64
+ s.add_dependency(%q<rspec>, [">= 2.0"])
65
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, [">= 0"])
67
+ s.add_dependency(%q<rcov>, [">= 0"])
68
+ s.add_dependency(%q<cucumber>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
+ require 'composition_engine'
12
+
13
+ require 'test/unit/assertions'
14
+
15
+ World(Test::Unit::Assertions)
@@ -0,0 +1,143 @@
1
+ require 'cgi'
2
+
3
+ module CompositionEngine
4
+ SESSION_KEY = 'composition_engine'
5
+ PATH_PREFIX = '/engine'
6
+
7
+ def self.assign_user_to_session(session,user)
8
+ scope_session(session)['user'] = user
9
+ end
10
+
11
+ def self.extract_user_from_session(session)
12
+ scope_session(session)['user']
13
+ end
14
+
15
+ def self.scope_session(session)
16
+ session[SESSION_KEY]||= {}
17
+ end
18
+
19
+ class User < Hashie::Dash
20
+ property :nickname
21
+ property :uuid
22
+ end
23
+
24
+ class Middleware
25
+ attr_accessor :app, :env
26
+
27
+ def initialize(_app)
28
+ self.app = _app
29
+ end
30
+
31
+ def call(_env)
32
+ self.env = _env
33
+ call_override || app.call(_env)
34
+ end
35
+
36
+ def call_override
37
+ case scoped_path
38
+ when false
39
+ LoginHandler.force_login(env) #This returns false and defaults control to the next middleware if they're already logged in
40
+ when '/inspect'
41
+ [200,{'Content-Type' => 'text/plain'},[self.env.keys.map{|k| "#{k.inspect}: #{self.env[k].inspect}"}.join("\n")]]
42
+ when /^#{LoginHandler.resource_path}/
43
+ LoginHandler.handle(env)
44
+ else
45
+ [404,{'ContentType' => 'text/plain'},['Not Found']]
46
+ end
47
+ end
48
+
49
+ def scoped_path
50
+ return false if !(env['PATH_INFO'] =~ /^#{PATH_PREFIX}(\/.*)?$/)
51
+
52
+ return '/' if $1.nil?
53
+ return $1
54
+ end
55
+ end
56
+
57
+ class LoginHandler
58
+ attr_accessor :env
59
+
60
+ def self.handle(_env)
61
+ self.new(_env).handle
62
+ end
63
+
64
+ def self.force_login(_env)
65
+ inst = self.new(_env)
66
+ if inst.logged_in?
67
+ false
68
+ else
69
+ inst.new_login
70
+ end
71
+ end
72
+
73
+ def self.resource_path
74
+ '/login'
75
+ end
76
+
77
+ def self.prefixed_path
78
+ PATH_PREFIX+self.resource_path
79
+ end
80
+
81
+ def initialize(_env)
82
+ self.env = _env
83
+ end
84
+
85
+ def handle
86
+ if request.get?
87
+ new_login
88
+ elsif request.post?
89
+ create_login
90
+ end
91
+ end
92
+
93
+ def new_login(message = nil) #TODO: require form key so they can't spam POSTs
94
+ body = <<HTML
95
+ <html>
96
+ <body>
97
+ <h1>New User!</h1>
98
+ #{"<em>#{message}</em>" if message}
99
+ <p>Select a handle and click Login</p>
100
+ <form action='#{self.class.prefixed_path}' method='POST'>
101
+ <label for='login_nickname'>Nickname: </label><input type='text' name='login[nickname]' id='login_nickname'/>
102
+ <input type='submit' value='Login' />
103
+ </form>
104
+ </body>
105
+ </html>
106
+ HTML
107
+ [200,{'ContentType' => 'text/html'},[body]]
108
+ end
109
+
110
+ def create_login
111
+ nickname = params['login']['nickname']
112
+ if nickname.nil? || nickname.empty?
113
+ new_login("Nickname must not be blank!")
114
+ else
115
+ user = ::CompositionEngine::User.new(:nickname => nickname, :uuid => UUIDTools::UUID.random_create)
116
+ ::CompositionEngine.assign_user_to_session(session,user)
117
+ [302,{'Location'=>'/'},[]]
118
+ end
119
+ end
120
+
121
+ def logged_in?
122
+ ::CompositionEngine.extract_user_from_session(session)
123
+ end
124
+
125
+ private
126
+
127
+ def scoped_session
128
+ ::CompositionEngine.scope_session(session)
129
+ end
130
+
131
+ def session
132
+ request.session
133
+ end
134
+
135
+ def params
136
+ request.params
137
+ end
138
+
139
+ def request
140
+ @_rack_request||= Rack::Request.new(env)
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe CompositionEngine do
4
+
5
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,3 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: ":memory:"
@@ -0,0 +1,30 @@
1
+
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ Bundler.require(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'composition_engine'
16
+
17
+ BASE = File.dirname(__FILE__)
18
+
19
+ config = YAML::load_file(File.join(BASE,'database.yml'))
20
+ ActiveRecord::Base.establish_connection(config['sqlite3'])
21
+
22
+ load(File.join(BASE,'schema.rb'))
23
+
24
+ # Requires supporting files with custom matchers and macros, etc,
25
+ # in ./support/ and its subdirectories.
26
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
27
+
28
+ RSpec.configure do |config|
29
+
30
+ end
@@ -0,0 +1,12 @@
1
+ class Game < Sinatra::Base
2
+ use Rack::Session::Pool
3
+ use CompositionEngine::Middleware
4
+
5
+ def current_user
6
+ CompositionEngine.extract_user_from_session(session)
7
+ end
8
+
9
+ get '/' do
10
+ "Welcome #{current_user.nickname}"
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: composition_engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Wilkinson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: &18101660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *18101660
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &18100160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *18100160
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &18099320 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *18099320
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &18098440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *18098440
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &18063840 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *18063840
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: &18063080 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *18063080
80
+ description: gem for participating in the composition_engine composition
81
+ email: jcwilk@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ files:
88
+ - .document
89
+ - .rspec
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - composition_engine.gemspec
97
+ - features/composition_engine.feature
98
+ - features/step_definitions/composition_engine_steps.rb
99
+ - features/support/env.rb
100
+ - lib/composition_engine.rb
101
+ - spec/composition_engine_spec.rb
102
+ - spec/database.yml
103
+ - spec/spec_helper.rb
104
+ - spec/support/game.rb
105
+ homepage: http://github.com/jcwilk/composition_engine
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 1830319338704296423
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.4
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: composition_engine gem
133
+ test_files: []