Module: Capricorn::Satellite::Persistence

Included in:
Capricorn::Satellite
Defined in:
lib/capricorn/satellite/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/capricorn/satellite/persistence.rb', line 7

def self.included(base)
  base.extend Capricorn::Satellite::Persistence::ClassMethods
end

Instance Method Details

#dump(io = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/capricorn/satellite/persistence.rb', line 24

def dump(io=nil)
  data = {}
  
  private_vars = %w( basedomain subdomain )
  instance_variables.each do |ivar_name|
    ivar_name = ivar_name.to_s
    ivar_name =~ /^@(.+)$/
    name = $1
    unless private_vars.include? name
      data[name] = instance_variable_get(ivar_name.to_sym)
    end
  end
  
  if io
    io.write YAML.dump(data)
  else
    YAML.dump(data)
  end
end

#dump_file(path) ⇒ Object



44
45
46
# File 'lib/capricorn/satellite/persistence.rb', line 44

def dump_file(path)
  File.open(path, 'w+') { |f| dump(f) }
end