Class: Epuber::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/epuber/plugin.rb

Defined Under Namespace

Classes: PluginFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Plugin

Returns a new instance of Plugin.

Parameters:

  • path (String)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/epuber/plugin.rb', line 71

def initialize(path)
  @path = path

  @files = if ::File.file?(path)
             [PluginFile.new(path)]
           elsif ::File.directory?(path)
             Dir.glob(File.expand_path('**/*.rb', path)).map do |file_path|
               PluginFile.new(Config.instance.pretty_path_from_project(file_path))
             end
           else
             raise LoadError, "#{self}: Can't find anything for #{path}"
           end

  # expand abs_source_paths to every file
  @files.each do |file|
    file.abs_source_path = File.expand_path(file.source_path, Config.instance.project_path)
  end
end

Instance Attribute Details

#filesArray<PluginFile> (readonly)

Returns:



67
68
69
# File 'lib/epuber/plugin.rb', line 67

def files
  @files
end

#pathString (readonly)

Returns:

  • (String)


63
64
65
# File 'lib/epuber/plugin.rb', line 63

def path
  @path
end

Instance Method Details

#checkersArray<Checker>

Returns:



102
103
104
# File 'lib/epuber/plugin.rb', line 102

def checkers
  instances(Checker)
end

#instances(klass) ⇒ Array<CheckerTransformerBase>

Parameters:

  • klass (Class)

    base class of all instances

Returns:



94
95
96
97
98
# File 'lib/epuber/plugin.rb', line 94

def instances(klass)
  files.map do |plugin_file|
    plugin_file.instances.select { |inst| inst.is_a?(klass) }
  end.flatten
end

#transformersArray<Transformer>

Returns:



108
109
110
# File 'lib/epuber/plugin.rb', line 108

def transformers
  instances(Transformer)
end