Class: TogoStanza::CLI::GenspecUpdater

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions, Thor::Shell
Defined in:
lib/togostanza/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



206
207
208
# File 'lib/togostanza/cli.rb', line 206

def self.source_root
  File.expand_path('../../../templates/stanza', __FILE__)
end

Instance Method Details

#check_existObject



210
211
212
213
214
215
216
217
218
219
# File 'lib/togostanza/cli.rb', line 210

def check_exist
  unless File.exist?("#{file_name}")
    say("This provider doesn't have #{file_name}")
    exit
  end
  unless File.exist?("#{file_name}/metadata.json")
    template 'metadata.json.erb', "#{file_name}/metadata.json"
    say("metadata.json has just made.")
  end
end

#replace_descriptionObject



221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/togostanza/cli.rb', line 221

def replace_description
  unless File.read("#{file_name}/#{file_name}.gemspec").include?("require\s'json'")
    insert_into_file("#{file_name}/#{file_name}.gemspec", "\nrequire\s'json'\n", :after=>"$LOAD_PATH.unshift(lib)\sunless\s$LOAD_PATH.include?(lib)\n")
    insert_into_file("#{file_name}/#{file_name}.gemspec", "metadata\s=\sopen('./metadata.json')\sdo\s|io|\n", :after=>"\nrequire\s'json'\n")
    insert_into_file("#{file_name}/#{file_name}.gemspec", "\s\sJSON.load\(io\)\nend\n", :after=>"metadata\s=\sopen('./metadata.json')\sdo\s|io|\n")
  end
  gsub_file("#{file_name}/#{file_name}.gemspec", /spec\.authors.*\n/, "spec.authors       = Array(metadata['author'])\n")
  gsub_file("#{file_name}/#{file_name}.gemspec", /spec\.email.*\n/, "spec.email         = Array(metadata['address'])\n")
  gsub_file("#{file_name}/#{file_name}.gemspec", /spec\.summary.*\n/, "spec.summary       = metadata['label']\n")
  gsub_file("#{file_name}/#{file_name}.gemspec", /spec\.description.*\n/, "spec.description   = metadata['definition']\n")
  gsub_file("#{file_name}/#{file_name}.gemspec", /spec\.license.*\n/, "spec.license       = metadata['license']\n")
end