lib/berkshelf/cookbook_generator.rb in berkshelf-3.1.4 vs lib/berkshelf/cookbook_generator.rb in berkshelf-3.1.5
- old
+ new
@@ -1,9 +1,19 @@
module Berkshelf
class CookbookGenerator < BaseGenerator
require_relative 'config'
+ LICENSE_MAP = {
+ "apachev2" => "Apache 2.0",
+ "gplv2" => "GNU Public License 2.0",
+ "gplv3" => "GNU Public License 3.0",
+ "mit" => "MIT",
+ "reserved" => "All rights reserved",
+ }.freeze
+
+ (LICENSES = LICENSE_MAP.keys).freeze
+
argument :name,
type: :string,
required: true
class_option :skip_vagrant,
@@ -81,17 +91,11 @@
def commented(content)
content.split("\n").collect { |s| s == "" ? "#" : "# #{s}"}.join("\n")
end
def license_name
- case options[:license]
- when 'apachev2'; 'Apache 2.0'
- when 'gplv2'; 'GNU Public License 2.0'
- when 'gplv3'; 'GNU Public License 3.0'
- when 'mit'; 'MIT'
- when 'reserved'; 'All rights reserved'
- else
- raise Berkshelf::LicenseNotFound.new(options[:license])
+ LICENSE_MAP.fetch(options[:license]) do |license|
+ raise Berkshelf::LicenseNotFound.new(license)
end
end
def license
ERB.new(File.read(File.join(self.class.source_root, license_file))).result(binding)