Class: CKick::Target

Inherits:
Object
  • Object
show all
Includes:
Hashable
Defined in:
lib/ckick/target.rb

Direct Known Subclasses

Executable, Library

Instance Method Summary collapse

Methods included from Hashable

#to_no_empty_value_hash

Constructor Details

#initialize(args = {}) ⇒ Target

Returns a new instance of Target.



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
# File 'lib/ckick/target.rb', line 15

def initialize args={}
  raise IllegalInitializationError unless args.is_a?(Hash) && !args.empty?

  name = args[:name] || ""
  raise NoNameError, "No target name given for target" unless name.is_a?(String) && !name.empty?
  @name = name

  source = args[:source] || []
  if source.is_a? Array
    raise NoSourceError, "No source file provided for target #{@name}" if source.empty?
    raise BadSourceError, "Bad source file names provided for target #{@name}: #{source}" unless source.select { |el| !el.is_a?(String) }.empty?
    @source = source
  elsif source.is_a? String
    @source = [source]
  else
    raise BadSourceError, "Bad source file name provided for target #{@name}"
  end

  @libs = []
  libs = args[:libs] || []
  if libs.is_a?(Array)
    raise BadLibError, "Bad library name provided for target #{@name}: #{libs}" unless libs.select { |el| !el.is_a?(String) }.empty?
    libs.each do |lib|
      @libs << LibraryLink.new(name: lib)
    end
  elsif libs.is_a?(String)
    @libs << LibraryLink.new(name: libs)
  else
    raise BadLibError, "Bad library name provided for target #{@name}: #{libs}"
  end

  @parent_dir = nil
end

Instance Method Details

#create_structureObject



66
67
68
69
70
71
72
# File 'lib/ckick/target.rb', line 66

def create_structure
  paths.each do |path|
    unless File.exist? path
      PathDelegate.touch_file(path)
    end
  end
end

#pathsObject

Raises:



57
58
59
60
61
62
63
64
# File 'lib/ckick/target.rb', line 57

def paths
  raise NoParentDirError, "No parent directory has been set for target #{@name}" unless @parent_dir
  res = []
  @source.each do |source_file|
    res << File.join(@parent_dir, source_file)
  end
  res
end

#to_hashObject



49
50
51
# File 'lib/ckick/target.rb', line 49

def to_hash
  to_no_empty_value_hash.without(:parent_dir)
end

#to_sObject



53
54
55
# File 'lib/ckick/target.rb', line 53

def to_s
  @name
end