Class: Take::Project::File

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/take/project/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ File

Returns a new instance of File.



20
21
22
# File 'lib/take/project/file.rb', line 20

def initialize(name)
  @name = name
end

Class Method Details

.normalize(file, path) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
# File 'lib/take/project/file.rb', line 9

def self.normalize(file, path)
  expanded = ::File.expand_path(file, path)
  raise ArgumentError, "The given file cannot be placed in " \
    "the project: #{file.inspect}" \
    unless expanded.start_with?(path.to_s)
  name = Pathname.new(expanded)
  name.relative_path_from(path)
end

Instance Method Details

#sub_ext(ext) ⇒ Object



42
43
44
# File 'lib/take/project/file.rb', line 42

def sub_ext(ext)
  File.new(@name.sub_ext(ext))
end

#typeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/take/project/file.rb', line 24

def type
  @_type ||= begin
    case @name.extname
    when ".ta"
      :library
    when ".to", ".o"
      :object
    when ".c"
      :source
    when ""
      :executable
    else
      :unknown
    end
  end
end