Module: Pushify::Install

Defined in:
lib/pushify/install.rb

Class Method Summary collapse

Class Method Details

.install!Object



5
6
7
# File 'lib/pushify/install.rb', line 5

def self.install!
  File.exist?(File.join(Dir.pwd, "Gemfile")) ? self.install_3! : self.install_2!
end

.install_2!Object



9
10
11
12
13
14
15
16
# File 'lib/pushify/install.rb', line 9

def self.install_2!
  return false if File.open('config/environments/development.rb', 'r').read.match(/\s*config\.gem\s+['"]pushify['"]/)
  
  File.open('config/environments/development.rb', 'a') do |f|
    f.write("\n\nconfig.gem 'pushify'\n")
  end
  true
end

.install_3!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pushify/install.rb', line 18

def self.install_3!
  return false if File.open('Gemfile', 'r').read.match(/\s*gem\s+['"]pushify['"]/)
  
  File.open('Gemfile', 'a') do |f|
    f.write("\n\ngroup :development do\n  gem 'pushify'\nend\n")
  end
  
  split_on = "Demo3::Application.configure do"
  parts = File.read('config/environments/development.rb').split(split_on)
  
  File.open('config/environments/development.rb', "w") do |f|
    f.puts parts.join(split_on + "\n\n  config.middleware.use Pushify::Rack")
  end
  true
end