Sha256: 596f221040b314d34a98bc3fd29b3726c8e0e0659389dd5d5a9e83787d8942fb

Contents?: true

Size: 1.95 KB

Versions: 5

Compression:

Stored size: 1.95 KB

Contents

# -*- encoding: utf-8 -*-

require 'watch_tower/appscript'

module WatchTower
  module Editor
    module BaseAppscript
      def self.included(base)
        base.send :include, InstanceMethods
      end

      module InstanceMethods
        def self.included(base)
          base.class_eval <<-END, __FILE__, __LINE__ + 1
            # Include AppScript
            include ::Appscript

            # Is the editor running ?
            #
            # @return [Boolean]
            def is_running?
              editor.is_running? if editor
            end

            # Returns the name of the editor
            #
            # Child class should implement this method
            def name
              editor.try(:name).try(:get)
            end

            # Returns the version of the editor
            #
            # Child class should implement this method
            def version
              editor.try(:version).try(:get)
            end

            # Return the path of the document being edited
            # Child classes can override this method if the behaviour is different
            #
            # @return [String] path to the document currently being edited
            def current_path
              current_paths.try(:first)
            end

            # Return the pathes of the documents being edited
            # Child classes can override this method if the behaviour is different
            #
            # @return [Array] pathes to the documents currently being edited
            def current_paths
              if is_running? && editor.respond_to?(:document)
                editor.document.get.collect(&:path).collect(&:get)
              end
            end

            # The editor's name for the log
            # Child classes can overwrite this method
            #
            # @return [String]
            def to_s
              "\#{self.class.to_s.split('::').last} Editor"
            end
          END
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
watch_tower-0.0.1.beta8 lib/watch_tower/editor/base_appscript.rb
watch_tower-0.0.1.beta7 lib/watch_tower/editor/base_appscript.rb
watch_tower-0.0.1.beta6 lib/watch_tower/editor/base_appscript.rb
watch_tower-0.0.1.beta5 lib/watch_tower/editor/base_appscript.rb
watch_tower-0.0.1.beta4 lib/watch_tower/editor/base_appscript.rb