Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Make cosmetic changes in generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dtan4 committed Jan 10, 2017
1 parent 9f5a6de commit 4571fdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ Style/CollectionMethods:
inject: "inject"
detect: "find"
find_all: "select"

Style/PerlBackrefs:
Enabled: false
20 changes: 14 additions & 6 deletions script/generate
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ Example:
EOS

def camelize(string)
string.sub(/^[a-z\d]*/) { |match| match.capitalize }.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }.gsub('/'.freeze, '::'.freeze)
string
.sub(/^[a-z\d]*/) { |match| match.capitalize }
.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
.gsub('/'.freeze, '::'.freeze)
end

def generate_resource_erb(resource)
Expand All @@ -30,9 +33,14 @@ def generate_resource_spec_rb(resource)
end

def humanize(string)
string.sub(/\A_+/, ''.freeze).sub(/_id\z/, ''.freeze).tr('_'.freeze, ' '.freeze).gsub(/([a-z\d]*)/i) do |match|
match.downcase
end.split(" ").map{ |w| w[0].upcase + w[1..-1] }.join(" ")
string
.sub(/\A_+/, ''.freeze)
.sub(/_id\z/, ''.freeze)
.tr('_'.freeze, ' '.freeze)
.gsub(/([a-z\d]*)/i) { |match| match.downcase }
.split(" ")
.map { |w| w[0].upcase + w[1..-1] }
.join(" ")
end


Expand All @@ -50,7 +58,7 @@ File.open(File.join("lib", "terraforming", "resource", "#{resource}.rb"), "w+")

puts "==> Generate #{resource}_spec.rb"
resource_spec_rb = generate_resource_spec_rb(resource)
File.open(File.join("spec", "lib", "terraforming", "resource", "#{resource}_spec.rb"), "w+") { |f| f.write(resource_rb)}
File.open(File.join("spec", "lib", "terraforming", "resource", "#{resource}_spec.rb"), "w+") { |f| f.write(resource_rb) }

puts "==> Generate #{resource}.erb"
resource_erb = generate_resource_erb(resource)
Expand Down Expand Up @@ -81,7 +89,7 @@ spec/lib/terraforming/cli_spec.rb:
describe CLI do
context "resources" do
describe "#{resource}" do
let(:klass) { Terraforming::Resource::#{camelize(resource) }
let(:klass) { Terraforming::Resource::#{camelize(resource)} }
let(:command) { :#{resource} }
it_behaves_like "CLI examples"
Expand Down

0 comments on commit 4571fdb

Please sign in to comment.