Sha256: 8e01ce32474ef8b5e9014ad01f08e928052e5072a8bb6fb37cd605de562f0a21

Contents?: true

Size: 818 Bytes

Versions: 41

Compression:

Stored size: 818 Bytes

Contents

require "yaml"

module Shelly
  class Cloudfile < Model
    attr_accessor :content

    def self.present?
      File.exists?(File.join(Dir.pwd, "Cloudfile"))
    end

    def initialize
      open if File.exists?(path)
    end

    def path
      File.join(Dir.pwd, "Cloudfile")
    end

    def open
      @content = YAML.load(File.open(path))
    end

    def write(hash)
      @content = hash
      File.open(path, "w") do |f|
        f.write(yaml(hash))
      end
    end

    # FIXME: this should return instances of App
    def clouds
      @content.keys.sort
    end

    def yaml(hash)
      string = hash.deep_stringify_keys.to_yaml
      # FIXME: check if it possible to remove sub("---", "") by passing options to_yaml
      string.sub("---","").split("\n").map(&:rstrip).join("\n").strip
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
shelly-0.0.57 lib/shelly/cloudfile.rb
shelly-0.0.56 lib/shelly/cloudfile.rb
shelly-0.0.55 lib/shelly/cloudfile.rb
shelly-0.0.55.pre lib/shelly/cloudfile.rb
shelly-0.0.54 lib/shelly/cloudfile.rb
shelly-0.0.53 lib/shelly/cloudfile.rb
shelly-0.0.52 lib/shelly/cloudfile.rb
shelly-0.0.51.pre lib/shelly/cloudfile.rb
shelly-0.0.51 lib/shelly/cloudfile.rb
shelly-0.0.50.pre2 lib/shelly/cloudfile.rb
shelly-0.0.50.pre lib/shelly/cloudfile.rb
shelly-0.0.50 lib/shelly/cloudfile.rb
shelly-0.0.49.pre lib/shelly/cloudfile.rb
shelly-0.0.49 lib/shelly/cloudfile.rb
shelly-0.0.48 lib/shelly/cloudfile.rb
shelly-0.0.48.pre4 lib/shelly/cloudfile.rb
shelly-0.0.48.pre3 lib/shelly/cloudfile.rb
shelly-0.0.48.pre2 lib/shelly/cloudfile.rb
shelly-0.0.48.pre lib/shelly/cloudfile.rb
shelly-0.0.47 lib/shelly/cloudfile.rb