class FiveApples::Server
Constants
- CONFIGDIRNAME
- CONFIGRU
- DBFILENAME
- MEDIADIR
Attributes
db[R]
host[R]
log[RW]
media_root[R]
one_way[R]
port[R]
resources[R]
role[R]
ui5d[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/fiveapples.rb, line 30 def initialize(options={}) options ||= {} @role = options[:role] # from libdir we readonly. --> can be a system (install) dir @libdir = __dir__.dup # apphome needs to be user-writeable ! @apphome = if ( @role == :test ) File.expand_path('testdb', @libdir) else gconfigdir = File.expand_path('.config', Dir.home) File.expand_path(CONFIGDIRNAME, gconfigdir) end $LOAD_PATH.unshift(@libdir) unless $LOAD_PATH.include?(@libdir) @systemdbname = File.join(@libdir, DBFILENAME) @homedbname = File.expand_path(DBFILENAME, @apphome) @media_root = File.expand_path(MEDIADIR, @apphome) @configru = File.expand_path(CONFIGRU, @libdir) @one_way = options[:one_way] @use_cdn = options[:use_cdn] # in testmode we dont log per default, # in non testmode we log per default, # but this can be overriden with option @log = ( options[:log] || ( @role != :test ) ) @resources = @use_cdn ? "https://openui5.hana.ondemand.com/#{OpenUI5::VERSION}/resources/sap-ui-core.js" : '../resources/sap-ui-core.js' @ui5d = @one_way ? 'ui5_1way' : 'ui5' @port = 9494 @host = if ( ( @role == :test ) && ENV['selenium_remote_url'] ) FiveApples.test_host_ip() else 'localhost' end end
Public Instance Methods
db_breeder_table_photo_id()
click to toggle source
# File lib/fiveapples.rb, line 92 def db_breeder_table_photo_id return if @db.schema(:breeder).find{|col| col[0] == :photo_id } @db.alter_table :breeder do add_column :photo_id, Integer add_foreign_key [:photo_id], :photo, key: :id, name: :breeder_photo_id_fkey end end
db_create_photo_table()
click to toggle source
# File lib/fiveapples.rb, line 83 def db_create_photo_table @db.create_table :photo do primary_key :id column :name, :text Integer :cultivar_id column :content_type, :text end end
get_binding()
click to toggle source
needed for ERB
# File lib/fiveapples.rb, line 119 def get_binding binding end
serve()
click to toggle source
# File lib/fiveapples.rb, line 123 def serve puts "Fiveapples version #{FiveApples::VERSION} on #{@host} config #{@configru}" begin # this requires safrano ~> 0.3.5 puts "Safrano version #{Safrano::VERSION}" rescue end Dir.chdir @libdir do # this is equivalent to 'rackup config.ru' but in same process ARGV.clear ARGV << @configru Rack::Server.start end end
setup_db_in_homedir()
click to toggle source
# File lib/fiveapples.rb, line 69 def setup_db_in_homedir FileUtils.mkdir_p(@apphome) unless Dir.exist?(@apphome) if ( @role == :test ) # in test-mode always start with a fresh DB copy FileUtils.cp(@systemdbname, @homedbname) # and reset the media directory media_photo_dir = File.absolute_path('Photo', @media_root) FileUtils.remove_entry_secure(media_photo_dir) if File.exists?(media_photo_dir) else FileUtils.cp(@systemdbname, @homedbname) unless File.exist?(@homedbname) end end
startdb()
click to toggle source
# File lib/fiveapples.rb, line 103 def startdb setup_db_in_homedir @db = Sequel::Model.db = Sequel.sqlite(@homedbname) # data model for media entities table and relations unless @db.table_exists? :photo db_create_photo_table end db_breeder_table_photo_id Kernel.at_exit { Sequel::Model.db.disconnect if Sequel::Model.db } end