Class: Firefly::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/tmin/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, &blk) ⇒ Server

Returns a new instance of Server.



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/tmin/server.rb', line 349

def initialize config = {}, &blk
  super
  @config = config.is_a?(Config) ? config : Firefly::Config.new(config)
  @config.instance_eval(&blk) if block_given?

  begin
    DataMapper.setup(:default, @config[:database])
    DataMapper.auto_upgrade!
    check_mysql_collation
    check_code_factory
  rescue
    puts "Error setting up database connection. Please check the `database` setting in config.ru"
    puts $!
    puts "-------"
    puts $!.backtrace
    exit(1)
  end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



28
29
30
# File 'lib/tmin/server.rb', line 28

def config
  @config
end

Instance Method Details

#alert_on(alert) ⇒ Object



435
436
437
438
439
440
441
442
443
# File 'lib/tmin/server.rb', line 435

def alert_on(alert)

 if alert == 0
   return 'Yes'
 else
   return 'No'
 end

end

#array_builder(string) ⇒ Object



397
398
399
400
401
# File 'lib/tmin/server.rb', line 397

def array_builder(string)
  ary = []
  ary = string.split(/;/)
  return ary
end

#check_code_factoryObject



368
369
370
# File 'lib/tmin/server.rb', line 368

def check_code_factory
  Firefly::CodeFactory.first || Firefly::CodeFactory.create(:count => 0)
end

#check_mysql_collation(first_try = true) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/tmin/server.rb', line 372

def check_mysql_collation(first_try = true)
  # Make sure the 'code' column is case-sensitive. This hack is for
  # MySQL only, other database systems don't have this problem.
  if DataMapper.repository(:default).adapter =~ "DataMapper::Adapters::MysqlAdapter"
    query     = "SHOW FULL COLUMNS FROM firefly_urls WHERE Field='code';"
    collation = DataMapper.repository(:default).adapter.select(query)[0][:collation]

    if collation != "utf8_bin"
      if first_try
        puts " ~ Your MySQL database is not using the 'utf8-bin' collation. Trying to fix..."
        DataMapper.repository(:default).adapter.execute("ALTER TABLE firefly_urls MODIFY `code` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
        return check_mysql_collation(false)
      else
        puts " ~ Failed to set the collation for `code` in `firefly_urls`. Please see http://wiki.github.com/ariejan/firefly/faq for details."
        return false
      end
    else
      if !first_try
        puts " ~ Successfully fixed your database."
      end
      return true
    end
  end
end

#font_builder(color) ⇒ Object



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/tmin/server.rb', line 403

def font_builder(color)
   if color == 0
    return 'black'
   elsif color == 1
    return 'dark_gray'
   elsif color == 2
    return 'light_gray'
   elsif color == 3
    return 'white'
   elsif color == 4
    return 'gray'
   elsif color == 5
    return 'red'
   elsif color == 6
    return 'green'
   elsif color == 7
    return 'blue'
   elsif color == 8
    return 'cyan'
   elsif color == 9
    return 'yellow'
   elsif color == 10
    return 'magenta'
   elsif color == 11
    return 'orange'
   elsif color == 12
    return 'purple'
   elsif color == 13
    return 'brown'
  end
end