Class: Firefly::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Firefly::Server
- Defined in:
- lib/tmin/server.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #check_code_factory ⇒ Object
- #check_mysql_collation(first_try = true) ⇒ Object
-
#initialize(config = {}, &blk) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(config = {}, &blk) ⇒ Server
Returns a new instance of Server.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/tmin/server.rb', line 320 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
#config ⇒ Object
Returns the value of attribute config.
28 29 30 |
# File 'lib/tmin/server.rb', line 28 def config @config end |
Instance Method Details
#check_code_factory ⇒ Object
339 340 341 |
# File 'lib/tmin/server.rb', line 339 def check_code_factory Firefly::CodeFactory.first || Firefly::CodeFactory.create(:count => 0) end |
#check_mysql_collation(first_try = true) ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/tmin/server.rb', line 343 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 |