Class: Sekt::Bottle

Inherits:
Object
  • Object
show all
Defined in:
lib/sekt/bottle.rb

Constant Summary collapse

WINE_PREFIX_NAME =
'windows'.freeze
REQUIRED_ATTRIBUTES =
%w{id name source}.freeze
OPTIONAL_ATTRIBUTES =
%w{architecture description dependencies executable}.freeze
ATTRIBUTES =
REQUIRED_ATTRIBUTES + OPTIONAL_ATTRIBUTES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Bottle

Returns a new instance of Bottle.



20
21
22
23
24
25
26
27
# File 'lib/sekt/bottle.rb', line 20

def initialize(hash)
  check_args!(hash)

  ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", hash[attr]) }

  @path = File.join(Cellar::CELLAR_PATH, @id)
  @wine_prefix = File.join(@path, WINE_PREFIX_NAME)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/sekt/bottle.rb', line 13

def path
  @path
end

#wine_prefixObject (readonly)

Returns the value of attribute wine_prefix.



13
14
15
# File 'lib/sekt/bottle.rb', line 13

def wine_prefix
  @wine_prefix
end

Class Method Details

.load(id, hash) ⇒ Object



29
30
31
32
# File 'lib/sekt/bottle.rb', line 29

def self.load(id, hash)
  hash['id'] = id
  Bottle.new(hash)
end

Instance Method Details

#check_args!(hash) ⇒ Object



15
16
17
18
# File 'lib/sekt/bottle.rb', line 15

def check_args!(hash)
  diff = REQUIRED_ATTRIBUTES - hash.keys
  raise "Some required bottle attributes are missing: #{diff}" unless diff.empty?
end

#inside(&block) ⇒ Object



42
43
44
# File 'lib/sekt/bottle.rb', line 42

def inside(&block)
  Dir.chdir(path, &block)
end

#inside_wine(&block) ⇒ Object



46
47
48
# File 'lib/sekt/bottle.rb', line 46

def inside_wine(&block)
  Dir.chdir(File.join(wine_prefix, 'drive_c'), &block)
end

#install_libs(libs) ⇒ Object



54
55
56
57
# File 'lib/sekt/bottle.rb', line 54

def install_libs(libs)
  wine_tricks.install(libs)
  @dependencies + libs
end

#ppObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sekt/bottle.rb', line 63

def pp
  %(
    Bottle___________________________________________________
    |NAME: #{name}
    |ID: #{id}
    |PATH: #{path}
    |WINE_PREFIX: #{wine_prefix}
    |________________________________________________________

      Description:
        #{description}
      Source: #{source}
      Executable: #{executable}
      Architecture: #{architecture}
  )
end

#startObject



50
51
52
# File 'lib/sekt/bottle.rb', line 50

def start
  wine.execute(executable)
end

#to_hObject



59
60
61
# File 'lib/sekt/bottle.rb', line 59

def to_h
  ATTRIBUTES.each_with_object({}) { |attr, hash| hash[attr] = instance_variable_get("@#{attr}") }
end

#wineObject



34
35
36
# File 'lib/sekt/bottle.rb', line 34

def wine
  Wine.new(wine_prefix, architecture)
end

#wine_tricksObject



38
39
40
# File 'lib/sekt/bottle.rb', line 38

def wine_tricks
  WineTricks.new(wine_prefix, architecture)
end