Sha256: e92c21bb1aa84c5548f80feba40d150cfc7fbb019709d53c45e1a3749ca92c67

Contents?: true

Size: 886 Bytes

Versions: 4

Compression:

Stored size: 886 Bytes

Contents

module RSpec::Rails
  module Observer   
    include RSpec::Rails::App
     
    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(observer_dir, "#{name}_observer.rb")
    end        
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
generator-spec-0.4.8 lib/generator_spec/rails_helpers/rails_observer.rb
generator-spec-0.4.7 lib/generator_spec/rails_helpers/rails_observer.rb
generator-spec-0.4.5 lib/generator_spec/rails_helpers/rails_observer.rb
generator-spec-0.4.4 lib/generator_spec/rails_helpers/rails_observer.rb