Sha256: b64b152d4baad0af5c694ef51297155352b51fb14753b121f87fbccc95000c62

Contents?: true

Size: 781 Bytes

Versions: 13

Compression:

Stored size: 781 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

    def clouds
      @content.keys.sort if @content
    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

13 entries across 13 versions & 1 rubygems

Version Path
shelly-0.1.6 lib/shelly/cloudfile.rb
shelly-0.1.5 lib/shelly/cloudfile.rb
shelly-0.1.4.pre2 lib/shelly/cloudfile.rb
shelly-0.1.4.pre lib/shelly/cloudfile.rb
shelly-0.1.3 lib/shelly/cloudfile.rb
shelly-0.1.2 lib/shelly/cloudfile.rb
shelly-0.1.1 lib/shelly/cloudfile.rb
shelly-0.1.0 lib/shelly/cloudfile.rb
shelly-0.0.62 lib/shelly/cloudfile.rb
shelly-0.0.61 lib/shelly/cloudfile.rb
shelly-0.0.60 lib/shelly/cloudfile.rb
shelly-0.0.59 lib/shelly/cloudfile.rb
shelly-0.0.58 lib/shelly/cloudfile.rb