Class: Calatrava::OutputFile

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/calatrava/output_file.rb

Constant Summary collapse

@@rules =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rake::DSL

#transient

Constructor Details

#initialize(output_dir, source_file, dependencies = []) ⇒ OutputFile

Returns a new instance of OutputFile.



29
30
31
32
33
34
35
# File 'lib/calatrava/output_file.rb', line 29

def initialize(output_dir, source_file, dependencies = [])
  @output_dir = Pathname.new(output_dir)
  @source_file = Pathname.new(source_file)

  @dependencies = [@source_file.to_s, @output_dir.to_s]
  @dependencies += dependencies if dependencies
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



27
28
29
# File 'lib/calatrava/output_file.rb', line 27

def dependencies
  @dependencies
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



27
28
29
# File 'lib/calatrava/output_file.rb', line 27

def source_file
  @source_file
end

Class Method Details

.action(file_name) ⇒ Object



18
19
20
# File 'lib/calatrava/output_file.rb', line 18

def self.action(file_name)
  rule_for(file_name.extname)[:action]
end

.rule(opts, &action) ⇒ Object



8
9
10
11
# File 'lib/calatrava/output_file.rb', line 8

def self.rule(opts, &action)
  start_ext = opts.keys[0]
  @@rules[start_ext] = {:target => opts[start_ext], :action => action}
end

.rule_for(ext) ⇒ Object



22
23
24
# File 'lib/calatrava/output_file.rb', line 22

def self.rule_for(ext)
  @@rules[ext]
end

.target_file(file_name) ⇒ Object



13
14
15
16
# File 'lib/calatrava/output_file.rb', line 13

def self.target_file(file_name)
  start_ext = file_name.extname
  Pathname.new(file_name.basename(start_ext).to_s + rule_for(start_ext)[:target])
end

Instance Method Details

#output_pathObject Also known as: to_s



37
38
39
# File 'lib/calatrava/output_file.rb', line 37

def output_path
  (@output_dir + OutputFile.target_file(@source_file)).to_s
end

#to_taskObject



42
43
44
45
46
# File 'lib/calatrava/output_file.rb', line 42

def to_task
  file(output_path => @dependencies) do
    OutputFile.action(@source_file).call(output_path.to_s, @source_file.to_s)
  end
end