Module: RailsBase::Commands

Extended by:
CliActions
Defined in:
lib/rs-rails-base/commands.rb

Overview

This module provides commands implementation

Class Method Summary collapse

Methods included from CliActions

ask_for_something, say_something

Class Method Details

.add_feature(feature) ⇒ Object



23
24
25
26
27
28
29
# 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) ⇒ Object



64
65
66
67
# 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_menuObject



74
75
76
77
78
79
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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_tagsObject



54
55
56
57
58
59
60
61
62
# 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_projectObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



69
70
71
72
# 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