lib/engine2/core.rb in engine2-1.0.8 vs lib/engine2/core.rb in engine2-1.0.9
- old
+ new
@@ -124,10 +124,14 @@
s[0..num] + "..."
else
s
end
end
+
+ def escape_html
+ Rack::Utils.escape_html(self)
+ end
end
class Symbol
def icon
s = self
@@ -136,16 +140,22 @@
else
"<span class='glyphicon glyphicon-#{s}'></span>"
end
end
+ def loc
+ Engine2::LOCS[self]
+ end
+
def q col
col.qualify self
end
- def loc
- Engine2::LOCS[self]
+ def html body = '', attrs = {}
+ element = self.to_s
+ attrs = attrs.map{|k, v| "#{k}=\"#{v}\""}.join(" ")
+ "<#{element} #{attrs}>#{body}</#{element}>"
end
end
module Faye
class WebSocket
@@ -172,11 +182,11 @@
class Sequel::Database
attr_accessor :models, :default_schema
def cache_file
- "#{Engine2::SETTINGS.path_for(:db_path)}/#{opts[:orig_opts][:name]}.dump"
+ "#{Engine2::SETTINGS.path_for(:db_path)}/#{opts[:orig_opts][:name]}.schema_cache"
end
def load_schema_cache_from_file
self.models = {}
load_schema_cache? cache_file if adapter_scheme
@@ -280,11 +290,11 @@
@validate_fields.each do |name| # || type_info.keys
info = type_info[name]
next if info[:primary_key] && !model.natural_key
value = values[name].to_s
- value.strip! unless info[:dont_strip]
+ value.strip! unless value.frozen? || info[:dont_strip]
if value.empty?
if req = info[:required]
errors.add(name, req[:message]) if !req[:if] || req[:if].(self)
end
else
@@ -390,11 +400,10 @@
select_more(*sels)
end
else
select(*pk.map{|k| model.table_name.q(k)})
end
-
end
def extract_select sel, al = nil, &blk
case sel
when Symbol
@@ -411,45 +420,45 @@
end
end
def setup_query fields
joins = {}
- type_info = model.type_info
model_table_name = model.table_name
select = @opts[:select].map do |sel|
extract_select sel do |table, name, aliaz|
- info = if table
+ mdl = if table
if table == model_table_name
model
else
assoc = model.many_to_one_associations[table] || model.many_to_many_associations[table]
raise Engine2::E2Error.new("Association #{table} not found for model #{model}") unless assoc
assoc.associated_class
- end.type_info
+ end
else
- type_info
+ model
end
- table ||= model_table_name
- if table == model_table_name
+ mdl_table_name = mdl.table_name
+ table ||= mdl_table_name
+ if mdl_table_name == model_table_name
fields << name
else
fields << table.q(name)
- joins[table] ||= model.many_to_one_associations[table] || model.many_to_many_associations[table]
+ joins[mdl_table_name] ||= model.many_to_one_associations[table] || model.many_to_many_associations[table]
end
- f_info = info[name]
- raise Engine2::E2Error.new("Column #{name} not found for table #{table || model_table_name}") unless f_info
+ f_info = mdl.type_info[name]
+ raise Engine2::E2Error.new("Column #{name} not found for table #{table}") unless f_info
if f_info[:dummy]
nil
else
- qname = table.q(name)
- if table != model_table_name
- Sequel.alias_columns_in_joins ? qname.as(:"#{table}__#{name}") : qname
- else
+ qname = mdl_table_name.q(name)
+ if table == model_table_name
qname
+ else
+ Sequel.alias_columns_in_joins ? qname.as(:"#{table}__#{name}") : qname
end
end
end
end.compact
@@ -486,11 +495,10 @@
def initialize error
@error = error
end
end
-
end
module Engine2
LOCS ||= Hash.new{|h, k| ":#{k}:"}
PATH ||= File.expand_path('../..', File.dirname(__FILE__))
@@ -499,11 +507,12 @@
app_path: 'app',
db_path: 'db',
model_path: 'models',
view_path: 'views',
asset_path: 'assets',
- conf_path: 'conf'
+ conf_path: 'conf',
+ log_path: 'log'
}
def SETTINGS.path_for path
"#{self[:app_path]}/#{self[path]}"
end unless SETTINGS.frozen?
@@ -547,13 +556,13 @@
end
load "#{Engine2::SETTINGS[:app_path]}/boot.rb"
Sequel::DATABASES.each &:load_schema_cache_from_file
- @model_boot_blk.() if @model_boot_blk
load 'engine2/models/Files.rb'
load 'engine2/models/UserInfo.rb'
Dir["#{Engine2::SETTINGS.path_for(:model_path)}/*"].each{|m| load m}
+ @model_boot_blk.() if @model_boot_blk
puts "MODELS: #{Sequel::DATABASES.reduce(0){|s, d|s + d.models.size}}, Time: #{Time.now - t}"
Sequel::DATABASES.each do |db|
db.dump_schema_cache_to_file
db.models.each{|n, m|m.synchronize_type_info}
end