Module: RailsAssist::Artifact::FileName

Includes:
Directory, Path
Included in:
RailsAssist::Artifact
Defined in:
lib/rails_artifactor/base/file_name.rb

Instance Method Summary collapse

Instance Method Details

#existing_file_name(name, type = nil, options = {}) ⇒ Object

Raises:

  • (IOError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_artifactor/base/file_name.rb', line 12

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

#make_file_name(name, type, options = {}) ⇒ Object



8
9
10
# File 'lib/rails_artifactor/base/file_name.rb', line 8

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