Sha256: 3abffc9505aa0ab81b1b57839b54849b6fe284e5413921753560a45d298cddf0

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

module Granify
  module Controller
    class Open < Controller::Base
      def files
        begin
          files = []
          
          if !$request.custom.nil? && $request.custom.size > 0
            # pull file list from CLI args
            $request.custom.each do |requested_file|
              files.push(requested_file) if File.exists? requested_file.to_s
            end
          else
            raise ::ArgumentError, "Command requires a list of files to open\ni.e. #{Granify::PACKAGE_NAME} open files file1.ext file2.ext file3.ext"
          end

          # we have some files, lets open them
          if files.size > 0
            `$EDITOR -n #{files.join(' ')}`

            Notify.success("Opened #{files.size} file(s) in sublime text")
          else
            Notify.warning("The requested files (#{$request.custom.join(', ')}) could not be opened")
          end

        rescue => e
          Notify.error(e.message)
        end
      end

      def files_from_log
        begin
          files = []

          if File.exists? $request.custom[0].to_s
            # pull file list from a log file
            files = IO.readlines($request.custom[0].to_s)
            files.each do |l|
              l.gsub!(/\r\n?/, "")
            end
          else
            raise ::ArgumentError, "Command requires a log file\ni.e. #{Granify::PACKAGE_NAME} open files_from_log file1.log"
          end

          if files.size > 0
            `$EDITOR -n #{files.join(' ')}`

            Notify.success("Opened #{files.size} file(s) in sublime text")
          else
            Notify.warning("The requested files (#{$request.custom.join(', ')}) could not be opened")
          end
        rescue => e
          Notify.error(e.message)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rbtils-0.0.2 lib/controllers/open.rb
rbtils-0.0.1 lib/controllers/open.rb