Sha256: 67a0e9c0ab7d07ab4632545dce4800b5f774486f47e1d57b928123afea184646

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module Rna
  class Outputer
    attr_reader :options
    def initialize(options={})
      @options = options
    end
  end
  
  class Filesystem < Outputer
    def run(jsons)
      # options[:output_path] only used for specs
      output_path = options[:output_path] || "output"
      FileUtils.mkdir(output_path) unless File.exist?(output_path)
      jsons.each do |role,json|
        puts "  #{role}.json" if options[:verbose]
        File.open("#{output_path}/#{role}.json", 'w') {|f| f.write(json) }
      end
    end
  end

  class S3 < Outputer
    attr_reader :config, :s3
    def run(jsons)
      acl_options = @options[:public_read] ? {:acl => :public_read} : {}
      # options[:config] only used for specs
      s3_config_path = options[:s3_config_path] || 'config/s3.yml'
      @config ||= YAML.load(File.read(s3_config_path))
      AWS.config(@config)
      @s3 = AWS::S3.new
      bucket = @s3.buckets[@config['bucket']]
      jsons.each do |role,json|
        puts "  #{role}.json" if options[:verbose]
        bucket.objects.create("#{@config['folder']}/#{role}.json", json)
      end
      self # return outputer object for specs
    end
  end

  class Stdout < Outputer
    def run(jsons)
      jsons.each do |role,json|
        puts "-" * 60
        puts "#{role}:"
        puts json
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rna-0.2.1 lib/rna/outputers.rb
rna-0.2.0 lib/rna/outputers.rb
rna-0.1.7 lib/rna/outputers.rb
rna-0.1.6 lib/rna/outputers.rb