Module: RSpec::Rails::Model

Includes:
App
Included in:
Orm::Base
Defined in:
lib/generator_spec/rails_helpers/rails_model.rb

Instance Method Summary collapse

Methods included from App

#all_files, #app_dir, #app_files, #config_dir, #controller_dir, #controller_files, #css_files, #db_dir, #db_files, #helper_dir, #helper_files, #initializer_dir, #initializer_files, #javascript_dir, #javascript_files, #locale_dir, #locale_files, #mailer_dir, #mailer_files, #migration_dir, #migration_files, #model_dir, #model_files, #observer_dir, #observer_files, #root_dir, #sass_files, #stylesheet_dir, #view_dir, #view_files, #view_files_haml, #view_files_html

Instance Method Details

#create_model(name, type = nil, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/generator_spec/rails_helpers/rails_model.rb', line 5

def create_model name, type=nil, &block      
  file = model_file_name(name)
  unless File.exist?(file)    
    FileUtils.mkdir_p File.dirname(file)
    File.open(file, 'w') do |f|  
      f.puts file_content(name, type)
      yield f if block_given?
    end
  end
end

#model_file_name(name) ⇒ Object



25
26
27
# File 'lib/generator_spec/rails_helpers/rails_model.rb', line 25

def model_file_name name
  File.join(model_dir, "#{name}.rb")
end

#remove_model(name) ⇒ Object



16
17
18
19
# File 'lib/generator_spec/rails_helpers/rails_model.rb', line 16

def remove_model name
  file = model_file_name(name)
  FileUtils.rm_f(file) if File.exist?(file)
end

#remove_models(*names) ⇒ Object



21
22
23
# File 'lib/generator_spec/rails_helpers/rails_model.rb', line 21

def remove_models *names
  names.each{|name| remove_model name }
end