Sha256: 93de24f15550f286295356f3f87e3fb6d75f689d0294ff48448d5cf39204f5d2

Contents?: true

Size: 632 Bytes

Versions: 13

Compression:

Stored size: 632 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, raise_error: true)
        valid? raise_error: 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

13 entries across 13 versions & 1 rubygems

Version Path
universe_compiler-0.3.6 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.3.5 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.3.4 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.3.3 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.3.2 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.3.1 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.3.0 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.2.16 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.2.15 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.2.14 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.2.13 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.2.12 lib/universe_compiler/entity/persistence.rb
universe_compiler-0.2.11 lib/universe_compiler/entity/persistence.rb