Class: CompassAeStarterKit::CompassAE

Inherits:
Object
  • Object
show all
Defined in:
lib/compass_ae_starter_kit/commands/compass_ae.rb

Class Method Summary collapse

Class Method Details



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/compass_ae_starter_kit/commands/compass_ae.rb', line 7

def banner
   %(
Usage:
  compass_ae new <app_name> [rails_opt]  Creates a new Rails Compass AE Application
    rails_opt:            all the options accepted by the rails command
  
  compass_ae dev <app_name> [rails_opt]  Creates a new Rails Compass AE Application and clones our repository and points the Compass AE gems to it
    rails_opt:            all the options accepted by the rails command
    
  compass_ae --help|-h    This help screen
   )
end

.runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/compass_ae_starter_kit/commands/compass_ae.rb', line 20

def run
  #Get rails version
  major, minor, tiny = `rails -v`.gsub!('Rails ', '').gsub!("\n",'').split('.').collect{|version| version.to_i}
  if version_allowed?(RAILS_MAJOR, major) and version_allowed?(RAILS_MINOR, minor) and version_allowed?(RAILS_TINY, tiny)
    template_path = File.join(File.dirname(__FILE__), '../templates/default_template.rb')
  
    if ARGV.first != "new" and ARGV.first != "dev"
      ARGV[0] = "--help"
    end
  
    if ARGV.first == "dev"
      template_path = File.join(File.dirname(__FILE__), '../templates/development_template.rb')
      ARGV[0] = "new"
    end

    command = ARGV.shift
    case command
    when '--help'
      puts self.banner
    when 'new'
      app_name = ARGV.shift
      raise "The application name is missing!" if app_name.nil?
      puts 'Generating Rails infrastructure...'
      system "rails new #{app_name} #{ARGV * ' '} -m #{template_path}"
      Dir.chdir app_name
      puts 'Installing CompassAE migrations and data migrations...'
      system "rake compass_ae:install:migrations"
      system "rake compass_ae:install:data_migrations"
      puts 'Migrating a fresh database...'
      system "rake db:migrate"
      system "rake db:migrate_data"
    end
  else
    puts "Installed Rails version is not compatible #{[major, minor, tiny].compact.join('.')}, please install #{[RAILS_MAJOR, RAILS_MINOR, RAILS_TINY].compact.join('.')}"
  end

end

.version_allowed?(allowed_version, version) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/compass_ae_starter_kit/commands/compass_ae.rb', line 58

def version_allowed?(allowed_version, version)
  result = true
  unless(allowed_version == '*')
    result = (allowed_version == version)
  end
  result
end