module RailsBase::Commands

This module provides commands implementation

Public Class Methods

add_feature(feature) click to toggle source
# File lib/rs-rails-base/commands.rb, line 23
def self.add_feature(feature)
  if feature.nil?
    display_menu
  else
    feature_case(feature)
  end
end
clone_project(version, uri, to_folder) click to toggle source
# File lib/rs-rails-base/commands.rb, line 64
def self.clone_project(version, uri, to_folder)
  command = "git clone -b #{version.strip!} --depth 1 #{uri} #{to_folder} &> /dev/null 2>&1"
  system(command)
end
display_menu() click to toggle source
# File lib/rs-rails-base/commands.rb, line 74
def self.display_menu
  say_something('FEATURE OPTIONS:')
  RailsBase::FEATURE_OPTIONS.merge(all: 'All').each_value do |feature|
    say_something(" #{feature}")
  end
end
feature_case(feature) click to toggle source
# File lib/rs-rails-base/commands.rb, line 31
def self.feature_case(feature)
  case feature
  when FEATURE_OPTIONS[:facebook]
    RailsBase::Features.facebook
    puts 'Mark is happy'
  when FEATURE_OPTIONS[:twilio]
    RailsBase::Features.twilio
    puts 'now start messaging'
  when FEATURE_OPTIONS[:chat]
    RailsBase::Features.chat
    puts 'now go and start talking'
  when 'all', 'All'
    FEATURE_OPTIONS.each do |k, v|
      puts "Installing #{v}"
      RailsBase::Features.send(k)
      puts "Feature #{v} installed"
    end
    puts 'All set'
  else
    puts 'Please select a valid option'
  end
end
manage_tags() click to toggle source
# File lib/rs-rails-base/commands.rb, line 54
def self.manage_tags
  filters = "awk '{print $2}'| cut -d '/' -f 3 | cut -d '^' -f 1 | uniq"
  tags = "git ls-remote -t #{RailsBase::REMOTE_URI} | #{filters}"
  reference_tag = RailsBase::API_BASE_VERSION
  tag_numbers = reference_tag.split('.')
  major = tag_numbers[0]
  minor = tag_numbers[1]
  `#{tags} | grep '#{major}.#{minor}.[0-9]' | tail -n 1 `
end
new_project() click to toggle source
# File lib/rs-rails-base/commands.rb, line 8
def self.new_project
  say_something('Getting ready to get an amazing project')
  answer = RailsBase::CliActions.ask_for_something('What would be the name for project folder?')
  if Dir.exist?(answer)
    say_something('Please dont use same project again and again')
  else
    final_version = manage_tags
    RailsBase::GitActions.fetch_from_remote(final_version)
    clone_project(final_version, RailsBase::REMOTE_URI, answer)
    remove_git_configuration(answer)
  end
  FileUtils.cd("#{Dir.pwd}/#{answer}")
  say_something('Download complete')
end
remove_git_configuration(project_folder) click to toggle source
# File lib/rs-rails-base/commands.rb, line 69
def self.remove_git_configuration(project_folder)
  git_config = project_folder + '/.git'
  FileUtils.rm_rf(git_config)
end