Class: Replicate
- Inherits:
-
Object
show all
- Defined in:
- lib/hobix/publish/replicate.rb
Constant Summary
collapse
- DIRFILE =
/^(.*\/)?([^\/]*)$/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash_src, hash_tgt) ⇒ Replicate
Returns a new instance of Replicate.
111
112
113
114
115
116
|
# File 'lib/hobix/publish/replicate.rb', line 111
def initialize(hash_src, hash_tgt)
@items = hash_src['items']
@source = hash_src['source']
@target = hash_tgt['path']
end
|
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
109
110
111
|
# File 'lib/hobix/publish/replicate.rb', line 109
def items
@items
end
|
#source ⇒ Object
Returns the value of attribute source.
109
110
111
|
# File 'lib/hobix/publish/replicate.rb', line 109
def source
@source
end
|
#target ⇒ Object
Returns the value of attribute target.
109
110
111
|
# File 'lib/hobix/publish/replicate.rb', line 109
def target
@target
end
|
Instance Method Details
#check_and_make_dirs ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/hobix/publish/replicate.rb', line 148
def check_and_make_dirs
dirs = get_dirs
dirs.each do |dir|
dir = File.join(target,dir)
if !directory?(dir)
mkdir_p(dir)
end
end
end
|
#copy(&block) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/hobix/publish/replicate.rb', line 181
def copy (&block)
if respond_to?(:login)
send :login
end
check_and_make_dirs
copy_files &block
if respond_to?(:logout)
send :logout
end
end
|
#copy_files(&block) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/hobix/publish/replicate.rb', line 162
def copy_files ( &block)
files = get_files
nb_files = files.size
files.each do |file|
src_f = File.join(source,file)
tgt_f = File.join(target,file)
if block_given?
yield nb_files,file, src_f, tgt_f
end
cp(src_f,tgt_f)
end
end
|
#get_dirs ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/hobix/publish/replicate.rb', line 121
def get_dirs
dirs = Array.new
dirfiles = items.collect do |itm|
dir,file = DIRFILE.match(itm).captures
if dir && dir.strip.size != 0
dirs.push dir
end
end
dirs
end
|
#get_files ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/hobix/publish/replicate.rb', line 135
def get_files
files = Array.new
dirfiles = items.collect do |itm|
dir,file = DIRFILE.match(itm).captures
if file && file.strip.size != 0
files.push itm
end
end
files
end
|