module TG
require 'time'
Public Class Methods
check_and_initialize(database_instance)
click to toggle source
# File lib/orientdb_time_graph.rb, line 43 def self.check_and_initialize database_instance if database_instance.get_classes( "name").values.flatten.include? 'time_base' return true else TG::Setup.init_database database_instance puts "Database-Structure allocated" puts "Exiting now, please restart and call »TG::TimeGraph.populate«" Kernel.exit end end
connect(**login) { |].flatten : [ "#{project_root}/model" ]| ... }
click to toggle source
# File lib/orientdb_time_graph.rb, line 30 def self.connect **login project_root = File.expand_path('../..', __FILE__) set_defaults( **login) unless ActiveOrient.default_server.is_a?(Hash) && ActiveOrient.default_server[:user].present? ActiveOrient::Init.define_namespace { TG } # a provided block is used to introduce additional locations of model-files the_model_dirs = block_given? ? [ "#{project_root}/model", yield].flatten : [ "#{project_root}/model" ] ActiveOrient::OrientDB.new preallocate: true, model_dir: the_model_dirs @time_graph = TG.const_defined?(:TIME_OF) ? TG::TIME_OF.count > 0 : nil end
info()
click to toggle source
# File lib/orientdb_time_graph.rb, line 54 def self.info puts "-------------- TIME GRAPH ------------------" puts "Allocated Years : " puts TG::Jahr.all.map(&:value).sort.join('; ') puts "" puts "Type: #{TG::Stunde.all.empty? ? "Date-Graph" : "DateTime-Graph"}" puts "" end
set_defaults(**login)
click to toggle source
completes the parameter for calling ActiveOrient::Init.connect
Is called from connect only if ActiveOrient.default_server is not set previously
otherwise the credentials from the main-activeorient-instance are used.
# File lib/orientdb_time_graph.rb, line 16 def self.set_defaults **login c = { :server => 'localhost', :port => 2480, :protocol => 'http', :user => 'root', :password => 'root', :database => 'temp' }.merge login ActiveOrient.default_server= { user: c[:user], password: c[:password] , server: c[:server], port: c[:port] } ActiveOrient.database = c[:database] end
setup(environment = :test)
click to toggle source
Standalone setup initializes ActiveOrient and adds time-graph database-classes through namespace
valid environments: :test, :development, :production
# File lib/setup.rb, line 19 def self.setup environment = :test read_yml = -> (key) do YAML::load_file( File.expand_path('../../config/connect.yml',__FILE__))[key] end logon = read_yml[:orientdb][environment] ActiveOrient::Init.connect **logon TG.connect **logon # we have to initialise the timegraph at this point, otherwise any # manual requirement fails. unless ActiveOrient::Model.namespace.send :const_defined?, 'Tag' Setup.init_database V.orientdb end end
time_graph?()
click to toggle source
# File lib/orientdb_time_graph.rb, line 40 def self.time_graph? @time_graph end