Class: CKick::SubDirectory
- Inherits:
-
Object
- Object
- CKick::SubDirectory
- Includes:
- Hashable
- Defined in:
- lib/ckick/sub_directory.rb
Overview
Represents a project sub directory (in respect to CMake sub_directory() command)
Instance Attribute Summary collapse
-
#has_cmake ⇒ Object
readonly
whether or not this directory has targets and a CMakeLists.txt.
-
#name ⇒ Object
readonly
directory name.
-
#parent_dir ⇒ Object
readonly
parent directory.
Instance Method Summary collapse
-
#cmake ⇒ Object
subdirectory CMakeLists.txt file content.
-
#create_structure ⇒ Object
creates subdirectory structure.
-
#initialize(args = {}) ⇒ SubDirectory
constructor
-
args
- SubDirectory hash (directly a CKickfile :subdirs Array element parsed with keys as Symbol), must be a Hash ====== Input hash keys *:name
- subdirectory name *:libraries
- libraries built in this subdirectory (in respect to CMake add_library() command), Array of Hash each containing information for CKick::Library::new *:executables
- executables built in this subdirectory (in respect to CMake add_executable() command), Array of Hash each containing information for CKick::Executable::new *:subdirs
- recursive subdirectories (in respect to CMake subdirectory() command), must be a Array of Hash passed to CKick::SubDirectory::new *:has_cmake
- whether or not this subdirectory has a CMakeLists.txt (consequently builds targets or not).
-
-
#path ⇒ Object
subdirectory path.
-
#to_hash ⇒ Object
converts to Hash (to CKickfile :subdirs element).
-
#to_s ⇒ Object
converts to String, subdirectory name as is.
Methods included from Hashable
Constructor Details
#initialize(args = {}) ⇒ SubDirectory
-
args
- SubDirectory hash (directly a CKickfile :subdirs Array element parsed with keys as Symbol), must be a Hash
Input hash keys
-
:name
- subdirectory name -
:libraries
- libraries built in this subdirectory (in respect to CMake add_library() command), Array of Hash each containing information for CKick::Library::new -
:executables
- executables built in this subdirectory (in respect to CMake add_executable() command), Array of Hash each containing information for CKick::Executable::new -
:subdirs
- recursive subdirectories (in respect to CMake subdirectory() command), must be a Array of Hash passed to CKick::SubDirectory::new -
:has_cmake
- whether or not this subdirectory has a CMakeLists.txt (consequently builds targets or not)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ckick/sub_directory.rb', line 34 def initialize args={} name = args[:name] raise IllegalInitializationError, "no name provided to sub directory" unless name.is_a?(String) && !name.empty? libs = args[:libraries] raise IllegalInitializationError, ":libraries argument is not an Array" unless libs.is_a?(Array) || libs.nil? exes = args[:executables] raise IllegalInitializationError, ":executables argument is not an Array" unless exes.is_a?(Array) || exes.nil? subdirs = args[:subdirs] raise IllegalInitializationError, ":subdirs is not an Array" unless subdirs.is_a?(Array) || subdirs.nil? has_cmake = args[:has_cmake].nil? || args[:has_cmake] if (!exes.nil? || !libs.nil?) && !has_cmake raise BadSubDirectoryError, "A subdirectory not containing a CMakeLists cannot contain targets." end @name = name @has_cmake = has_cmake @libraries = [] libs.each do |lib| @libraries << Library.new(lib) end @executables = [] exes.each do |exe| @executables << Executable.new(exe) end @subdirs = [] subdirs.each do |subdir| @subdirs << SubDirectory.new(subdir) end @parent_dir = nil end |
Instance Attribute Details
#has_cmake ⇒ Object (readonly)
whether or not this directory has targets and a CMakeLists.txt
25 26 27 |
# File 'lib/ckick/sub_directory.rb', line 25 def has_cmake @has_cmake end |
#name ⇒ Object (readonly)
directory name
19 20 21 |
# File 'lib/ckick/sub_directory.rb', line 19 def name @name end |
#parent_dir ⇒ Object (readonly)
parent directory
22 23 24 |
# File 'lib/ckick/sub_directory.rb', line 22 def parent_dir @parent_dir end |
Instance Method Details
#cmake ⇒ Object
subdirectory CMakeLists.txt file content
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/ckick/sub_directory.rb', line 109 def cmake res = '' res << targets.collect { |t| t.cmake }.join("\n") unless @subdirs.empty? res << "\n" res << @subdirs.collect do |subdir| "add_subdirectory(#{subdir.name})" end.join("\n") end res end |
#create_structure ⇒ Object
creates subdirectory structure
this method is called recursively on subdirectories
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ckick/sub_directory.rb', line 92 def create_structure PathDelegate.create_directory(path) if @has_cmake PathDelegate.write_file(path, "CMakeLists.txt", cmake) targets.each do |t| t.create_structure end end @subdirs.each do |subdir| subdir.create_structure end end |
#path ⇒ Object
subdirectory path
84 85 86 87 |
# File 'lib/ckick/sub_directory.rb', line 84 def path raise NoParentDirError, "sub directory #{@name} has no parent set" unless @parent_dir File.join(@parent_dir, @name) end |
#to_hash ⇒ Object
converts to Hash (to CKickfile :subdirs element)
76 77 78 79 80 81 |
# File 'lib/ckick/sub_directory.rb', line 76 def to_hash if !@has_cmake return to_no_empty_value_hash.without(:parent_dir) end to_no_empty_value_hash.without(:parent_dir, :has_cmake) end |
#to_s ⇒ Object
converts to String, subdirectory name as is
71 72 73 |
# File 'lib/ckick/sub_directory.rb', line 71 def to_s @name end |