forked from voxpupuli/modulesync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces a new class PuppetModule in order to simplify properties computation. This new class: - allows a single `name`, `namespace` and the working directory computation - introduces the `given_name` property, which is the name the user puts in its configuration file - adds the capability a have a longer `namespace` (e.g. puppet/modules) This commit also exposes the options through ModuleSync.options instead of passing it to almost any methods. As `name` and `namespace` can be confusing in code, so they have been renamed to `repository_name` and `repository_namespace`. This commit only introduces minor changes on the output of `msync`: some single quotes have been added as delimiters for relevant dynamic part of the messages; and the use of `given_name` (i.e. user-provided name) when relevant (e.g. "Syncing 'voxpupuli/puppet-module'").
- Loading branch information
Showing
6 changed files
with
114 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'modulesync' | ||
require 'modulesync/util' | ||
|
||
module ModuleSync | ||
# Provide methods to retrieve puppet module attributes | ||
class PuppetModule | ||
attr_reader :given_name | ||
attr_reader :options | ||
|
||
def initialize(given_name, options) | ||
options ||= {} | ||
@options = Util.symbolize_keys(options) | ||
|
||
@given_name = given_name | ||
|
||
return unless given_name.include?('/') | ||
|
||
@repository_name = given_name.split('/').last | ||
@repository_namespace = given_name.split('/')[0...-1].join('/') | ||
end | ||
|
||
def repository_name | ||
@repository_name ||= given_name | ||
end | ||
|
||
def repository_namespace | ||
@repository_namespace ||= @options[:namespace] || ModuleSync.options[:namespace] | ||
end | ||
|
||
def repository_path | ||
@repository_path ||= "#{repository_namespace}/#{repository_name}" | ||
end | ||
|
||
def repository_remote | ||
@repository_remote ||= @options[:remote] || _repository_remote | ||
end | ||
|
||
def working_directory | ||
@working_directory ||= File.join(ModuleSync.options[:project_root], repository_path) | ||
end | ||
|
||
private | ||
|
||
def _repository_remote | ||
git_base = ModuleSync.options[:git_base] | ||
git_base.start_with?('file://') ? "#{git_base}#{repository_path}" : "#{git_base}#{repository_path}.git" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters