Class: Take::Project::Target

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

Instance Method Summary collapse

Constructor Details

#initialize(hash, project, &block) ⇒ Target

Initializes the target.

Parameters:

  • project (Project)

    the project that this target is a part of.

  • hash (Hash)

    a hash of the options for this target. If the any key is not one of the below, it is assumed to be the target key-pair; there may only be one target key-pair (any more will cause an ArgumentError). If the key of the key pair is a symbol, it is considered an “invalid” target, meaning it _must not_ be a default target.

Options Hash (hash):

  • :type (Symbol)

    The type of target it is. This is normally assumed from the extension.

  • :depends, (Array<String>)

    :depends_on Files that the target depends on. This is normally set by the value of the target key pair.

  • :name (Symbol, String)

    The name of the target. This is normally set by the key of the target key pair.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
# File 'lib/take/project/target.rb', line 23

def initialize(hash, project, &block)
  raise ArgumentError, "Targets require blocks" \
    unless block_given?
  @block = block
  @project = project
  @dependencies = []
  handle_arguments(hash)
  guess_type unless @type
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/take/project/target.rb', line 33

def invalid?
  @target.is_a?(Symbol)
end

#nameObject



37
38
39
40
41
42
43
# File 'lib/take/project/target.rb', line 37

def name
  if invalid?
    @target
  else
    @target.to_path
  end
end

#sub(what, to) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/take/project/target.rb', line 45

def sub(what, to)
  @dependencies.map do |dep|
    if dep.extname == what
      dep.sub_ext(to)
    else
      dep
    end
  end
end

#to_aObject



55
56
57
# File 'lib/take/project/target.rb', line 55

def to_a
  @dependencies.map(&:to_path)
end