Class: CKick::Target
Overview
common representation of targets to build, such as executables and libraries
Direct Known Subclasses
Instance Method Summary collapse
-
#create_structure ⇒ Object
creates target’s structure (each missing source file).
-
#initialize(args = {}) ⇒ Target
constructor
-
args
- Target hash (directly a CKickfile target element’s hash parsed with keys as Symbol), must be a Hash ====== Input hash keys *:name
- name of the target *:source
- either a String (single-source file) or Array of String (multiple source files) *:libs
- names of the libraries to link to the target, must be Array of String.
-
-
#paths ⇒ Object
Array of source file paths.
-
#to_hash ⇒ Object
converts to Hash (for CKickfile).
-
#to_s ⇒ Object
converts to String, the target’s name as is.
Methods included from Hashable
Constructor Details
#initialize(args = {}) ⇒ Target
-
args
- Target hash (directly a CKickfile target element’s hash parsed with keys as Symbol), must be a Hash
Input hash keys
-
:name
- name of the target -
:source
- either a String (single-source file) or Array of String (multiple source files) -
:libs
- names of the libraries to link to the target, must be Array of String
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 |
# File 'lib/ckick/target.rb', line 21 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_structure ⇒ Object
creates target’s structure (each missing source file)
76 77 78 79 80 81 82 |
# File 'lib/ckick/target.rb', line 76 def create_structure paths.each do |path| unless File.exist? path PathDelegate.touch_file(path) end end end |
#paths ⇒ Object
Array of source file paths
66 67 68 69 70 71 72 73 |
# File 'lib/ckick/target.rb', line 66 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_hash ⇒ Object
converts to Hash (for CKickfile)
56 57 58 |
# File 'lib/ckick/target.rb', line 56 def to_hash to_no_empty_value_hash.without(:parent_dir) end |
#to_s ⇒ Object
converts to String, the target’s name as is
61 62 63 |
# File 'lib/ckick/target.rb', line 61 def to_s @name end |