Class: Audition::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/audition/target.rb

Overview

Figures out what the user pointed us at and what that means for scanning (which .rb files) and dynamic probing (which entry).

Detection precedence for directories: Rails beats Rack (a Rails root always has a config.ru), Rack beats gem (an app may vendor a gemspec), gem beats plain directory.

Constant Summary collapse

EXCLUDED_DIRS =
%w[
  vendor node_modules tmp log coverage pkg .git .bundle
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, root:, ruby_files:, entry:) ⇒ Target

Returns a new instance of Target.



165
166
167
168
169
170
# File 'lib/audition/target.rb', line 165

def initialize(type:, root:, ruby_files:, entry:)
  @type = type
  @root = root
  @ruby_files = ruby_files
  @entry = entry
end

Instance Attribute Details

#entryHash? (readonly)

Returns dynamic probe entry (:mode plus mode-specific keys), nil for static-only targets.

Returns:

  • (Hash, nil)

    dynamic probe entry (:mode plus mode-specific keys), nil for static-only targets



27
28
29
# File 'lib/audition/target.rb', line 27

def entry
  @entry
end

#rootString (readonly)

Returns the target's root directory.

Returns:

  • (String)

    the target's root directory



20
21
22
# File 'lib/audition/target.rb', line 20

def root
  @root
end

#ruby_filesArray<String> (readonly)

Returns Ruby files to scan statically.

Returns:

  • (Array<String>)

    Ruby files to scan statically



23
24
25
# File 'lib/audition/target.rb', line 23

def ruby_files
  @ruby_files
end

#typeSymbol (readonly)

Returns one of :script, :gem, :rack, :rails, :directory, :bundle.

Returns:

  • (Symbol)

    one of :script, :gem, :rack, :rails, :directory, :bundle



17
18
19
# File 'lib/audition/target.rb', line 17

def type
  @type
end

Class Method Details

.detect(raw) ⇒ Target

Detects what raw points at and builds the target.

Parameters:

  • raw (String)

    a .rb/.ru file, a directory, a Gemfile.lock, or an installed gem name

Returns:

Raises:



35
36
37
38
39
40
41
42
43
44
# File 'lib/audition/target.rb', line 35

def self.detect(raw)
  raw = normalize(raw)
  if File.file?(raw)
    from_file(raw)
  elsif File.directory?(raw)
    from_directory(raw)
  else
    from_gem_name(raw)
  end
end