Module: WatchTower::Editor::BaseAppscript::InstanceMethods

Defined in:
lib/watch_tower/editor/base_appscript.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/watch_tower/editor/base_appscript.rb', line 13

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
      @name ||= editor.try(:name).try(:get)
    end

    # Returns the version of the editor
    #
    # Child class should implement this method
    def version
      @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 Version \#{version}"
    end
  END
end