forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_generator.rb
63 lines (56 loc) · 2.04 KB
/
provider_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
55
56
57
58
59
60
61
62
63
require "rails/generators/rails/app/app_generator"
class ProviderGenerator < Rails::Generators::NamedBase
source_root File.expand_path('templates', __dir__)
alias provider_name file_name
def initialize(*args)
super
self.destination_root = File.expand_path(provider_name, File.expand_path('providers', destination_root))
empty_directory "."
FileUtils.cd(destination_root)
end
def create_files
template ".codeclimate.yml"
template ".gitignore"
template ".rspec"
template ".rspec_ci"
template ".rubocop.yml"
template ".rubocop_cc.yml"
template ".rubocop_local.yml"
template ".travis.yml"
template "Gemfile"
template "LICENSE.txt"
template "manageiq-providers-%provider_name%.gemspec"
template "Rakefile"
template "README.md"
template "zanata.xml"
empty_directory_with_keep_file "locale"
empty_directory "app/models/manageiq/providers/#{provider_name}"
template "bin/rails"
template "bin/setup"
template "config/initializers/gettext.rb"
template "lib/manageiq/providers/%provider_name%.rb"
template "lib/manageiq/providers/%provider_name%/engine.rb"
template "lib/manageiq/providers/%provider_name%/version.rb"
template "lib/tasks/spec.rake"
empty_directory "spec/factories"
empty_directory "spec/models/manageiq/providers/#{provider_name}"
template "spec/spec_helper.rb"
template "tools/ci/before_install.sh"
end
def create_manageiq_gem
data = <<EOT
unless dependencies.detect { |d| d.name == "manageiq-providers-#{provider_name}" }
gem "manageiq-providers-#{provider_name}", :path => File.expand_path("providers/#{provider_name}", __dir__)
end
EOT
inject_into_file '../../Gemfile', data, :after => "# when using this Gemfile inside a providers Gemfile, the dependency for the provider is already declared\n"
end
private
def empty_directory_with_keep_file(destination, config = {})
empty_directory(destination, config)
keep_file(destination)
end
def keep_file(destination)
create_file("#{destination}/.keep")
end
end