Class: Mystro::Organization

Inherits:
Object
  • Object
show all
Defined in:
lib/mystro/organization.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, file) ⇒ Organization

Returns a new instance of Organization.



45
46
47
48
49
50
51
52
# File 'lib/mystro/organization.rb', line 45

def initialize(name, file)
  cfg = Mystro.config.to_hash
  organization = File.exists?(file) ? YAML.load_file(file) : {}
  @name = name
  @file = file
  @data = Hashie::Mash.new(cfg.deep_merge(organization))
  @data.name = name
end

Class Attribute Details

.selectedObject (readonly)

Returns the value of attribute selected.



6
7
8
# File 'lib/mystro/organization.rb', line 6

def selected
  @selected
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



41
42
43
# File 'lib/mystro/organization.rb', line 41

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



42
43
44
# File 'lib/mystro/organization.rb', line 42

def file
  @file
end

#nameObject (readonly)

Returns the value of attribute name.



43
44
45
# File 'lib/mystro/organization.rb', line 43

def name
  @name
end

Class Method Details

.[](name) ⇒ Object



8
9
10
# File 'lib/mystro/organization.rb', line 8

def [](name)
  get(name)
end

.defaultObject



29
30
31
32
33
34
# File 'lib/mystro/organization.rb', line 29

def default
  return ENV['MYSTRO_ORGANIZATION'] if ENV['MYSTRO_ORGANIZATION']
  return Mystro.config.default_organization if Mystro.config.default_organization?
  return "default" if @list.keys.include?("default")
  @list.keys.first
end

.get(name) ⇒ Object



12
13
14
# File 'lib/mystro/organization.rb', line 12

def get(name)
  @list[name]
end

.readObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mystro/organization.rb', line 16

def read
  dir = Mystro.directory
  @list = {}

  Dir["#{dir}/organizations/*.y*ml"].each do |file|
    name = file.gsub(/#{dir}\/organizations\//, "").gsub(/\.(\w+?)$/, "")
    Mystro::Log.debug "loading organization '#{name}' '#{file}'"
    @list[name] = self.new(name, file)
  end

  @selected = default
end

.select(name) ⇒ Object



36
37
38
# File 'lib/mystro/organization.rb', line 36

def select(name)
  @selected = name
end

Instance Method Details

#balancerObject



62
63
64
# File 'lib/mystro/organization.rb', line 62

def balancer
  @balancer ||= connect(:balancer)
end

#computeObject



58
59
60
# File 'lib/mystro/organization.rb', line 58

def compute
  @compute ||= connect(:compute)
end

#recordObject



66
67
68
# File 'lib/mystro/organization.rb', line 66

def record
  @dns ||= connect(:record)
end

#to_hashObject



54
55
56
# File 'lib/mystro/organization.rb', line 54

def to_hash
  @data.to_hash
end