Module: RubyGallery::Generators::OrmHelpers

Included in:
ActiveRecord::Generators::RubyGalleryGenerator
Defined in:
lib/generators/ruby_gallery/orm_helpers.rb

Instance Method Summary collapse

Instance Method Details

#controller_exists?Boolean

Returns:



19
20
21
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 19

def controller_exists?
  File.exists?(File.join(destination_root, controller_path))
end

#controller_pathObject



39
40
41
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 39

def controller_path
  @controller_path ||= File.join("app", "controllers", "#{table_name}_controller.rb")
end

#migration_add_columns_exists?(table_name) ⇒ Boolean

Returns:



27
28
29
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 27

def migration_add_columns_exists?(table_name)
  Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_ruby_gallery_add_columns_to_#{table_name}.rb$/).first
end

#migration_exists?(table_name) ⇒ Boolean

Returns:



23
24
25
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 23

def migration_exists?(table_name)
  Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_ruby_gallery_create_#{table_name}.rb$/).first
end

#migration_pathObject



31
32
33
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 31

def migration_path
  @migration_path ||= File.join("db", "migrate")
end

#model_contentsObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 4

def model_contents
<<-CONTENT
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  # devise :database_authenticatable, :registerable,
  #          :recoverable, :rememberable, :trackable, :validatable
  #          
CONTENT
end

#model_exists?Boolean

Returns:



15
16
17
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 15

def model_exists?
  File.exists?(File.join(destination_root, model_path))
end

#model_pathObject



35
36
37
# File 'lib/generators/ruby_gallery/orm_helpers.rb', line 35

def model_path
  @model_path ||= File.join("app", "models", "#{file_path}.rb")
end