Sha256: 234ded1455b3ba3ec711386cc494ebf86e1eb0967b5839ab829f47f50c8969f2

Contents?: true

Size: 666 Bytes

Versions: 1

Compression:

Stored size: 666 Bytes

Contents

require 'fileutils'

module UniverseCompiler
  module Entity

    module Persistence

      attr_accessor :source_uri

      def self.load(uri)
        entity = YAML.load_file uri
        entity.source_uri = uri
        entity
      end

      def save(uri = source_uri, save_options = { raise_error: true })
        valid? raise_error: save_options[:raise_error]
        FileUtils.mkpath File.dirname(uri)
        File.write uri, to_yaml, mode: 'w'
        self.source_uri = uri
        self
      end

      def delete
        universe.delete self
        unless self.source_uri.nil?
          FileUtils.rm self.source_uri
        end
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
universe_compiler-0.3.7 lib/universe_compiler/entity/persistence.rb