Sha256: 8559e3ba5d7718fb9ab34162824f6391926615a765744359c624c38e17136812

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

module Rna
  class Outputer
    attr_reader :options
    def initialize(options={})
      @options = options
    end
  end
  
  class Filesystem < Outputer
    def run(jsons)
      output_path = options[:output_path] || "output"
      FileUtils.rm_rf(output_path) if options[:clean]
      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)
      # 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

5 entries across 5 versions & 1 rubygems

Version Path
rna-0.4.7 lib/rna/outputers.rb
rna-0.4.6 lib/rna/outputers.rb
rna-0.4.2 lib/rna/outputers.rb
rna-0.4.1 lib/rna/outputers.rb
rna-0.4.0 lib/rna/outputers.rb