Class: Wooget::Unity

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/wooget/template/unity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/wooget/template/unity.rb', line 3

def options
  @options
end

Class Method Details

.source_rootObject



8
9
10
# File 'lib/wooget/template/unity.rb', line 8

def self.source_root
  File.join(File.dirname(__FILE__), "files")
end

Instance Method Details

#bootstrapObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wooget/template/unity.rb', line 14

def bootstrap

  dependencies_path = File.join(options[:path], "paket.dependencies")
  if File.exists?(dependencies_path)
    set_wooga_sources dependencies_path
  else
    template("unity_paket.dependencies.erb", File.join(options[:path], "paket.dependencies"))
  end

  required_files = %w(paket.lock paket.unity3d.references).select { |f| not File.exists?(File.join(options[:path], f)) }
  required_files.each { |f| create_file File.join(options[:path], f) }
end

#generate_referencesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/wooget/template/unity.rb', line 45

def generate_references
  unless Paket.should_generate_unity3d_references? options[:path]
    Wooget.log.debug "automanage tag not found - skipping `paket.unity3d.references` generation"
    return
  end

  to_install = File.open(File.join(options[:path], "paket.dependencies")).readlines.select { |l| l =~ /^\s*nuget \w+/ }
  to_install.map! { |d| d.match(/nuget (\S+)/)[1] }

  File.open(File.join(options[:path], "paket.unity3d.references"), "w") do |f|
    to_install.each { |dep| f.puts(dep) }
  end
end

#install(package) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/wooget/template/unity.rb', line 32

def install package
  unless Util.file_contains? File.join(options[:path], "paket.dependencies"), "nuget #{package}"

    package.split(",").each do |pkg|
      append_to_file File.join(options[:path], "paket.dependencies"), "\nnuget #{pkg}"
    end
  end

  generate_references
end