studio54 0.0.5
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/Gemfile +31 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +25 -0
- data/README.md +0 -0
- data/Rakefile +56 -0
- data/VERSION +5 -0
- data/app/controllers/users_controller.rb +29 -0
- data/app/models/post.rb +4 -0
- data/app/models/user.rb +46 -0
- data/bare/Gemfile +31 -0
- data/bare/Rakefile +28 -0
- data/bare/config.ru +9 -0
- data/bare/config/app_tie.rb +12 -0
- data/bare/config/db.rb +20 -0
- data/bare/config/db_connect.rb +19 -0
- data/bare/config/environment.rb +17 -0
- data/bare/config/sinatra.rb +36 -0
- data/bare/config/studio54_tie.rb +2 -0
- data/bare/dance.rb +11 -0
- data/bare/lib/after_filters.rb +7 -0
- data/bare/lib/before_filters.rb +7 -0
- data/bare/lib/helpers.rb +5 -0
- data/bare/public/index.rhtml +1 -0
- data/bare/public/layout.rhtml +12 -0
- data/bare/static/css/base.css +86 -0
- data/bare/static/css/yui_reset.css +30 -0
- data/bare/test/helpers.rb +8 -0
- data/bare/test/suite.rb +13 -0
- data/bin/studio54 +65 -0
- data/config.ru +9 -0
- data/config/app_tie.rb +8 -0
- data/config/db.rb +20 -0
- data/config/db_connect.rb +19 -0
- data/config/environment.rb +17 -0
- data/config/sinatra.rb +36 -0
- data/dance.rb +80 -0
- data/ideas +0 -0
- data/lib/after_filters.rb +7 -0
- data/lib/base.rb +29 -0
- data/lib/before_filters.rb +30 -0
- data/lib/helpers.rb +24 -0
- data/lib/lazy_controller.rb +87 -0
- data/lib/lazy_record.rb +395 -0
- data/lib/partials.rb +19 -0
- data/lib/studio54.rb +14 -0
- data/lib/vendor.rb +23 -0
- data/public/_partial_test.rhtml +4 -0
- data/public/all.rhtml +7 -0
- data/public/form.rhtml +11 -0
- data/public/index.rhtml +6 -0
- data/public/layout.rhtml +15 -0
- data/public/partial_test.rhtml +6 -0
- data/public/test_find_by.rhtml +4 -0
- data/rack/cache/body/ec/b48431757330e446c58d88e317574ef0eca2e9 +0 -0
- data/rack/cache/meta/25/3a7a342a66b79119b7b8cb34bda89978f9e606 +0 -0
- data/rack/cache/meta/c1/34c9b7112c7d884220d6ee9a8e43ec69d2ea6e +0 -0
- data/static/css/base.css +86 -0
- data/static/css/yui_reset.css +30 -0
- data/static/hello.html +1 -0
- data/studio54.gemspec +25 -0
- data/tags +149 -0
- data/test/email.rb +8 -0
- data/test/environment.rb +28 -0
- data/test/helpers.rb +8 -0
- data/test/integration/index_test.rb +41 -0
- data/test/integration/partial_test.rb +50 -0
- data/test/mail/email_test.rb +14 -0
- data/test/rack/helpers.rb +23 -0
- data/test/suite.rb +8 -0
- data/test/unit/associations_test.rb +33 -0
- data/test/unit/callbacks_test.rb +16 -0
- data/test/unit/database_test.rb +73 -0
- data/test/unit/model_introspection_test.rb +44 -0
- data/test/unit/serialization_test.rb +19 -0
- data/test/unit/validations_test.rb +73 -0
- metadata +165 -0
data/Gemfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem "rack"
|
4
|
+
gem "rack-cache"
|
5
|
+
gem "rack-flash"
|
6
|
+
gem "sinatra"
|
7
|
+
# Check config/app_tie to see which active_support files are required.
|
8
|
+
# Note: many required files require other active_support files in turn.
|
9
|
+
gem "activesupport"
|
10
|
+
gem "activemodel"
|
11
|
+
|
12
|
+
# dbi
|
13
|
+
gem "dbi"
|
14
|
+
# dbi driver
|
15
|
+
gem "dbd-mysql"
|
16
|
+
|
17
|
+
# optional, only need if serving xml
|
18
|
+
gem "builder"
|
19
|
+
|
20
|
+
# optional, for sending email
|
21
|
+
gem "pony"
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem "thin"
|
25
|
+
gem "shotgun"
|
26
|
+
end
|
27
|
+
|
28
|
+
group :test do
|
29
|
+
gem "rack-test"
|
30
|
+
end
|
31
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.0)
|
5
|
+
activesupport (= 3.0.0)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.4.1)
|
8
|
+
activesupport (3.0.0)
|
9
|
+
builder (2.1.2)
|
10
|
+
daemons (1.1.4)
|
11
|
+
dbd-mysql (0.4.4)
|
12
|
+
dbi (>= 0.4.0)
|
13
|
+
mysql
|
14
|
+
dbi (0.4.5)
|
15
|
+
deprecated (= 2.0.1)
|
16
|
+
deprecated (2.0.1)
|
17
|
+
eventmachine (0.12.10)
|
18
|
+
i18n (0.4.2)
|
19
|
+
mail (2.3.0)
|
20
|
+
i18n (>= 0.4.0)
|
21
|
+
mime-types (~> 1.16)
|
22
|
+
treetop (~> 1.4.8)
|
23
|
+
mime-types (1.17.2)
|
24
|
+
mysql (2.8.1)
|
25
|
+
polyglot (0.3.2)
|
26
|
+
pony (1.3)
|
27
|
+
mail (> 2.0)
|
28
|
+
rack (1.3.4)
|
29
|
+
rack-cache (1.1)
|
30
|
+
rack (>= 0.4)
|
31
|
+
rack-flash (0.1.2)
|
32
|
+
rack
|
33
|
+
rack-protection (1.1.4)
|
34
|
+
rack
|
35
|
+
rack-test (0.6.1)
|
36
|
+
rack (>= 1.0)
|
37
|
+
shotgun (0.9)
|
38
|
+
rack (>= 1.0)
|
39
|
+
sinatra (1.3.1)
|
40
|
+
rack (~> 1.3, >= 1.3.4)
|
41
|
+
rack-protection (~> 1.1, >= 1.1.2)
|
42
|
+
tilt (~> 1.3, >= 1.3.3)
|
43
|
+
thin (1.2.11)
|
44
|
+
daemons (>= 1.0.9)
|
45
|
+
eventmachine (>= 0.12.6)
|
46
|
+
rack (>= 1.0.0)
|
47
|
+
tilt (1.3.3)
|
48
|
+
treetop (1.4.10)
|
49
|
+
polyglot
|
50
|
+
polyglot (>= 0.3.1)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
activemodel
|
57
|
+
activesupport
|
58
|
+
builder
|
59
|
+
dbd-mysql
|
60
|
+
dbi
|
61
|
+
pony
|
62
|
+
rack
|
63
|
+
rack-cache
|
64
|
+
rack-flash
|
65
|
+
rack-test
|
66
|
+
shotgun
|
67
|
+
sinatra
|
68
|
+
thin
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2011 by Luke Gruber
|
2
|
+
|
3
|
+
This software is a bridge between Sinatra, parts of Rails, and my own
|
4
|
+
code. The code herein is licensed either under the same license as
|
5
|
+
Sinatra, the same license as Rails, or the 'MIT' license contained
|
6
|
+
below. The user can choose which license suits their needs the best.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
a copy of this software and associated documentation files (the
|
10
|
+
"Software"), to deal in the Software without restriction, including
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included
|
17
|
+
in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
22
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
23
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
24
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
25
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
$:.unshift 'lib'
|
2
|
+
$:.unshift 'rakelib'
|
3
|
+
$:.unshift 'config'
|
4
|
+
require 'environment'
|
5
|
+
include Studio54::Config::Environment
|
6
|
+
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'fileutils'
|
10
|
+
include FileUtils
|
11
|
+
|
12
|
+
task :default => [:output_test_count]
|
13
|
+
|
14
|
+
task :output_test_count do
|
15
|
+
files = Dir.glob(File.join(ROOTDIR, 'test', '**/*'))
|
16
|
+
puts "#{files.count} test files to run."
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :gem do
|
20
|
+
desc 'rebuild the studio54 gem'
|
21
|
+
task :rebuild do
|
22
|
+
if `gem list | grep studio54`
|
23
|
+
system("gem uninstall studio54 --executables")
|
24
|
+
end
|
25
|
+
gemfile = Dir.glob 'studio54-*'
|
26
|
+
rm gemfile
|
27
|
+
gemspec = 'studio54.gemspec'
|
28
|
+
system "gem build #{gemspec}"
|
29
|
+
new_gemfile = Dir.glob 'studio54-*'
|
30
|
+
system "gem install #{new_gemfile}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
namespace :test do
|
35
|
+
desc 'Run test suite (suite.rb)'
|
36
|
+
Rake::TestTask.new(:suite) do |t|
|
37
|
+
t.test_files = FileList['test/suite*'].to_a
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Run unit tests (test/unit/*)'
|
41
|
+
Rake::TestTask.new(:unit) do |t|
|
42
|
+
t.test_files = FileList['test/unit/runner*'].to_a
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Run integration tests (test/integration/*)'
|
46
|
+
Rake::TestTask.new(:integration) do |t|
|
47
|
+
t.test_files = FileList['test/integration/runner*'].to_a
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Run email tests (test/email/*)'
|
51
|
+
Rake::TestTask.new(:email) do |t|
|
52
|
+
t.test_files = FileList['test/email*'].to_a
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class UsersController < LazyController
|
2
|
+
|
3
|
+
before_action :index do |obj|
|
4
|
+
@second_user = 'me'
|
5
|
+
end
|
6
|
+
|
7
|
+
def index
|
8
|
+
@user = User.find(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def all
|
12
|
+
@users = User.all
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_by
|
16
|
+
@user = User.find_by({:name => "andrew", :id => 5}, :conjunction => 'OR')
|
17
|
+
end
|
18
|
+
|
19
|
+
def new
|
20
|
+
@user = User.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(params)
|
24
|
+
@user = User.new params[:user]
|
25
|
+
@user.save
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
data/app/models/post.rb
ADDED
data/app/models/user.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
class User < LazyRecord
|
2
|
+
attr_primary :id
|
3
|
+
tbl_attr_accessor :name, :age
|
4
|
+
has_many :posts
|
5
|
+
attr_accessor :humor
|
6
|
+
attr_accessor :email
|
7
|
+
|
8
|
+
# validations
|
9
|
+
validates_presence_of :humor
|
10
|
+
validates_length_of :name, :minimum => 5, :message => 'is too short'
|
11
|
+
validates_numericality_of :age, :less_than => 99, :message => 'must be less than 99'
|
12
|
+
validates_format_of :email, :without => /SPAM/
|
13
|
+
|
14
|
+
validate :name_not_blank
|
15
|
+
validate :age_greater_than_18
|
16
|
+
def name_not_blank
|
17
|
+
errors.add(:name, "can't be blank") if self.name.blank?
|
18
|
+
end
|
19
|
+
|
20
|
+
def age_greater_than_18
|
21
|
+
errors.add(:age, "must be greater than 18") if self.age.to_i <= 18
|
22
|
+
end
|
23
|
+
|
24
|
+
define_callbacks :drink
|
25
|
+
set_callback :drink, :before do |obj|
|
26
|
+
obj.age = 21
|
27
|
+
end
|
28
|
+
def drink
|
29
|
+
run_callbacks :drink do
|
30
|
+
"mmm"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
define_callbacks :save
|
35
|
+
set_callback :save, :before do |object|
|
36
|
+
@humor = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def save
|
40
|
+
run_callbacks :save do
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
data/bare/Gemfile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem "rack"
|
4
|
+
gem "rack-cache"
|
5
|
+
gem "rack-flash"
|
6
|
+
gem "sinatra"
|
7
|
+
# Check config/app_tie to see which active_support files are required.
|
8
|
+
# Note: many required files require other active_support files in turn.
|
9
|
+
gem "activesupport"
|
10
|
+
gem "activemodel"
|
11
|
+
|
12
|
+
# optional, only need it if serving xml
|
13
|
+
gem "builder"
|
14
|
+
|
15
|
+
# dbi
|
16
|
+
gem "dbi"
|
17
|
+
# dbi driver
|
18
|
+
gem "dbd-mysql"
|
19
|
+
|
20
|
+
#optional, for sending email
|
21
|
+
#gem "pony"
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem "thin"
|
25
|
+
gem "shotgun"
|
26
|
+
end
|
27
|
+
|
28
|
+
group :test do
|
29
|
+
gem "rack-test"
|
30
|
+
end
|
31
|
+
|
data/bare/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.unshift 'lib'
|
2
|
+
$:.unshift 'rakelib'
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/clean'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
task :test => [:output_test_count]
|
9
|
+
|
10
|
+
desc 'Run all *_tests and *_specs (default)'
|
11
|
+
test = Rake::TestTask.new(:test) do |t|
|
12
|
+
TEST_LIST = FileList['test/*_test.rb'].to_a
|
13
|
+
SPEC_LIST = FileList['test/*_spec.rb'].to_a
|
14
|
+
t.test_files = TEST_LIST
|
15
|
+
t.test_files + SPEC_LIST unless SPEC_LIST.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
task :output_test_count do
|
19
|
+
puts(TEST_LIST.count + SPEC_LIST.count).to_s + " test files to run."
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :test do
|
23
|
+
desc 'Run test suite (suite.rb)'
|
24
|
+
Rake::TestTask.new(:suite) do |t|
|
25
|
+
t.test_files = FileList['test/suite.rb'].to_a
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/bare/config.ru
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Studio54
|
2
|
+
require_relative 'environment'
|
3
|
+
include Config::Environment
|
4
|
+
require 'config/studio54_tie'
|
5
|
+
require 'config/sinatra'
|
6
|
+
require 'config/db'
|
7
|
+
|
8
|
+
require File.join(LIBDIR, 'before_filters')
|
9
|
+
require File.join(LIBDIR, 'after_filters')
|
10
|
+
require File.join(LIBDIR, 'helpers')
|
11
|
+
end
|
12
|
+
|
data/bare/config/db.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Studio54
|
2
|
+
class Db
|
3
|
+
|
4
|
+
cattr_accessor :host
|
5
|
+
cattr_accessor :user
|
6
|
+
cattr_accessor :pass
|
7
|
+
cattr_accessor :schema
|
8
|
+
cattr_accessor :type
|
9
|
+
cattr_accessor :conn
|
10
|
+
|
11
|
+
self.host = 'localhost'
|
12
|
+
self.user = 'root'
|
13
|
+
self.pass = 'root'
|
14
|
+
self.schema = 'test'
|
15
|
+
# Mysql
|
16
|
+
self.type = 'Mysql'
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Studio54
|
2
|
+
begin
|
3
|
+
Db.conn.disconnect if Db.conn.kind_of? DBI::DatabaseHandle and
|
4
|
+
Db.conn.connected?
|
5
|
+
|
6
|
+
# connect to the MySQL server
|
7
|
+
Db.conn = DBI.connect("DBI:#{Db.type}:#{Db.schema}:#{Db.host}",
|
8
|
+
Db.user, Db.pass)
|
9
|
+
|
10
|
+
rescue DBI::DatabaseError => e
|
11
|
+
puts "Error code: #{e.err}"
|
12
|
+
puts "Error message: #{e.errstr}"
|
13
|
+
puts "Error SQLSTATE: #{e.state}" if e.respond_to? :state
|
14
|
+
|
15
|
+
# Db.conn is disconnected automatically if used in a controller
|
16
|
+
# action
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Studio54
|
2
|
+
module Config
|
3
|
+
module Environment
|
4
|
+
|
5
|
+
ROOTDIR = File.expand_path(File.dirname(__FILE__) + '/..')
|
6
|
+
APPDIR = File.join(ROOTDIR, "app")
|
7
|
+
LIBDIR = File.join(ROOTDIR, "lib")
|
8
|
+
BINDIR = File.join(ROOTDIR, "bin")
|
9
|
+
CONFIGDIR = File.join(ROOTDIR, "config")
|
10
|
+
MODELSDIR = File.join(APPDIR, "models")
|
11
|
+
CONTROLLERSDIR = File.join(APPDIR, "controllers")
|
12
|
+
|
13
|
+
$:.unshift(ROOTDIR) unless $:.include? ROOTDIR
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Studio54::Dancefloor < Sinatra::Base
|
2
|
+
|
3
|
+
set :app_file, __FILE__
|
4
|
+
|
5
|
+
configure :development do
|
6
|
+
set :server, %w[thin mongrel webrick]
|
7
|
+
set :dump_errors, false
|
8
|
+
set :shotgun, false
|
9
|
+
end
|
10
|
+
|
11
|
+
configure :production do
|
12
|
+
set :shotgun, false
|
13
|
+
end
|
14
|
+
|
15
|
+
# app root dir
|
16
|
+
set :root, File.join(File.expand_path(File.dirname(__FILE__)), '..')
|
17
|
+
### Static Files ###
|
18
|
+
# serve static files
|
19
|
+
set :static, true
|
20
|
+
# static file directory, served_from => :views.
|
21
|
+
# To override Sinatra's wrapping of rack/static, disable
|
22
|
+
# set :static and set :public_folder and explicity use
|
23
|
+
# Rack::Static from config.ru.
|
24
|
+
set :public_folder, Proc.new { File.join(root, 'static') }
|
25
|
+
###
|
26
|
+
# template files directory
|
27
|
+
set :views, Proc.new { File.join(root, 'public') }
|
28
|
+
# whether or not to use layout.* in view folder
|
29
|
+
set :erb, :layout => true
|
30
|
+
|
31
|
+
# enable sessions
|
32
|
+
set :sessions, true
|
33
|
+
# using _method (PUT, DELETE)
|
34
|
+
set :method_override, true
|
35
|
+
end
|
36
|
+
|