Class: RepoManager::Add

Inherits:
Thor
  • Object
show all
Includes:
ActionHelper, AddHelper, GenerateHelper, ThorHelper, Thor::Actions
Defined in:
lib/repo_manager/tasks/add/asset.rb

Instance Method Summary collapse

Methods included from ActionHelper

#relative_path, #shell_quote, #windows?

Methods included from AddHelper

#process_discovered_assets

Methods included from GenerateHelper

#asset_name_to_config_file

Methods included from ThorHelper

#configuration, #configuration=, #ruby_binary

Instance Method Details

#asset(folder) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/repo_manager/tasks/add/asset.rb', line 161

def asset(folder)
  discovered_assets = []
  unless File.exists?(File.join(folder, '.git/'))
    say_status :error, "unable to find '.git' folder in working folder '#{folder}'", :red
    exit 1
  end

  # check existing assets for path match, if found, use existing name instead of the generated name
  existing = existing_assets.detect do |existing_asset|
    existing_asset.path && folder && (File.expand_path(existing_asset.path) == File.expand_path(folder))
  end

  if (existing)
    name = existing.name
    if options[:name]
      say_status :error, "asset already exists under a different name '#{name}'", :red
      exit 1
    end
  else
    name = options[:name]
    name ||= File.basename(folder)
  end

  asset = ::RepoManager::RepoAsset.new(name)
  asset.path = File.expand_path(folder)

  discovered_assets << asset
  process_discovered_assets(discovered_assets)
end

#assets(folder) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/repo_manager/tasks/add/asset.rb', line 127

def assets(folder)
  say_status "collecting",  "collecting top level folder names"
  discovered_assets = []
  filters = options[:filter] || ['.*']
  # Thor does not allow comma separated array options, fix that here
  filters = filters.first.to_s.split(',') if filters.length == 1
  Dir.glob( File.join(folder, '*/')  ).each do |repo_folder|
    logger.debug "filters: #{filters.inspect}"
    next unless filters.find {|filter| repo_folder.match(/#{filter}/)}
    next unless File.exists?(File.join(repo_folder, '.git/'))

    # check existing assets for path match, if found, use existing name instead of the generated name
    existing = existing_assets.detect do |existing_asset|
      existing_asset.path && repo_folder && (File.expand_path(existing_asset.path) == File.expand_path(repo_folder))
    end

    if (existing)
      name = existing.name
    else
      name = File.basename(repo_folder)
    end

    asset = ::RepoManager::RepoAsset.new(name)
    asset.path = File.expand_path(repo_folder)

    discovered_assets << asset
  end

  process_discovered_assets(discovered_assets)
end