spiderfw 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -351,7 +351,7 @@ module Spider; module WebDAV
351
351
  raise HTTPStatus.NO_CONTENT
352
352
  else
353
353
  Spider::Logger.error("UNLOCK OF #{path} FAILED!!!")
354
- raise Forbidden
354
+ raise Forbidden, "Unlock of path #{path}"
355
355
  end
356
356
  end
357
357
 
@@ -362,7 +362,7 @@ module Spider; module WebDAV
362
362
  begin
363
363
  vfs.mkdir(path)
364
364
  rescue Errno::ENOENT, Errno::EACCES
365
- raise Forbidden
365
+ raise Forbidden, "MKCOL of path #{path}"
366
366
  rescue Errno::ENOSPC
367
367
  raise HTTPStatus.WEBDAV_INSUFFICIENT_STORAGE
368
368
  rescue Errno::EEXIST
@@ -378,7 +378,7 @@ module Spider; module WebDAV
378
378
 
379
379
  vfs.unlock_all(lock.resource) if vfs.locking? and lock
380
380
  rescue Errno::EPERM
381
- raise Forbidden
381
+ raise Forbidden, "DELETE #{path}"
382
382
  end
383
383
  raise HTTPStatus.NO_CONTENT
384
384
  end
@@ -829,7 +829,7 @@ module Spider; module WebDAV
829
829
  src = path
830
830
  dest = normalize_path(@request.env['HTTP_DESTINATION'])
831
831
 
832
- src == dest and raise Forbidden
832
+ src == dest and raise Forbidden, "Copy or move #{src} on itself"
833
833
 
834
834
  if @request.env['REQUEST_METHOD'] == 'MOVE'
835
835
  # MOVE - check lock on source
@@ -77,11 +77,11 @@ module Spider; module WebDAV; module VFS
77
77
  end
78
78
 
79
79
  def cp(src, dst, recursive=true)
80
- raise Forbidden
80
+ raise Forbidden, "Copy #{src} -> #{dst}"
81
81
  end
82
82
 
83
83
  def mv(src, dst)
84
- raise Forbidden
84
+ raise Forbidden, "Move #{src} -> #{dst}"
85
85
  end
86
86
 
87
87
  def exists?(path)
data/lib/spiderfw/app.rb CHANGED
@@ -68,6 +68,7 @@ module Spider
68
68
  ms << m
69
69
  m.constants.each do |c|
70
70
  sub_mod = m.const_get(c)
71
+ next unless sub_mod.is_a?(Module)
71
72
  next if !sub_mod.subclass_of?(Spider::Model::BaseModel) || sub_mod.app != self
72
73
  next if sub_mod == m
73
74
  ms += get_models(sub_mod)
@@ -21,6 +21,7 @@ module Spider
21
21
  config_option 'webserver.port', _("Port to use for the http server"), :default => 8080
22
22
  config_option 'webserver.force_threads', _("Force threading on non-threaded adapters"),
23
23
  :default => Proc.new{ RUBY_VERSION_PARTS[1] == '8' ? true : false }
24
+ config_option 'webserver.timeout', _("Time allowed for each request (in seconds)"), :type=> Fixnum, :default => nil
24
25
  # Client
25
26
  config_option 'client.text_editor', _("The text editor installed on the client")
26
27
 
@@ -77,6 +77,8 @@ module Spider
77
77
  def try_rescue(exc)
78
78
  if exc.is_a?(Spider::Controller::NotFound)
79
79
  Spider.logger.error("Not found: #{exc.path}")
80
+ elsif exc.is_a?(Spider::Controller::Forbidden)
81
+ Spider.logger.warn("Forbidden: #{exc.message}")
80
82
  else
81
83
  super
82
84
  end
@@ -78,6 +78,17 @@ module Spider; module HTTP
78
78
 
79
79
  def initialize(server)
80
80
  @server = server
81
+ if (Spider.conf.get('webserver.timeout'))
82
+ begin
83
+ require 'system_timer'
84
+ @timer = SystemTimer
85
+ rescue LoadError
86
+ require 'timeout'
87
+ @timer = Timeout
88
+ end
89
+
90
+ end
91
+
81
92
  #@request_notify = true
82
93
  end
83
94
 
@@ -113,16 +124,25 @@ module Spider; module HTTP
113
124
  end
114
125
 
115
126
  begin
116
- controller = ::Spider::HTTPController.new(controller_request, controller_response)
117
- controller.extend(Spider::FirstResponder)
118
- Spider::Logger.debug("CONTROLLER: #{controller}")
119
- controller.before(path)
120
- MongrelIO.send_headers(controller_response, response) unless Spider.conf.get('http.auto_headers')
121
- controller.execute(path)
122
- Spider::Logger.debug("Response:")
123
- Spider::Logger.debug(controller.response)
124
- controller.after(path)
125
- Spider::Logger.debug("Controller #{controller} DONE")
127
+ main_block = lambda do
128
+ controller = ::Spider::HTTPController.new(controller_request, controller_response)
129
+ controller.extend(Spider::FirstResponder)
130
+ Spider::Logger.debug("CONTROLLER: #{controller}")
131
+ controller.before(path)
132
+ MongrelIO.send_headers(controller_response, response) unless Spider.conf.get('http.auto_headers')
133
+ controller.execute(path)
134
+ Spider::Logger.debug("Response:")
135
+ Spider::Logger.debug(controller.response)
136
+ controller.after(path)
137
+ Spider::Logger.debug("Controller #{controller} DONE")
138
+ end
139
+ if (Spider.conf.get('webserver.timeout'))
140
+ @timer.timeout(Spider.conf.get('webserver.timeout')) do
141
+ main_block.call
142
+ end
143
+ else
144
+ main_block.call
145
+ end
126
146
  rescue => exc
127
147
  Spider.logger.error(exc)
128
148
  controller.ensure() if controller
@@ -210,7 +210,7 @@ module Spider; module Model
210
210
 
211
211
  orig_type = type
212
212
  assoc_type = nil
