swerling-synfeld 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/
2
+ doc/
3
+ ext/Makefile
4
+ ext/mkmf.log
5
+ ext/*.o
6
+ ext/*.so
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.0.1 / 2009-07-18
2
+
3
+ * initial release
data/README.txt ADDED
@@ -0,0 +1,126 @@
1
+ synfeld
2
+ by Steven Swerling
3
+ http://tab-a.slot-z.net
4
+
5
+ == DESCRIPTION:
6
+
7
+ Synfeld is an application framework that does almost nothing, and it ain't all that classy.
8
+
9
+ Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router)
10
+
11
+ Very alpha-ish stuff here. Seems to work though.
12
+
13
+ == SYNOPSIS:
14
+
15
+ Here is an example Synfeld application (foo_app.rb):
16
+
17
+ require 'synfeld'
18
+
19
+ class FooApp < Synfeld::App
20
+
21
+ def router
22
+ @router ||= Rack::Router.new(nil, {}) do |r|
23
+ r.map "/yip/", :get, :to => self, :with => { :action => "yip" }
24
+ r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yapfoo" }
25
+ r.map "/yap/", :get, :to => self, :with => { :action => "yap" }
26
+ r.map "/:anything", :get, :to => self, :with => { :action => "no_route" }
27
+ r.map "/", :get, :to => self, :with => { :action => "home" }
28
+ end
29
+ end
30
+
31
+ def yip; "yip"; end
32
+ def yap; "yap"; end
33
+ def home; "home"; end
34
+
35
+ def no_route
36
+ # Note: 'self.env' is the rack env
37
+ self.response[:body] = "route not found for: '#{self.env['REQUEST_URI']}'"
38
+ self.response[:status_code] = 404
39
+ end
40
+
41
+ def yapfoo
42
+ "yapfoo, #{self.params[:yap_variable]}"
43
+ end
44
+
45
+ end
46
+
47
+ And here is an example rack config, foo_app.ru:
48
+
49
+ require 'foo_app'
50
+ run FooApp.new.as_rack_app
51
+
52
+ Run FooApp w/ rackup or shotgun:
53
+
54
+ rackup --server=thin foo.ru -p 3000
55
+
56
+ or
57
+
58
+ shotgun --server=thin foo.ru -p 3000
59
+
60
+ == FEATURES
61
+
62
+ When a Synfeld application handles a rack request, it
63
+
64
+ 1. Duplicates self (so it's thread safe)
65
+ 2. Sets @response, @params, @env (the rack env)
66
+ 3. Calls the action that Rack::Router route that matched. If the action returns a String, that is used for the @response[:body]
67
+
68
+ The @response is a hash used to return rack status code, headers hash, and body. Actions may do what they please with
69
+ the response. Default response:
70
+
71
+ @response = {
72
+ :status_code => 200,
73
+ :headers => {'Content-Type' => 'text/html'},
74
+ :body => nil
75
+ }
76
+
77
+
78
+ Actions are expected to side-effect the :status_code, :headers, and :body. As a convenience, if an action returns a
79
+ string, it is assumed that that string is the :body. An exception is thrown if the :body is not set to something.
80
+
81
+ That's it. Really not much to see here. Just gives you a thread-safe rack-based web framework that consists of
82
+ nothing but a router.
83
+
84
+ == PROBLEMS
85
+
86
+ None known.
87
+
88
+ == REQUIREMENTS:
89
+
90
+ * rack
91
+ * Rack::Router (the rack-router gem), see http://github.com/carllerche/rack-router
92
+
93
+ == INSTALL:
94
+
95
+ * first install rack and rack-router
96
+ * gem install synfeld
97
+
98
+ == Acknowledgements:
99
+
100
+ rack and rack-router were used, obviously.
101
+ 'bones' used for gem generation.
102
+
103
+ == LICENSE:
104
+
105
+ (The MIT License)
106
+
107
+ Copyright (c) 2009 Steven Swerling
108
+
109
+ Permission is hereby granted, free of charge, to any person obtaining
110
+ a copy of this software and associated documentation files (the
111
+ 'Software'), to deal in the Software without restriction, including
112
+ without limitation the rights to use, copy, modify, merge, publish,
113
+ distribute, sublicense, and/or sell copies of the Software, and to
114
+ permit persons to whom the Software is furnished to do so, subject to
115
+ the following conditions:
116
+
117
+ The above copyright notice and this permission notice shall be
118
+ included in all copies or substantial portions of the Software.
119
+
120
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
121
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
122
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
123
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
124
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
125
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
126
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ ensure_in_path 'lib'
17
+ require 'synfeld_info'
18
+
19
+ task :default => 'spec:run'
20
+
21
+ PROJ.name = 'synfeld'
22
+ PROJ.authors = 'Steven Swerling'
23
+ PROJ.email = 'sswerling@yahoo.com'
24
+ PROJ.url = 'http://tab-a.slot-z.net'
25
+ PROJ.version = Synfeld::VERSION
26
+ PROJ.rubyforge.name = 'synfeld'
27
+ PROJ.gem.dependencies = ['rack', 'rack-router']
28
+ PROJ.rdoc.opts = ["--inline-source"]
29
+ PROJ.rdoc.exclude = ["^tasks/setup\.rb$", "lib/synfeld_info.rb"]
30
+
31
+ PROJ.spec.opts << '--color'
32
+
33
+ task :default => 'spec:run'
34
+ namespace :my do
35
+ namespace :gem do
36
+ task :package => [:clobber] do
37
+ this_dir = File.join(File.dirname(__FILE__))
38
+ sh "rm -rf #{File.join(this_dir, 'pkg')}"
39
+ sh "rm -rf #{File.join(this_dir, 'doc')}"
40
+ sh "cp #{File.join(this_dir, 'README.txt')} #{File.join(this_dir, 'README.rdoc')} "
41
+ Rake::Task['gem:package'].invoke
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__),'../lib/synfeld.rb')
2
+
3
+ #
4
+ # Example synfeld application
5
+ #
6
+ class FooApp < Synfeld::App
7
+
8
+ def router
9
+ return @router ||= Rack::Router.new(nil, {}) do |r|
10
+ r.map "/yip/", :get, :to => self, :with => { :action => "yip" }
11
+ r.map "/yap/:yap_variable", :get, :to => self, :with => { :action => "yapfoo" }
12
+ r.map "/yap/", :get, :to => self, :with => { :action => "yap" }
13
+ r.map "/:anything", :get, :to => self, :with => { :action => "no_route" }
14
+ r.map "/", :get, :to => self, :with => { :action => "home" }
15
+ end
16
+ end
17
+
18
+ def yip; "yip"; end
19
+ def yap; "yap"; end
20
+ def home; "home"; end
21
+
22
+ def no_route
23
+ self.response[:body] = "route not found for: '#{self.env['REQUEST_URI']}'"
24
+ self.response[:status_code] = 404
25
+ end
26
+
27
+ def yapfoo
28
+ "yapfoo, #{self.params[:yap_variable]}"
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__),'foo_app.rb')
2
+ run FooApp.new.as_rack_app
data/lib/synfeld.rb ADDED
@@ -0,0 +1,12 @@
1
+ # base ruby requires
2
+ require 'logger'
3
+
4
+ # gems dependencies
5
+ require 'rubygems'
6
+ require 'rack'
7
+ require 'rack/router'
8
+
9
+ # my files (require_all_libs_relative_to is a bones util method in synfeld_info.rb)
10
+ require 'synfeld_info'
11
+ Synfeld.require_all_libs_relative_to(__FILE__)
12
+
@@ -0,0 +1,95 @@
1
+ module Synfeld
2
+
3
+ #
4
+ # See the synopsis section of README.txt for usage.
5
+ #
6
+ # See the RackRouter project for the kinds of routes you can setup.
7
+ #
8
+ # Variables of note:
9
+ #
10
+ # @response
11
+ # a hash with keys :body, :headers, :status_code, the 3 items all rack handlers are expected to set.
12
+ # Body is a string, status code is an http status code integer, and headers is a hash that
13
+ # should conform to rack's contract.
14
+ #
15
+ # @env
16
+ # The rack env passed into this apps #call method
17
+ #
18
+ # @params
19
+ # The params that the matching Rack::Router route set.
20
+ #
21
+ class App
22
+ attr_accessor :response, :params, :env, :logger
23
+
24
+ # Options:
25
+ # :logger => where to log to.
26
+ # Note this is not the same thing as the rack access log (although you
27
+ # can pass that logger in if you want). Default: Logger.new(STDOUT)
28
+ def initialize(opts = {})
29
+ @logger = opts[:logger] || Logger.new(STDOUT)
30
+ end
31
+
32
+ # the router for this Synfeld::App. Subclasses are _required_ to override this.
33
+ # (see README.txt for example usage)
34
+ def router
35
+ raise "#{self.class} must implement a 'router' method that returns a Rack::Router"
36
+ end
37
+
38
+ # Alias for #router
39
+ def as_rack_app; self.router; end # alias_method doesn't seem to work here (it doesnt call the subclass)
40
+
41
+ # The rack #call method
42
+ def call(env)
43
+ dup._call(env) # be thread-safe
44
+ end
45
+
46
+ #
47
+ # Misc Sugar
48
+ #
49
+
50
+ # The name of the action method, determined by the Route that Rack::Router bound to the incoming request
51
+ def action
52
+ self.params[:action]
53
+ end
54
+
55
+ # Overridable method that handles missing action that was defined by a route
56
+ def theres_no_action
57
+ self.response[:body] = "Action '#{self.action}' not found in '#{self.class}'"
58
+ self.response[:status_code] = 500
59
+ end
60
+
61
+ protected
62
+
63
+ # :stopdoc:
64
+
65
+ def _call(env)
66
+ start_time = Time.now.to_f
67
+
68
+ @env = env
69
+ @params = env['rack_router.params']
70
+ @response = {
71
+ :status_code => 200,
72
+ :headers => {'Content-Type' => 'text/html'},
73
+ :body => nil
74
+ }
75
+
76
+ action = self.action
77
+ if self.respond_to?(action)
78
+ body = self.send(self.action)
79
+ else
80
+ body = theres_no_action
81
+ end
82
+
83
+ response[:body] = body if body.is_a?(String)
84
+ raise "You have to set the response body" if response[:body].nil?
85
+
86
+ logger.debug("It took #{Time.now.to_f - start_time} sec for #{self.class} to handle request.")
87
+ [response[:status_code], response[:headers], response[:body]]
88
+ end
89
+
90
+ # :startdoc:
91
+ end
92
+ end
93
+
94
+
95
+
@@ -0,0 +1,51 @@
1
+ #
2
+ # See README.txt for usage.
3
+ #
4
+ module Synfeld
5
+
6
+ # :stopdoc:
7
+
8
+ VERSION = '0.0.1'
9
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
10
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
11
+
12
+ # Returns the version string for the library.
13
+ #
14
+ def self.version
15
+ VERSION
16
+ end
17
+
18
+ # Returns the library path for the module. If any arguments are given,
19
+ # they will be joined to the end of the libray path using
20
+ # <tt>File.join</tt>.
21
+ #
22
+ def self.libpath( *args )
23
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
24
+ end
25
+
26
+ # Returns the lpath for the module. If any arguments are given,
27
+ # they will be joined to the end of the path using
28
+ # <tt>File.join</tt>.
29
+ #
30
+ def self.path( *args )
31
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
32
+ end
33
+
34
+ # Utility method used to require all files ending in .rb that lie in the
35
+ # directory below this file that has the same name as the filename passed
36
+ # in. Optionally, a specific _directory_ name can be passed in such that
37
+ # the _filename_ does not have to be equivalent to the directory.
38
+ #
39
+ def self.require_all_libs_relative_to( fname, dir = nil )
40
+ dir ||= ::File.basename(fname, '.*')
41
+ search_me = ::File.expand_path(
42
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
43
+
44
+ Dir.glob(search_me).sort.each {|rb| require rb}
45
+ end
46
+
47
+ # :startdoc:
48
+
49
+ end # module Synfeld
50
+
51
+
@@ -0,0 +1,16 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. lib synfeld]))
4
+
5
+ Spec::Runner.configure do |config|
6
+ # == Mock Framework
7
+ #
8
+ # RSpec uses it's own mocking framework by default. If you prefer to
9
+ # use mocha, flexmock or RR, uncomment the appropriate line:
10
+ #
11
+ # config.mock_with :mocha
12
+ # config.mock_with :flexmock
13
+ # config.mock_with :rr
14
+ end
15
+
16
+ # EOF
@@ -0,0 +1,7 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+
4
+ describe Synfeld do
5
+ end
6
+
7
+ # EOF
data/synfeld.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = %q{synfeld}
6
+ s.version = "0.0.1"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.authors = ["Steven Swerling"]
10
+ s.date = %q{2009-07-18}
11
+ s.description = %q{Synfeld is an application framework that does almost nothing, and it ain't all that classy.
12
+
13
+ Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router)
14
+
15
+ Very alpha-ish stuff here. Seems to work though.}
16
+ s.email = %q{sswerling@yahoo.com}
17
+ s.extra_rdoc_files = ["History.txt", "README.txt"]
18
+ s.files = [".gitignore", "History.txt", "README.txt", "Rakefile", "example/foo_app.rb", "example/foo_app.ru", "lib/synfeld.rb", "lib/synfeld/base.rb", "lib/synfeld_info.rb", "spec/spec_helper.rb", "spec/synfeld_spec.rb", "synfeld.gemspec", "test/test_synfeld.rb"]
19
+ s.homepage = %q{http://tab-a.slot-z.net}
20
+ s.rdoc_options = ["--inline-source", "--main", "README.txt"]
21
+ s.require_paths = ["lib"]
22
+ s.rubyforge_project = %q{synfeld}
23
+ s.rubygems_version = %q{1.3.3}
24
+ s.summary = %q{Synfeld is an application framework that does almost nothing, and it ain't all that classy}
25
+ s.test_files = ["test/test_synfeld.rb"]
26
+
27
+ if s.respond_to? :specification_version then
28
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
+ s.specification_version = 3
30
+
31
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
32
+ s.add_runtime_dependency(%q<rack>, [">= 0"])
33
+ s.add_runtime_dependency(%q<rack-router>, [">= 0"])
34
+ s.add_development_dependency(%q<bones>, [">= 2.4.0"])
35
+ else
36
+ s.add_dependency(%q<rack>, [">= 0"])
37
+ s.add_dependency(%q<rack-router>, [">= 0"])
38
+ s.add_dependency(%q<bones>, [">= 2.4.0"])
39
+ end
40
+ else
41
+ s.add_dependency(%q<rack>, [">= 0"])
42
+ s.add_dependency(%q<rack-router>, [">= 0"])
43
+ s.add_dependency(%q<bones>, [">= 2.4.0"])
44
+ end
45
+ end
File without changes
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swerling-synfeld
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Swerling
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack-router
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bones
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.4.0
44
+ version:
45
+ description: Synfeld is an application framework that does almost nothing, and it ain't all that classy. Basically this is just a tiny wrapper for the Rack::Router (see http://github.com/carllerche/rack-router) Very alpha-ish stuff here. Seems to work though.
46
+ email: sswerling@yahoo.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History.txt
53
+ - README.txt
54
+ files:
55
+ - .gitignore
56
+ - History.txt
57
+ - README.txt
58
+ - Rakefile
59
+ - example/foo_app.rb
60
+ - example/foo_app.ru
61
+ - lib/synfeld.rb
62
+ - lib/synfeld/base.rb
63
+ - lib/synfeld_info.rb
64
+ - spec/spec_helper.rb
65
+ - spec/synfeld_spec.rb
66
+ - synfeld.gemspec
67
+ - test/test_synfeld.rb
68
+ has_rdoc: false
69
+ homepage: http://tab-a.slot-z.net
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --inline-source
73
+ - --main
74
+ - README.txt
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project: synfeld
92
+ rubygems_version: 1.2.0
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Synfeld is an application framework that does almost nothing, and it ain't all that classy
96
+ test_files:
97
+ - test/test_synfeld.rb