Class: Makit::Configuration::Project
- Inherits:
-
Object
- Object
- Makit::Configuration::Project
- Defined in:
- lib/makit/configuration/project.rb
Overview
Project configuration management
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#description ⇒ Object
Returns the value of attribute description.
-
#dotnet_projects ⇒ Object
Returns the value of attribute dotnet_projects.
-
#git_remote_url ⇒ Object
Returns the value of attribute git_remote_url.
-
#license_expression ⇒ Object
Returns the value of attribute license_expression.
-
#name ⇒ Object
Returns the value of attribute name.
-
#project_type ⇒ Object
Returns the value of attribute project_type.
-
#steps ⇒ Object
Returns the value of attribute steps.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.decode_json(json_string) ⇒ Object
Class method for deserializing from JSON string (used by serializer).
-
.default ⇒ Object
Load a project from the default .makit.json file.
- .from_json(path) ⇒ Object
Instance Method Summary collapse
- #add_step(step) ⇒ Object
-
#initialize(name, version = nil, project_type = nil) ⇒ Project
constructor
A new instance of Project.
- #save ⇒ Object
-
#save_as(path) ⇒ Object
Save the project to a specific path as pretty JSON.
-
#show ⇒ Object
Display the project configuration in YAML format.
- #to_gitlab_ci(path) ⇒ Object
- #to_json(*args) ⇒ Object
- #to_json_pretty ⇒ Object
- #to_rakefile ⇒ Object
Constructor Details
#initialize(name, version = nil, project_type = nil) ⇒ Project
Returns a new instance of Project.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/makit/configuration/project.rb', line 12 def initialize(name, version = nil, project_type = nil) # Support both keyword arguments and positional arguments for compatibility if name.is_a?(Hash) # Keyword arguments: Project.new(name: "test", version: "1.0.0") @name = name[:name] @version = name[:version] @project_type = name[:project_type] else # Positional arguments: Project.new("test", "1.0.0", "nuget") @name = name @version = version @project_type = project_type end @authors = "authors" @description = "description" @license_expression = "MIT" @steps = [] end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def @authors end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def description @description end |
#dotnet_projects ⇒ Object
Returns the value of attribute dotnet_projects.
10 11 12 |
# File 'lib/makit/configuration/project.rb', line 10 def dotnet_projects @dotnet_projects end |
#git_remote_url ⇒ Object
Returns the value of attribute git_remote_url.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def git_remote_url @git_remote_url end |
#license_expression ⇒ Object
Returns the value of attribute license_expression.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def license_expression @license_expression end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def name @name end |
#project_type ⇒ Object
Returns the value of attribute project_type.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def project_type @project_type end |
#steps ⇒ Object
Returns the value of attribute steps.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def steps @steps end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/makit/configuration/project.rb', line 9 def version @version end |
Class Method Details
.decode_json(json_string) ⇒ Object
Class method for deserializing from JSON string (used by serializer)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/makit/configuration/project.rb', line 85 def self.decode_json(json_string) data = JSON.parse(json_string, symbolize_names: true) project = new(data[:name], data[:version], data[:project_type]) # Set additional fields if they exist in the JSON project. = data[:authors] if data[:authors] project.description = data[:description] if data[:description] project.license_expression = data[:license_expression] if data[:license_expression] data[:steps].each do |step_data| step = Step.new( name: step_data[:name], description: step_data[:description], commands: step_data[:commands], ) project.add_step(step) end project end |
.default ⇒ Object
Load a project from the default .makit.json file
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/makit/configuration/project.rb', line 150 def self.default if File.exist?(".makit.json") from_json(".makit.json") else # Makit::Logging.default_logger.warn("Project not configured") # #if defined?(NAME) && defined?(VERSION) && defined?(PROJECT_TYPE) # project = new(name: NAME, version: VERSION, project_type: PROJECT_TYPE) # project.save # else project = new(name: "", version: "0.0.0", project_type: "") Makit::Logging.default_logger.warn("Project not configured") # Makit::Logging.default_logger.warn("Define NAME, VERSION, and PROJECT_TYPE in the Rakefile") # end project end end |
.from_json(path) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/makit/configuration/project.rb', line 61 def self.from_json(path) content = File.read(path) data = JSON.parse(content, symbolize_names: true) project = new(data[:name], data[:version], data[:project_type]) # Set additional fields if they exist in the JSON project. = data[:authors] if data[:authors] project.description = data[:description] if data[:description] project.license_expression = data[:license_expression] if data[:license_expression] data[:steps].each do |step_data| step = Step.new( name: step_data[:name], description: step_data[:description], commands: step_data[:commands], ) project.add_step(step) end project end |
Instance Method Details
#add_step(step) ⇒ Object
31 32 33 34 35 |
# File 'lib/makit/configuration/project.rb', line 31 def add_step(step) raise ArgumentError, "Step must be a Makit::Configuration::Step instance" unless step.is_a?(Step) @steps << step end |
#save ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/makit/configuration/project.rb', line 125 def save # Validate that the project has a non-empty name before saving if @name.nil? || @name.strip.empty? raise ArgumentError, "Project name cannot be empty. Please set a valid project name before saving." end save_as(".makit.json") end |
#save_as(path) ⇒ Object
Save the project to a specific path as pretty JSON
116 117 118 119 120 121 122 123 |
# File 'lib/makit/configuration/project.rb', line 116 def save_as(path) # Validate that the project has a non-empty name before saving if @name.nil? || @name.strip.empty? raise ArgumentError, "Project name cannot be empty. Please set a valid project name before saving." end File.write(path, to_json_pretty) end |
#show ⇒ Object
Display the project configuration in YAML format
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/makit/configuration/project.rb', line 135 def show require "yaml" project_data = { name: @name, version: @version, project_type: @project_type, git_remote_url: @git_remote_url, steps: @steps.map(&:to_h), } puts YAML.dump(project_data) end |
#to_gitlab_ci(path) ⇒ Object
107 108 109 |
# File 'lib/makit/configuration/project.rb', line 107 def to_gitlab_ci(path) GitLabHelper.to_yaml(self, path) end |
#to_json(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/makit/configuration/project.rb', line 37 def to_json(*args) { name: @name, version: @version, project_type: @project_type, authors: @authors, description: @description, license_expression: @license_expression, steps: @steps.map(&:to_h), }.to_json(*args) end |
#to_json_pretty ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/makit/configuration/project.rb', line 49 def to_json_pretty JSON.pretty_generate({ name: @name, version: @version, project_type: @project_type, authors: @authors, description: @description, license_expression: @license_expression, steps: @steps.map(&:to_h), }) end |
#to_rakefile ⇒ Object
111 112 113 |
# File 'lib/makit/configuration/project.rb', line 111 def to_rakefile RakefileHelper.generate(self) end |