Module: Diametric::ServiceBase::ClassMethods

Defined in:
lib/diametric/service_base.rb

Instance Method Summary collapse

Instance Method Details

#datomic_classpath(datomic_home) ⇒ Object


65
66
67
68
69
70
71
72
73
74
# File 'lib/diametric/service_base.rb', line 65

def datomic_classpath(datomic_home)
  # Find jar archives
  jars = Dir["#{datomic_home}/lib/*.jar"]
  jars += Dir["#{datomic_home}/*transactor*.jar"]

  # Setup CLASSPATH
  classpath = jars.join(File::PATH_SEPARATOR)
  files = ["samples/clj", "bin", "resources"]
  classpath += File::PATH_SEPARATOR + files.collect {|f| datomic_home + "/" + f}.join(File::PATH_SEPARATOR)
end

#datomic_conf_file?(file = "datomic_version.yml") ⇒ Boolean


12
13
14
15
16
17
# File 'lib/diametric/service_base.rb', line 12

def datomic_conf_file?(file="datomic_version.yml")
  if Pathname.new(file).relative?
    file = File.join(File.dirname(__FILE__), "../..", file)
  end
  return File.exists?(file)
end

#datomic_version(conf = "datomic_version.yml") ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/diametric/service_base.rb', line 19

def datomic_version(conf="datomic_version.yml")
  if datomic_conf_file?(conf)
    datomic_names = File.read(File.join(File.dirname(__FILE__), "../..", conf))
    datomic_versions = YAML.load(datomic_names)
    if ENV['DIAMETRIC_ENV'] && (ENV['DIAMETRIC_ENV'] == "pro")
      return "pro", datomic_versions["pro"]
    else
      return "free", datomic_versions["free"]
    end
  else
    return "free", conf
  end
end

#datomic_version_no(datomic_version_str) ⇒ Object


33
34
35
# File 'lib/diametric/service_base.rb', line 33

def datomic_version_no(datomic_version_str)
  /(\d|\.)+/.match(datomic_version_str)[0]
end

#download(conf = "datomic_version.yml", dest = "vendor/datomic") ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/diametric/service_base.rb', line 45

def download(conf="datomic_version.yml", dest="vendor/datomic")
  return true if downloaded?(conf, dest)
  type, version = datomic_version(conf)
  url = "https://my.datomic.com/downloads/#{type}/#{version}"
  if Pathname.new(dest).relative?
    dest = File.join(File.dirname(__FILE__), "../..", dest)
  end
  require 'open-uri'
  require 'zip/zipfilesystem'
  open(url) do |zip_file|
    Zip::ZipFile.open(zip_file.path) do |zip_path|
      zip_path.each do |zip_entry|
        file_path = File.join(dest, zip_entry.to_s)
        FileUtils.mkdir_p(File.dirname(file_path))
        zip_path.extract(zip_entry, file_path) { true }
      end
    end
  end
end

#downloaded?(conf = "datomic_version.yml", dest = "vendor/datomic") ⇒ Boolean


37
38
39
40
41
42
43
# File 'lib/diametric/service_base.rb', line 37

def downloaded?(conf="datomic_version.yml", dest="vendor/datomic")
  datomic_type, datomic_version = datomic_version(conf)
  if Pathname.new(dest).relative?
    dest = File.join(File.dirname(__FILE__), "..", "..", dest)
  end
  File.exists?(File.join(dest, "datomic-#{datomic_type}-#{datomic_version}"))
end