Class: Orkester::PackageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/orkester/package_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ PackageHandler

Returns a new instance of PackageHandler.



7
8
9
10
11
12
13
# File 'lib/orkester/package_handler.rb', line 7

def initialize(args)
  @context = args[:context]
  @package = args[:package]
  @install_location = @package["location"] || @package["name"]
  @package_path = @context.root.join(@install_location) 
  self.load_defination
end

Instance Method Details

#compileObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/orkester/package_handler.rb', line 28

def compile
  self.dependencies.to_a.each do |dependency|
    match = @context.included_packages.find { |x| x == dependency["name"] }
    if match
    else
      dependency_handler = PackageHandler.new context: @context, package: dependency
      dependency_handler.compile
    end
  end

  compiler = Compiler.new context: @context, package_defination: @package_defination
  compiler.compile 
end

#dependenciesObject



24
25
26
# File 'lib/orkester/package_handler.rb', line 24

def dependencies
  @package_defination["dependencies"]
end

#include_from_remote(dependency) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/orkester/package_handler.rb', line 43

def include_from_remote(dependency)
  p dependency
  uri = URI(dependency["remote"])
  FileUtils.mkdir_p @package_path.join("javascripts")
  str = Net::HTTP.get(uri)

  File.write @package_path.join( "javascripts", "main.js"), str
  File.write @package_path.join("package.yaml"), dependency.to_yaml
end

#load_definationObject



15
16
17
18
19
20
21
22
# File 'lib/orkester/package_handler.rb', line 15

def load_defination
  if @package_path.exist?
  else
    self.include_from_remote @package
  end
  package_yaml = File.read @package_path.join("package.yaml")
  @package_defination = YAML.load package_yaml
end