Class: Makit::Configuration::Project
- Inherits:
-
Object
- Object
- Makit::Configuration::Project
- Defined in:
- lib/makit/configuration/project.rb
Overview
Project configuration management - Refactored to use protobuf messages exclusively
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
-
.convert_from_proto_model(proto_model) ⇒ Object
Convert Protobuf model to Ruby Project object.
-
.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.
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 48 49 50 51 52 53 54 |
# File 'lib/makit/configuration/project.rb', line 15 def initialize(name, version = nil, project_type = nil) @grpc_service = Makit::V1::Configuration::ProjectServiceImpl.new # 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 # Create project via gRPC service (handle empty names) if @name && !@name.strip.empty? create_request = Makit::V1::Configuration::CreateProjectRequest.new( name: @name, version: @version || "0.0.0", project_type: @project_type || "gem" ) @proto_model = @grpc_service.create_project(create_request, nil) else # Create empty project directly (bypass gRPC validation for empty names) @proto_model = Makit::V1::Configuration::Project.new( name: @name || "", version: @version || "0.0.0", project_type: @project_type || "", authors: "authors", description: "description", license_expression: "MIT", steps: [] ) end # Initialize Ruby attributes for backward compatibility sync_attributes_from_proto end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def description @description end |
#dotnet_projects ⇒ Object
Returns the value of attribute dotnet_projects.
13 14 15 |
# File 'lib/makit/configuration/project.rb', line 13 def dotnet_projects @dotnet_projects end |
#git_remote_url ⇒ Object
Returns the value of attribute git_remote_url.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def git_remote_url @git_remote_url end |
#license_expression ⇒ Object
Returns the value of attribute license_expression.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def license_expression @license_expression end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def name @name end |
#project_type ⇒ Object
Returns the value of attribute project_type.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def project_type @project_type end |
#steps ⇒ Object
Returns the value of attribute steps.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def steps @steps end |
#version ⇒ Object
Returns the value of attribute version.
12 13 14 |
# File 'lib/makit/configuration/project.rb', line 12 def version @version end |
Class Method Details
.convert_from_proto_model(proto_model) ⇒ Object
Convert Protobuf model to Ruby Project object
258 259 260 261 262 263 264 265 266 |
# File 'lib/makit/configuration/project.rb', line 258 def self.convert_from_proto_model(proto_model) project = new(proto_model.name, proto_model.version, proto_model.project_type) # Update all attributes from Protobuf model project.instance_variable_set(:@proto_model, proto_model) project.send(:sync_attributes_from_proto) project end |
.decode_json(json_string) ⇒ Object
Class method for deserializing from JSON string (used by serializer)
120 121 122 123 124 125 126 127 128 |
# File 'lib/makit/configuration/project.rb', line 120 def self.decode_json(json_string) # Use gRPC service to load from JSON string grpc_service = Makit::V1::Configuration::ProjectServiceImpl.new request = Makit::V1::Configuration::LoadFromJsonRequest.new(json_string: json_string) proto_model = grpc_service.load_from_json(request, nil) # Convert Protobuf model to Ruby object convert_from_proto_model(proto_model) end |
.default ⇒ Object
Load a project from the default .makit.json file
194 195 196 197 198 199 200 201 202 |
# File 'lib/makit/configuration/project.rb', line 194 def self.default # Use gRPC service to load default project grpc_service = Makit::V1::Configuration::ProjectServiceImpl.new request = Google::Protobuf::Empty.new proto_model = grpc_service.load_default(request, nil) # Convert Protobuf model to Ruby object convert_from_proto_model(proto_model) end |
.from_json(path) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/makit/configuration/project.rb', line 109 def self.from_json(path) # Use gRPC service to load from file grpc_service = Makit::V1::Configuration::ProjectServiceImpl.new request = Makit::V1::Configuration::LoadFromFileRequest.new(path: path) proto_model = grpc_service.load_from_file(request, nil) # Convert Protobuf model to Ruby object convert_from_proto_model(proto_model) end |
Instance Method Details
#add_step(step) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/makit/configuration/project.rb', line 56 def add_step(step) raise ArgumentError, "Step must be a Makit::Configuration::Step instance" unless step.is_a?(Step) # Add step to Protobuf model proto_step = Makit::V1::Configuration::Step.new( name: step.name, description: step.description, commands: step.commands ) @proto_model.steps << proto_step # Update Ruby attribute for backward compatibility @steps << step end |
#save ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/makit/configuration/project.rb', line 161 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 # Use gRPC service to save to default location request = Makit::V1::Configuration::SaveToDefaultRequest.new(project: @proto_model) @grpc_service.save_to_default(request, nil) end |
#save_as(path) ⇒ Object
Save the project to a specific path as pretty JSON
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/makit/configuration/project.rb', line 147 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 # Use gRPC service to save to file request = Makit::V1::Configuration::SaveToFileRequest.new( project: @proto_model, path: path ) @grpc_service.save_to_file(request, nil) end |
#show ⇒ Object
Display the project configuration in YAML format
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/makit/configuration/project.rb', line 173 def show require "yaml" project_data = { name: @proto_model.name, version: @proto_model.version, project_type: @proto_model.project_type, git_remote_url: @proto_model.git_remote_url, steps: @proto_model.steps.map do |step| { name: step.name, description: step.description, commands: step.commands.to_a } end } puts YAML.dump(project_data) end |
#to_gitlab_ci(path) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/makit/configuration/project.rb', line 130 def to_gitlab_ci(path) # Use gRPC service to generate GitLab CI request = Makit::V1::Configuration::GenerateGitlabCiRequest.new( project: @proto_model, path: path ) @grpc_service.generate_gitlab_ci(request, nil) end |
#to_json(*args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/makit/configuration/project.rb', line 71 def to_json(*args) project_data = { name: @proto_model.name, version: @proto_model.version, project_type: @proto_model.project_type, authors: @proto_model., description: @proto_model.description, license_expression: @proto_model.license_expression, steps: @proto_model.steps.map do |step| { name: step.name, description: step.description, commands: step.commands.to_a } end } project_data.to_json(*args) end |
#to_json_pretty ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/makit/configuration/project.rb', line 90 def to_json_pretty project_data = { name: @proto_model.name, version: @proto_model.version, project_type: @proto_model.project_type, authors: @proto_model., description: @proto_model.description, license_expression: @proto_model.license_expression, steps: @proto_model.steps.map do |step| { name: step.name, description: step.description, commands: step.commands.to_a } end } JSON.pretty_generate(project_data) end |
#to_rakefile ⇒ Object
139 140 141 142 143 144 |
# File 'lib/makit/configuration/project.rb', line 139 def to_rakefile # Use gRPC service to generate Rakefile request = Makit::V1::Configuration::GenerateRakefileRequest.new(project: @proto_model) response = @grpc_service.generate_rakefile(request, nil) response.content end |