Class: Rake::Distribute::Item::FileItem

Inherits:
Base
  • Object
show all
Defined in:
lib/rake/distribute/item/file.rb

Direct Known Subclasses

ErbFile

Instance Method Summary collapse

Methods inherited from Base

#from, #to

Constructor Details

#initialize(&block) ⇒ FileItem

Returns a new instance of FileItem.



17
18
19
20
21
# File 'lib/rake/distribute/item/file.rb', line 17

def initialize(&block)
  @diff_proc = Proc.new { |dest,src| puts "#{dest} differs from #{src}"}
  @build_dir = File.join('build', 'distribute')
  super
end

Instance Method Details

#build(options = {}, &block) ⇒ Object



28
29
30
31
# File 'lib/rake/distribute/item/file.rb', line 28

def build(options = {}, &block)
  @build_options = options
  @build_proc = block if block_given?
end

#build_dir(folder) ⇒ Object



33
34
35
# File 'lib/rake/distribute/item/file.rb', line 33

def build_dir(folder)
  @build_dir = folder
end

#define_build_task(from) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rake/distribute/item/file.rb', line 149

def define_build_task(from)

  build_dest = get_build_dest

  build_dir = File.dirname(build_dest)
  directory build_dir
  file build_dest => [from, build_dir] do
    @build_proc.call(from, build_dest)
  end

  desc "distribute: build"
  task :build => build_dest

  desc "distribute: clean"
  task :clean do
    safe_unlink build_dest if File.exist?(build_dest)
  end

  desc "distribute: clobber"
  task :clobber => [:clean] do
    rmdir @build_dir if File.exist?(@build_dir)
  end

  build_dest
end

#define_diff_task(from) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/rake/distribute/item/file.rb', line 135

def define_diff_task(from)
  return unless defined? @dest

  desc "distribute: diff"
  task :diff do
    diffy = Diffy::Diff.new(
    @dest, from, :source => 'files', :allow_empty_diff => true
    ).to_s(:text)

    @diff_proc.call(@dest, @src) unless diffy.empty?
  end
end

#define_tasks(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rake/distribute/item/file.rb', line 46

def define_tasks(options={})
  if defined? @build_proc
    build_dest = define_build_task(@src)
  else
    build_dest = nil
  end

  if defined? @dest

    if build_dest

      if File.directory?(@dest)
        dest = File.join(@dest, File.basename(build_dest))
      else
        dest = @dest
      end

      dest_folder = File.dirname(dest)
      directory dest_folder

      file dest => [build_dest, dest_folder] do
        if File.directory?(build_dest)
          cp_r build_dest, @dest, @dest_options
        else
          install build_dest, @dest, @dest_options
        end
      end


      desc "distribute: install"
      task :install => dest


      define_diff_task(build_dest)

    else # without build ( install @src -> @dest )

      if File.directory?(@dest)
        dest_folder = @dest
      else
        dest_folder = @dest.pathmap("%d")
      end

      directory dest_folder

      file @dest => [@src, dest_folder] do
        if File.directory?(@dest)
          cp_r @src, @dest, @dest_options
        else
          install @src, @dest, @dest_options
        end
      end


      desc "distribute: install"
      task :install => @dest

      define_diff_task(@src)
    end

    desc "distribute: uninstall"
    task :uninstall do
      if File.directory?(@dest)
        uninstall_hint
      else
        safe_unlink @dest if File.exist?(@dest)
      end

      if defined? @uninstall_entries
        if @uninstall_entries.is_a?(String)
          if File.exist?(@uninstall_entries)
            puts "remove_entry_secure #{@uninstall_entries}"
            remove_entry_secure @uninstall_entries
          end
        elsif @uninstall_entries.is_a?(Array)
          @uninstall_entries.each { |e|
            if File.exist?(e)
              puts "remove_entry_secure #{e}"
              remove_entry_secure e
            end
          }
        end
      end
    end

  end
end

#diff(&block) ⇒ Object



41
42
43
# File 'lib/rake/distribute/item/file.rb', line 41

def diff(&block)
  @diff_proc = block if block_given?
end

#sanity?Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


23
24
25
26
# File 'lib/rake/distribute/item/file.rb', line 23

def sanity?
  super
  raise ArgumentError, "#{@src} does not exist!" unless File.exists?(@src)
end

#uninstall(entries) ⇒ Object



37
38
39
# File 'lib/rake/distribute/item/file.rb', line 37

def uninstall(entries)
  @uninstall_entries = entries
end