Class: Freyr::ServiceInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/freyr/service_info.rb

Constant Summary collapse

ATTRS =
[]
MODIFIERS =
Hash.new {|h,k| h[k] = []}
SUDO_MATCHER =
/^sudo\s+/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, args = {}, &block) ⇒ ServiceInfo

Returns a new instance of ServiceInfo.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/freyr/service_info.rb', line 20

def initialize(name=nil, args={}, &block)
  @groups = []
  @also = []
  @dependencies = []
  if name.is_a?(Hash)
    @name = name.keys.first
    @groups << name[@name]
  else
    @name = name
  end
  
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, val = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/freyr/service_info.rb', line 55

def method_missing key, val=nil
  key = key.to_s.gsub(/\=$/,'').to_sym
  
  if val
    MODIFIERS[key].each do |modifier|
      val = send(modifier,val)
    end
    instance_variable_set("@#{key}", val)
  else
    instance_variable_get("@#{key}")
  end
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



3
4
5
# File 'lib/freyr/service_info.rb', line 3

def groups
  @groups
end

Class Method Details

.add_service_method(*methods) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/freyr/service_info.rb', line 6

def add_service_method *methods
  Service.send :add_service_method, *methods
  Command.send :add_service_method, *methods
  methods.each do |method|
    ATTRS << methods
  end
end

.from_file(file) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/freyr/service_info.rb', line 85

def from_file file
  @file_path = file
  file = File.expand_path(file)
  return [] unless File.exist?(file)
  @added_services = []
  instance_eval(File.open(file).read)
  @added_services
end

.method_missing(name, *args) ⇒ Object



94
95
96
# File 'lib/freyr/service_info.rb', line 94

def method_missing name, *args
  STDERR.puts "Freyr doesn't support #{name} as used in #{@file_path}"
end

Instance Method Details

#also_as(*val) ⇒ Object



46
47
48
# File 'lib/freyr/service_info.rb', line 46

def also_as(*val)
  @also |= val
end

#group(*val) ⇒ Object



38
39
40
# File 'lib/freyr/service_info.rb', line 38

def group(*val)
  @groups |= val
end

#requires(*val) ⇒ Object



42
43
44
# File 'lib/freyr/service_info.rb', line 42

def requires *val
  @dependencies |= val
end

#use_sudoObject



34
35
36
# File 'lib/freyr/service_info.rb', line 34

def use_sudo
  @sudo = true
end