Module: RSpec::Rails::Model
- Included in:
- Orm::Base
- Defined in:
- lib/rspec_for_generators/rails_helpers/rails_model.rb
Instance Method Summary collapse
- #create_model(name, &block) ⇒ Object
- #model_file_name(name) ⇒ Object
- #remove_model(name) ⇒ Object
- #remove_models(*names) ⇒ Object
Instance Method Details
#create_model(name, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 3 def create_model name, &block puts "create_model: #{name}" 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) yield f if block_given? end end end |
#model_file_name(name) ⇒ Object
25 26 27 |
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 25 def model_file_name name File.join(::Rails.root, "app/models/#{name}.rb") end |
#remove_model(name) ⇒ Object
16 17 18 19 |
# File 'lib/rspec_for_generators/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/rspec_for_generators/rails_helpers/rails_model.rb', line 21 def remove_models *names names.each{|name| remove_model name } end |