Class: Firefly::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Firefly::Server
- Defined in:
- lib/firefly/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.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/firefly/server.rb', line 285 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/firefly/server.rb', line 28 def config @config end |
Instance Method Details
#check_code_factory ⇒ Object
304 305 306 |
# File 'lib/firefly/server.rb', line 304 def check_code_factory Firefly::CodeFactory.first || Firefly::CodeFactory.create(:count => 0) end |
#check_mysql_collation(first_try = true) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/firefly/server.rb', line 308 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 |