Sha256: 9c9e1271d76eb8d42f0839c1f8ad7746565b3fc68604214bbb5e4a65ae100d87

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

require 'rails3_assist/artifact'

module Rails3::Assist::Artifact
  module FileName         
    include Rails3::Assist::Artifact::Directory
    include Rails3::Assist::Artifact::Path

    def make_file_name name, type, options={}      
      send :"#{type}_file_name", name, options
    end

    def existing_file_name name, type=nil, options = {} 
      # first try finder method
      finder_method = :"find_#{type}"       
      if respond_to?(finder_method)          
        result = send finder_method, name, options 
        if !result.kind_of? String          
          raise IOError, "The call to #find_#{type}(#{name}) didn't find an existing #{type} file. Error in find expression: #{result.find_expr}" 
        end
        return result
      elsif type == :migration
        raise StandardError, "The method #find_#{type} to find the migration is not available!"
      end
      
      # default for non-migration
      file_name = make_file_name name, type, options
      raise IOError, "No file for :#{type} found at location: #{file_name}" if !File.file?(file_name)
      file_name
    end

    Rails3::Assist.artifacts.each do |name|
      class_eval %{
        def existing_#{name}_file name, type=nil, options = {}
          existing_file_name name, type, options
        end
      } 
    end
  end  # file_name
  
  include FileName
end    

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rails3_artifactor-0.4.0 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.3.2 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.3.1 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.3.0 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.8 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.7 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.6 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.5 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.4 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.3 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.2 lib/rails3_artifactor/base/file_name.rb
rails3_artifactor-0.2.1 lib/rails3_artifactor/base/file_name.rb