Sha256: 8199fec74a559d3122eca2684b7a1b0d587d7d3c27f2878a1cc7b246ee993233

Contents?: true

Size: 1.61 KB

Versions: 17

Compression:

Stored size: 1.61 KB

Contents

require "yaml"

module Shelly
  class Cloudfile < Model
    attr_accessor :content
    # Cloudfile attributes used for generating Cloudfile from a template
    attr_accessor :code_name, :ruby_version, :environment, :domains,
      :databases, :size

    # Public: Return true if Cloudfile is present in current directory
    def present?
      File.exists?(path)
    end

    # Public: Clouds in Cloudfile
    # Returns Array of clouds names from Cloudfile
    # nil if there is no cloudfile
    def clouds
      content.keys.sort.map do |code_name|
        Shelly::App.new(code_name, content[code_name.to_s])
      end if content
    end

    # Public: Generate example Cloudfile based on object attributes
    # Returns the generated Cloudfile as String
    def generate
      @email = current_user.email
      @thin = @size == "small" ? 2 : 4
      template = File.read(template_path)
      cloudfile = ERB.new(template, 0, "%<>-")
      cloudfile.result(binding)
    end

    # Public: Create Cloudfile in current path (or append if exists)
    # File is created based on assigned attributes
    def create
      File.open(path, "a+") { |f| f << generate }
    end

    # Internal: Load and parse Cloudfile
    def content
      return unless present?
      @content ||= YAML.load(File.open(path))
    end

    # Internal: Path to Cloudfile in current directory
    # Returns path as String
    def path
      File.join(Dir.pwd, "Cloudfile")
    end

    # Internal: Return path to Cloudfile template
    # Returns path as String
    def template_path
      File.join(File.dirname(__FILE__), "templates", "Cloudfile.erb")
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shelly-0.1.40 lib/shelly/cloudfile.rb
shelly-0.1.39 lib/shelly/cloudfile.rb
shelly-0.1.38 lib/shelly/cloudfile.rb
shelly-0.1.37.pre lib/shelly/cloudfile.rb
shelly-0.1.36 lib/shelly/cloudfile.rb
shelly-0.1.35 lib/shelly/cloudfile.rb
shelly-0.1.34 lib/shelly/cloudfile.rb
shelly-0.1.34.pre lib/shelly/cloudfile.rb
shelly-0.1.33 lib/shelly/cloudfile.rb
shelly-0.1.32 lib/shelly/cloudfile.rb
shelly-0.1.31 lib/shelly/cloudfile.rb
shelly-0.1.30 lib/shelly/cloudfile.rb
shelly-0.1.29 lib/shelly/cloudfile.rb
shelly-0.1.28 lib/shelly/cloudfile.rb
shelly-0.1.27 lib/shelly/cloudfile.rb
shelly-0.1.26 lib/shelly/cloudfile.rb
shelly-0.1.25 lib/shelly/cloudfile.rb