Sha256: f4699ad8ea008dcfbea884d3efb63c59fd3ada0eed11e40a0fbe50487e5fe7a9

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

module Localeapp
  module CLI
    class Push
      include ::Localeapp::ApiCall

      def initialize(output = $stdout)
        @output = output
      end

      def execute(path = nil)
        @output.puts "Localeapp Push"
        if path_is_directory?(path)
          yaml_files_in_directory(path).each do |path|
            push_file(path)
          end
        else
          push_file(path)
        end
      end

      def push_file(file_path)
        @output.puts ""
        @file_path = file_path # for callbacks
        file = sanitize_file(file_path)
        if file
          @output.puts "Pushing file #{File.basename(file_path)}:"
          api_call :import,
            :payload => { :file => file },
            :success => :report_success,
            :failure => :report_failure,
            :max_connection_attempts => 3
        else
          @output.puts "Could not load file"
        end
      end

      def report_success(response)
        @output.puts "Success!"
        @output.puts ""
        @output.puts "#{@file_path} queued for processing."
      end

      def report_failure(response)
        @output.puts "Failed!"
      end

      private
      def sanitize_file(file_path)
        if File.exist?(file_path)
          File.new(file_path)
        else
          nil
        end
      end

      def path_is_directory?(path)
        File.directory?(path)
      end

      def yaml_files_in_directory(path)
        Dir.glob(File.join(path, '*.yml')).sort
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
localeapp-0.5.2 lib/localeapp/cli/push.rb
localeapp-0.5.1 lib/localeapp/cli/push.rb
localeapp-0.5.0 lib/localeapp/cli/push.rb
localeapp-0.4.3 lib/localeapp/cli/push.rb
localeapp-0.4.2 lib/localeapp/cli/push.rb
localeapp-0.4.1 lib/localeapp/cli/push.rb
localeapp-0.4.0 lib/localeapp/cli/push.rb
localeapp-0.3.2 lib/localeapp/cli/push.rb
localeapp-0.3.1 lib/localeapp/cli/push.rb
localeapp-0.3.0 lib/localeapp/cli/push.rb