Class: Veewee::Provider::Core::Provider

Inherits:
Object
  • Object
show all
Includes:
Helper::Shell
Defined in:
lib/veewee/provider/core/provider.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper::Shell

#shell_exec

Constructor Details

#initialize(name, options, env) ⇒ Provider

Returns a new instance of Provider.



22
23
24
25
26
27
28
29
# File 'lib/veewee/provider/core/provider.rb', line 22

def initialize(name,options,env)

  @env=env
  @name=name
  @options=options
  @type=self.class.to_s.split("::")[-2]
  check_requirements
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



7
8
9
# File 'lib/veewee/provider/core/provider.rb', line 7

def env
  @env
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/veewee/provider/core/provider.rb', line 11

def name
  @name
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/veewee/provider/core/provider.rb', line 8

def options
  @options
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/veewee/provider/core/provider.rb', line 10

def type
  @type
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/veewee/provider/core/provider.rb', line 49

def self.available?
  begin
    self.check_requirements
    return true
  rescue Error
    return false
  end
end

Instance Method Details

#gem_available?(gemname) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/veewee/provider/core/provider.rb', line 58

def gem_available?(gemname)
  env.logger.info "Checking for gem #{gemname}"
  available=false
  begin
    available=true unless Gem::Specification::find_by_name("#{gemname}").nil?
  rescue Gem::LoadError
    env.logger.info "Error loading gem #{gemname}"
    available=false
  rescue
    env.logger.info "Falling back to old syntax for #{gemname}"
    available=Gem.available?("#{gemname}")
    env.logger.info "Old syntax #{gemname}.available? #{available}"
  end
  return available
end

#gems_available?(names) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/veewee/provider/core/provider.rb', line 74

def gems_available?(names)
  names.each do |gemname|
    return false if !gem_available?(gemname)
  end
  return true
end

#get_box(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/veewee/provider/core/provider.rb', line 31

def get_box(name)
  begin
    require_path='veewee/provider/'+type.to_s.downcase+"/box.rb"
    require require_path

    # Get a real box object from the Provider
    box=Object.const_get("Veewee").const_get("Provider").const_get(type.to_s.capitalize).const_get("Box").new(name,env)

    # Attach the provider to the box
    box.provider = self

    return box
  rescue Error => ex
    ui.error "Could not instante the box #{name} with provider #{type} ,#{ex}"
    raise
  end
end

#uiObject



15
16
17
18
19
20
# File 'lib/veewee/provider/core/provider.rb', line 15

def ui
  return @_ui if defined?(@_ui)
  @_ui = @env.ui.dup
  @_ui.resource = @name
  @_ui
end