Sha256: 169dd16887a85d2201ce2813964f181947c74a37c87b4c04cf83b58e421a6e07

Contents?: true

Size: 862 Bytes

Versions: 4

Compression:

Stored size: 862 Bytes

Contents

module RSpec::Rails
  module Observer    
    def create_observer name, content=nil
      file =  observer_file_name(name)
      unless File.exist?(file)    
        FileUtils.mkdir_p File.dirname(file)
        content ||= yield if block_given?
        File.open(file, 'w') do |f|  
          f.puts observer_content(name, content)
        end
      end
    end  

    def observer_content name, content=nil
      %Q{class #{name.to_s.camelize}Observer < ActiveRecord::Observer      
  #{content}
end}        
    end

    def remove_observer name
      file = observer_file_name(name)
      FileUtils.rm_f(file) if File.exist?(file)
    end

    def remove_observers *names
      names.each{|name| remove_observer name }
    end      
    
    def observer_file_name name
      File.join(::Rails.root, "app/models/#{name}_observer.rb")
    end        
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
generator-spec-0.4.3 lib/rspec_for_generators/rails_helpers/rails_observer.rb
generator-spec-0.4.2 lib/rspec_for_generators/rails_helpers/rails_observer.rb
generator-spec-0.4.1 lib/rspec_for_generators/rails_helpers/rails_observer.rb
generator-spec-0.4.0 lib/rspec_for_generators/rails_helpers/rails_observer.rb