Sha256: a73bb003d7e2b89530008f7f3da2ba9fa04746910a7ee6c9426abd7a3b4bbe38

Contents?: true

Size: 1.07 KB

Versions: 31

Compression:

Stored size: 1.07 KB

Contents

require 'yaml'

module Capricorn
  class Satellite
    module Persistence
      
      def self.included(base)
        base.extend Capricorn::Satellite::Persistence::ClassMethods
      end
      
      module ClassMethods
        
        def load(data)
          Capricorn::Satellite.new(YAML.load(data))
        end
        
        def load_file(path)
          return nil unless File.exist?(path)
          Capricorn::Satellite.new(YAML.load_file(path))
        end
        
      end
      
      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
      
      def dump_file(path)
        File.open(path, 'w+') { |f| dump(f) }
      end
      
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
simonmenke-capricorn-0.2.00 lib/capricorn/satellite/persistence.rb
simonmenke-capricorn-0.2.03 lib/capricorn/satellite/persistence.rb
simonmenke-capricorn-0.2.07 lib/capricorn/satellite/persistence.rb
simonmenke-capricorn-0.2.25 lib/capricorn/satellite/persistence.rb
simonmenke-capricorn-0.2.26 lib/capricorn/satellite/persistence.rb
capricorn-0.2.25 lib/capricorn/satellite/persistence.rb
capricorn-0.2.24 lib/capricorn/satellite/persistence.rb
capricorn-0.2.23 lib/capricorn/satellite/persistence.rb
capricorn-0.2.22 lib/capricorn/satellite/persistence.rb
capricorn-0.2.21 lib/capricorn/satellite/persistence.rb
capricorn-0.2.20 lib/capricorn/satellite/persistence.rb
capricorn-0.2.19 lib/capricorn/satellite/persistence.rb
capricorn-0.2.18 lib/capricorn/satellite/persistence.rb
capricorn-0.2.17 lib/capricorn/satellite/persistence.rb
capricorn-0.2.16 lib/capricorn/satellite/persistence.rb
capricorn-0.2.15 lib/capricorn/satellite/persistence.rb
capricorn-0.2.14 lib/capricorn/satellite/persistence.rb
capricorn-0.2.13 lib/capricorn/satellite/persistence.rb
capricorn-0.2.12 lib/capricorn/satellite/persistence.rb
capricorn-0.2.11 lib/capricorn/satellite/persistence.rb