213
- if (attributes[:junction] || (attributes[:multiple] && (!attributes[:add_reverse]) && (!attributes[:has_single_reverse]) && \
213
+ if (proc || attributes[:junction] || (attributes[:multiple] && (!attributes[:add_reverse]) && (!attributes[:has_single_reverse]) && \
214
214
  # FIXME! the first check is needed when the referenced class has not been parsed yet
215
215
  # but now it assumes that the reverse is not multiple if it is not defined
216
216
  (attributes[:has_single_reverse] == false || !attributes[:reverse] || (!type.elements[attributes[:reverse]] || type.elements[attributes[:reverse]].multiple?))))
@@ -807,6 +807,11 @@ module Spider; module Model
807
807
  @mapper_modules << mod
808
808
  end
809
809
 
810
+ def self.mapper_include_for(params, mod)
811
+ @mapper_modules_for ||= []
812
+ @mapper_modules_for << [params, mod]
813
+ end
814
+
810
815
  # The given proc will be mixed in the mapper used by this class
811
816
  # Note that the proc will be converted to a Module, so any overridden methods will still have
812
817
  # access to the super method.
@@ -881,6 +886,13 @@ module Spider; module Model
881
886
  if (@mapper_modules)
882
887
  @mapper_modules.each{ |mod| mapper.extend(mod) }
883
888
  end
889
+ if (@mapper_modules_for)
890
+ @mapper_modules_for.each do |params, mod|
891
+ if params.is_a?(String)
892
+ mapper.extend(mod) if self.use_storage == params
893
+ end
894
+ end
895
+ end
884
896
  if (@mapper_procs)
885
897
  @mapper_procs.each{ |proc| mapper.instance_eval(&proc) }
886
898
  end
@@ -1059,7 +1071,7 @@ module Spider; module Model
1059
1071
  end
1060
1072
  end
1061
1073
  obj.identity_mapper = self.identity_mapper if obj.respond_to?(:identity_mapper)
1062
- if (element.attributes[:junction] && element.attributes[:keep_junction])
1074
+ if (element.multiple? && element.attributes[:junction] && element.attributes[:keep_junction])
1063
1075
  obj.append_element = element.attributes[:junction_their_element]
1064
1076
  end
1065
1077
  if (element.attributes[:set] && element.attributes[:set].is_a?(Hash))
@@ -1108,8 +1120,9 @@ module Spider; module Model
1108
1120
  element = element.name if (element.class == Spider::Model::Element)
1109
1121
  first, rest = element.to_s.split('.', 2)
1110
1122
  if (rest)
1111
- return nil unless element_has_value?(first.to_sym)
1112
- return send(first).get(rest)
1123
+ sub_val = send(first)
1124
+ return nil unless sub_val
1125
+ return sub_val.get(rest)
1113
1126
  end
1114
1127
  return send(element)
1115
1128
  end
@@ -337,10 +337,11 @@ module Spider; module Model; module Mappers
337
337
  primary_keys << field if model_pks.include?(el)
338
338
  seen_fields[field.name] = true
339
339
  end
340
- elsif (!element.multiple?)
340
+ elsif (!element.attributes[:junction])
341
341
  if (schema.has_foreign_fields?(el))
342
342
  element.model.primary_keys.each do |key|
343
343
  field = schema.foreign_key_field(el, key.name)
344
+ raise "Can't find a foreign key field for key #{key.name} of element #{el} of model #{@model}" unless field
344
345
  unless seen_fields[field.name]
345
346
  keys << field
346
347
  primary_keys << field if model_pks.include?(el)
@@ -459,10 +460,28 @@ module Spider; module Model; module Mappers
459
460
  element = model.elements[k.to_sym]
460
461
  if (!v.is_a?(Condition) && element.model?)
461
462
  condition.delete(element.name)
462
- if (v.is_a?(BaseModel))
463
- element.model.primary_keys.each do |primary_key|
464
- condition.set("#{element.name}.#{primary_key.name}", '=', v.get(primary_key))
463
+ def set_pks_condition(condition, el, val, prefix)
464
+ el.model.primary_keys.each do |primary_key|
465
+ new_prefix = "#{prefix}.#{primary_key.name}"
466
+ if (primary_key.model?)
467
+ if (primary_key.model.primary_keys.length == 1)
468
+ # FIXME: this should not be needed, see below
469
+ condition.set(new_prefix, '=', val.get(primary_key).get(primary_key.model.primary_keys[0]))
470
+ else
471
+ # FIXME! does not work, the subcondition does not get processed
472
+ raise "Subonditions on multiple key elements not supported yet"
473
+ set_pks_condition(condition, primary_key, val.get(primary_key), new_prefix)
474
+ end
475
+ else
476
+ condition.set(new_prefix, '=', val.get(primary_key))
477
+ end
465
478
  end
479
+ end
480
+ if (v.is_a?(BaseModel))
481
+ set_pks_condition(condition, element, v, element.name)
482
+ # element.model.primary_keys.each do |primary_key|
483
+ # condition.set("#{element.name}.#{primary_key.name}", '=', v.get(primary_key))
484
+ # end
466
485
  elsif (element.model.primary_keys.length == 1 )
467
486
  new_v = Condition.new
468
487
  if (model.mapper.have_references?(element.name))
@@ -892,7 +911,7 @@ module Spider; module Model; module Mappers
892
911
  column.primary_key = true if element.primary_key?
893
912
  schema.set_column(element.name, column)
894
913
  elsif (true) # FIXME: must have condition element.storage == @storage in some of the subcases
895
- if (!element.multiple?) # 1/n <-> 1
914
+ if (!element.multiple? && !element.attributes[:junction]) # 1/n <-> 1
896
915
  current_schema = schema.foreign_keys[element.name] || {}
897
916
  foreign_key_constraints = {}
898
917
  element.type.primary_keys.each do |key|
@@ -315,7 +315,12 @@ module Spider; module Model
315
315
  def search_key(obj, name) # :nodoc:
316
316
  sub = obj.is_a?(Hash) ? obj[name] : obj.get(name.to_sym)
317
317
  if (sub.is_a?(Spider::Model::BaseModel))
318
- @model.elements[name.to_sym].type.primary_keys.map{ |k| sub.get(k).to_s }.join(',')
318
+ name_parts = name.to_s.split('.')
319
+ model = @model
320
+ name_parts.each do |part|
321
+ model = model.elements[part.to_sym].type
322
+ end
323
+ model.primary_keys.map{ |k| sub.get(k).to_s }.join(',')
319
324
  else
320
325
  sub.to_s
321
326
  end
@@ -108,10 +108,13 @@ module Spider; module Model; module Storage; module Db
108
108
  case type.name
109
109
  when 'Date', 'DateTime'
110
110
  return nil unless value
111
+ return value if value.is_a?(Type)
111
112
  return value.to_datetime if type == DateTime
112
113
  return value.to_date # FIXME: check what is returned, here we espect an OCI8::Date
113
114
  when 'Spider::DataTypes::Text'
114
115
  value = value.read if value.respond_to?(:read)
116
+ when 'Spider::DataTypes::Decimal', 'BigDecimal'
117
+ value = value.to_s
115
118
  end
116
119
  return super(type, value)
117
120
  end
@@ -276,7 +279,7 @@ module Spider; module Model; module Storage; module Db
276
279
  pk_sql = query[:primary_keys].join(', ')
277
280
  distinct_sql = "SELECT DISTINCT #{pk_sql} FROM #{tables_sql}"
278
281
  distinct_sql += " WHERE #{where}" if where && !where.empty?
279
- data_sql = "SELECT #{keys} FROM #{query[:tables].join(',')} WHERE #{pk_sql} IN (#{distinct_sql}) order by #{order}"
282
+ data_sql = "SELECT #{keys} FROM #{tables_sql} WHERE #{pk_sql} IN (#{distinct_sql}) order by #{order}"
280
283
  else
281
284
  data_sql = "#{sql} order by #{order}"
282
285
  end
@@ -172,6 +172,10 @@ module Spider; module Model; module Storage; module Db
172
172
  @name
173
173
  end
174
174
 
175
+ def inspect
176
+ "#<#{self.class.name}:#{self.object_id} @name=\"#{@name}\ >"
177
+ end
178
+
175
179
  end
176
180
 
177
181
  class Field
@@ -203,7 +207,7 @@ module Spider; module Model; module Storage; module Db
203
207
  end
204
208
 
205
209
  def inspect
206
- "#<#{self.class.name}:#{self.object_id} @name=\"#{@name}\", @table=#<Spider::Model::Storage::Db::Table:0x6d3ff94 #{@table.name}> >"
210
+ "#<#{self.class.name}:#{self.object_id} @name=\"#{@name}\", @table=#<Spider::Model::Storage::Db::Table:#{@table.object_id} #{@table.name}> >"
207
211
  end
208
212
 
209
213
  end
@@ -44,6 +44,9 @@ module Spider
44
44
  def send_to_loggers(action, *args)
45
45
  return if $SAFE > 1
46
46
  return unless @loggers
47
+ if args[0].is_a?(String)
48
+ args[0] = "T#{Thread.current.object_id} #{args[0]}"
49
+ end
47
50
  @loggers.each do |dest, logger|
48
51
  begin
49
52
  logger.send(action, *args)
data/lib/spiderfw.rb CHANGED
@@ -368,7 +368,6 @@ module Spider
368
368
  return Resource.new(first_found(extensions, File.dirname(cur_path)+path[2..-1]), owner_class)
369
369
  end
370
370
  end
371
- app = nil
372
371
  if (path[0].chr == '/')
373
372
  Spider.apps_by_path.each do |p, a|
374
373
  if (path.index(p) == 1)
data/spider.gemspec CHANGED
@@ -2,8 +2,8 @@ require 'rake'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "spiderfw"
5
- s.version = "0.5.5"
6
- s.date = "2010-02-18"
5
+ s.version = "0.5.6"
6
+ s.date = "2010-02-26"
7
7
  s.summary = "A (web) framework"
8
8
  s.email = "abmajor7@gmail.com"
9
9
  s.homepage = "http://github.com/me/spider"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiderfw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Pirlik
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-18 00:00:00 +01:00
12
+ date: 2010-02-26 00:00:00 +01:00
13
13
  default_executable: spider
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency