cramp 0.11 → 0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cramp.rb +12 -1
- data/lib/cramp/abstract.rb +72 -0
- data/lib/cramp/action.rb +12 -0
- data/lib/cramp/body.rb +48 -0
- data/lib/cramp/callbacks.rb +48 -0
- data/lib/cramp/keep_connection_alive.rb +19 -0
- data/lib/cramp/periodic_timer.rb +49 -0
- data/lib/cramp/rendering.rb +11 -0
- data/lib/cramp/test_case.rb +54 -0
- data/lib/cramp/websocket.rb +84 -0
- data/lib/cramp/{controller/websocket → websocket}/rainbows_backend.rb +1 -1
- data/lib/cramp/{controller/websocket → websocket}/thin_backend.rb +1 -1
- metadata +37 -86
- data/lib/cramp/controller.rb +0 -15
- data/lib/cramp/controller/abstract.rb +0 -71
- data/lib/cramp/controller/action.rb +0 -14
- data/lib/cramp/controller/body.rb +0 -50
- data/lib/cramp/controller/callbacks.rb +0 -50
- data/lib/cramp/controller/keep_connection_alive.rb +0 -21
- data/lib/cramp/controller/periodic_timer.rb +0 -51
- data/lib/cramp/controller/rendering.rb +0 -13
- data/lib/cramp/controller/test_case.rb +0 -57
- data/lib/cramp/controller/websocket.rb +0 -63
- data/lib/cramp/model.rb +0 -40
- data/lib/cramp/model/arel_monkey_patches.rb +0 -66
- data/lib/cramp/model/attribute.rb +0 -104
- data/lib/cramp/model/attribute_methods.rb +0 -83
- data/lib/cramp/model/base.rb +0 -119
- data/lib/cramp/model/callbacks.rb +0 -41
- data/lib/cramp/model/column.rb +0 -72
- data/lib/cramp/model/emysql_ext.rb +0 -21
- data/lib/cramp/model/engine.rb +0 -75
- data/lib/cramp/model/engine/connection.rb +0 -32
- data/lib/cramp/model/evented_mysql.rb +0 -298
- data/lib/cramp/model/finders.rb +0 -27
- data/lib/cramp/model/quoting.rb +0 -104
- data/lib/cramp/model/relation.rb +0 -62
- data/lib/cramp/model/status.rb +0 -18
data/lib/cramp/model/finders.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Cramp
|
2
|
-
module Model
|
3
|
-
module Finders
|
4
|
-
|
5
|
-
delegate :all, :first, :each, :where, :select, :group, :order, :limit, :offset, :to => :relation
|
6
|
-
|
7
|
-
def [](attribute)
|
8
|
-
arel_table[attribute]
|
9
|
-
end
|
10
|
-
|
11
|
-
def arel_table
|
12
|
-
@arel_table ||= Arel::Table.new(table_name)
|
13
|
-
end
|
14
|
-
|
15
|
-
def relation
|
16
|
-
Relation.new(self, arel_table)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def table_name
|
22
|
-
self.to_s.demodulize.underscore.pluralize
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/cramp/model/quoting.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# Yanked from Rails
|
2
|
-
|
3
|
-
# Copyright (c) 2004-2009 David Heinemeier Hansson
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
|
24
|
-
module Cramp
|
25
|
-
module Model
|
26
|
-
module Quoting
|
27
|
-
def quote_column_name(name)
|
28
|
-
@quoted_column_names[name] ||= "`#{name}`"
|
29
|
-
end
|
30
|
-
|
31
|
-
def quote_table_name(name)
|
32
|
-
@quoted_table_names[name] ||= quote_column_name(name).gsub('.', '`.`')
|
33
|
-
end
|
34
|
-
|
35
|
-
def quote(value, column = nil)
|
36
|
-
if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
|
37
|
-
s = value.unpack("H*")[0]
|
38
|
-
"x'#{s}'"
|
39
|
-
elsif value.kind_of?(BigDecimal)
|
40
|
-
value.to_s("F")
|
41
|
-
else
|
42
|
-
super
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def quote(value, column = nil)
|
47
|
-
# records are quoted as their primary key
|
48
|
-
return value.quoted_id if value.respond_to?(:quoted_id)
|
49
|
-
|
50
|
-
case value
|
51
|
-
when String, ActiveSupport::Multibyte::Chars
|
52
|
-
value = value.to_s
|
53
|
-
if column && column.type == :binary && column.class.respond_to?(:string_to_binary)
|
54
|
-
"#{quoted_string_prefix}'#{quote_string(column.class.string_to_binary(value))}'" # ' (for ruby-mode)
|
55
|
-
elsif column && [:integer, :float].include?(column.type)
|
56
|
-
value = column.type == :integer ? value.to_i : value.to_f
|
57
|
-
value.to_s
|
58
|
-
else
|
59
|
-
"#{quoted_string_prefix}'#{quote_string(value)}'" # ' (for ruby-mode)
|
60
|
-
end
|
61
|
-
when NilClass then "NULL"
|
62
|
-
when TrueClass then (column && column.type == :integer ? '1' : quoted_true)
|
63
|
-
when FalseClass then (column && column.type == :integer ? '0' : quoted_false)
|
64
|
-
when Float, Fixnum, Bignum then value.to_s
|
65
|
-
# BigDecimals need to be output in a non-normalized form and quoted.
|
66
|
-
when BigDecimal then value.to_s('F')
|
67
|
-
else
|
68
|
-
if value.acts_like?(:date) || value.acts_like?(:time)
|
69
|
-
"'#{quoted_date(value)}'"
|
70
|
-
else
|
71
|
-
"#{quoted_string_prefix}'#{quote_string(value.to_yaml)}'"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Quotes a string, escaping any ' (single quote) and \ (backslash)
|
77
|
-
# characters.
|
78
|
-
def quote_string(s)
|
79
|
-
s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
|
80
|
-
end
|
81
|
-
|
82
|
-
def quoted_true
|
83
|
-
"'t'"
|
84
|
-
end
|
85
|
-
|
86
|
-
def quoted_false
|
87
|
-
"'f'"
|
88
|
-
end
|
89
|
-
|
90
|
-
def quoted_date(value)
|
91
|
-
if value.acts_like?(:time)
|
92
|
-
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
|
93
|
-
value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
|
94
|
-
else
|
95
|
-
value
|
96
|
-
end.to_s(:db)
|
97
|
-
end
|
98
|
-
|
99
|
-
def quoted_string_prefix
|
100
|
-
''
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/cramp/model/relation.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
module Cramp
|
2
|
-
module Model
|
3
|
-
class Relation
|
4
|
-
|
5
|
-
def initialize(klass, relation)
|
6
|
-
@klass, @relation = klass, relation
|
7
|
-
end
|
8
|
-
|
9
|
-
def each(callback = nil, &block)
|
10
|
-
callback ||= block
|
11
|
-
|
12
|
-
@relation.each do |row|
|
13
|
-
object = @klass.instantiate(row)
|
14
|
-
callback.call(object)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def all(callback = nil, &block)
|
19
|
-
callback ||= block
|
20
|
-
|
21
|
-
@relation.all do |rows|
|
22
|
-
objects = rows.map {|r| @klass.instantiate(r) }
|
23
|
-
callback.call(objects)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def first(callback = nil, &block)
|
28
|
-
callback ||= block
|
29
|
-
|
30
|
-
@relation.first do |row|
|
31
|
-
object = row ? @klass.instantiate(row) : nil
|
32
|
-
callback.call(object)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def where(*conditions)
|
37
|
-
Relation.new(@klass, @relation.where(*conditions))
|
38
|
-
end
|
39
|
-
|
40
|
-
def select(*selects)
|
41
|
-
Relation.new(@klass, @relation.project(*selects))
|
42
|
-
end
|
43
|
-
|
44
|
-
def group(groups)
|
45
|
-
Relation.new(@klass, @relation.group(groups))
|
46
|
-
end
|
47
|
-
|
48
|
-
def order(orders)
|
49
|
-
Relation.new(@klass, @relation.order(orders))
|
50
|
-
end
|
51
|
-
|
52
|
-
def limit(limits)
|
53
|
-
Relation.new(@klass, @relation.take(limits))
|
54
|
-
end
|
55
|
-
|
56
|
-
def offset(offsets)
|
57
|
-
Relation.new(@klass, @relation.skip(offsets))
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/lib/cramp/model/status.rb
DELETED