Class: CKick::Project
Constant Summary collapse
- NAME_MATCH =
/^[[A-Z][a-z]_[0-9]]+$/
- CMAKE_VERSION_MATCH =
/^[0-9](\.[0-9]){0,2}$/
Instance Attribute Summary collapse
-
#build_dir ⇒ Object
readonly
Returns the value of attribute build_dir.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#subdirs ⇒ Object
readonly
Returns the value of attribute subdirs.
Instance Method Summary collapse
- #cmake ⇒ Object
- #create_structure ⇒ Object
-
#initialize(args) ⇒ Project
constructor
A new instance of Project.
- #path ⇒ Object
- #plugin_name(plugin) ⇒ Object
- #register_plugin(plugin = nil, &block) ⇒ Object
- #set_name(name) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Hashable
Constructor Details
#initialize(args) ⇒ Project
Returns a new instance of Project.
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 54 55 |
# File 'lib/ckick/project.rb', line 21 def initialize args name = args[:name] || "" raise IllegalInitializationError, "name must be a non-empty string only containing alphanumeric characters" unless name.is_a?(String) && name.match(NAME_MATCH) min_v = args[:cmake_min_version] || '3' raise IllegalInitializationError, "cmake_min_version is non-String" unless min_v.is_a?(String) raise IllegalInitializationError, "cmake_min_version has non working pattern x or x.y or x.y.z" unless min_v.match(CMAKE_VERSION_MATCH) root = args[:root] || "" raise IllegalInitializationError, "root directory is non-String" unless root.is_a?(String) raise IllegalInitializationError, "root directory is empty" if root.empty? build_dir = args[:build_dir] || "" raise IllegalInitializationError, "build directory is non-String" unless build_dir.is_a?(String) raise IllegalInitializationError, "build directory is empty" if build_dir.empty? @name = name @cmake_min_version = min_v @root = root @build_dir = build_dir @dependencies = Dependencies.new(args[:dependencies] || {}) @plugins = [] args[:plugins].each do |plugin| @plugins << PluginDelegate.find(plugin) end @subdirs = [] args[:subdirs].each do |subdir| @subdirs << SubDirectory.new(subdir) end @subdirs_initiated = false init_subdirs end |
Instance Attribute Details
#build_dir ⇒ Object (readonly)
Returns the value of attribute build_dir.
16 17 18 |
# File 'lib/ckick/project.rb', line 16 def build_dir @build_dir end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
16 17 18 |
# File 'lib/ckick/project.rb', line 16 def dependencies @dependencies end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
16 17 18 |
# File 'lib/ckick/project.rb', line 16 def root @root end |
#subdirs ⇒ Object (readonly)
Returns the value of attribute subdirs.
16 17 18 |
# File 'lib/ckick/project.rb', line 16 def subdirs @subdirs end |
Instance Method Details
#cmake ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ckick/project.rb', line 99 def cmake append_plugin_paths res = "project(#{@name})\n" + "cmake_minimum_required(VERSION #{@cmake_min_version})\n\n" res << "set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)\n" \ "set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)\n" \ "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)\n\n" res << @dependencies.cmake << "\n\n" res << plugins_cmake << "\n\n" unless @plugins.empty? @subdirs.each do |dir| res << "add_subdirectory(#{dir.name})\n" if dir.has_cmake end res end |
#create_structure ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ckick/project.rb', line 74 def create_structure raise "SubDirectories have not been initiated" unless @subdirs_initiated run_plugins PathDelegate.create_directory path PathDelegate.write_file(path, "CMakeLists.txt", cmake) @subdirs.each do |subdir| subdir.create_structure end call_plugins end |
#path ⇒ Object
70 71 72 |
# File 'lib/ckick/project.rb', line 70 def path @root end |
#plugin_name(plugin) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/ckick/project.rb', line 156 def plugin_name(plugin) if plugin.respond_to?(:name) return plugin.name else return "<inline plugin>" end end |
#register_plugin(plugin = nil, &block) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/ckick/project.rb', line 89 def register_plugin(plugin=nil, &block) raise ArgumentError, "" unless plugin.is_a?(::CKick::Plugin) || block if plugin.is_a?(::CKick::Plugin) @plugins << plugin elsif plugin.nil? && block @plugins << block end end |
#set_name(name) ⇒ Object
57 58 59 60 |
# File 'lib/ckick/project.rb', line 57 def set_name(name) raise BadProjectNameError, "project name must be a non-empty alphanumeric string" unless name.is_a?(String) && name.match(NAME_MATCH) @name = name end |
#to_hash ⇒ Object
66 67 68 |
# File 'lib/ckick/project.rb', line 66 def to_hash to_no_empty_value_hash.without(:subdirs_initiated) end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/ckick/project.rb', line 62 def to_s @name end |