Module: Rails3::Assist::File::Special::Methods

Included in:
Rails3::Assist::File::Special, Rails3::Assist::File::Special
Defined in:
lib/rails3_assist/file/special.rb

Instance Method Summary collapse

Instance Method Details

#clean_gemfileObject



35
36
37
38
# File 'lib/rails3_assist/file/special.rb', line 35

def clean_gemfile
  clean_gemfile_content = read_gem_file.gsub(/('|"|end)\s*gem/m, "\\1\ngem")
  File.open(gem_file, 'w') {|f| f.write(clean_gemfile_content) }
end

#database_fileObject



15
16
17
# File 'lib/rails3_assist/file/special.rb', line 15

def database_file
  File.join(Rails3::Assist::Directory.config_dir, 'database.yml')
end

#gem_fileObject



23
24
25
# File 'lib/rails3_assist/file/special.rb', line 23

def gem_file
  File.join(Rails3::Assist::Directory.root_dir, 'Gemfile')
end

#has_gem?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rails3_assist/file/special.rb', line 27

def has_gem? name
  File.new(gem_file).read =~ /gem\s+('|")#{name}\1/
end

#has_gem_version?(name, version = nil) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rails3_assist/file/special.rb', line 31

def has_gem_version? name, version = nil
  File.new(gem_file).read =~ /gem\s+('|")#{name}\1,\s*('|")#{version}\2/
end

#insert_into_routes(route_stmt = nil, &block) ⇒ Object



40
41
42
43
# File 'lib/rails3_assist/file/special.rb', line 40

def insert_into_routes route_stmt=nil, &block
  statement = block ? yield : route_stmt
  File.insert_into routes_file, statement, :after => 'Application.routes.draw do'
end

#seed_fileObject



19
20
21
# File 'lib/rails3_assist/file/special.rb', line 19

def seed_file
  File.join(Rails3::Assist::Directory.db_dir, 'seeds.rb')
end