Class: Replicate
- Inherits:
-
Object
- Object
- Replicate
- Defined in:
- lib/hobix/publish/replicate.rb
Direct Known Subclasses
Constant Summary collapse
- DIRFILE =
/^(.*\/)?([^\/]*)$/
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #check_and_make_dirs ⇒ Object
- #copy(&block) ⇒ Object
- #copy_files(&block) ⇒ Object
- #get_dirs ⇒ Object
- #get_files ⇒ Object
-
#initialize(hash_src, hash_tgt) ⇒ Replicate
constructor
A new instance of Replicate.
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| # Check existence and create if not present dir = File.join(target,dir) if !directory?(dir) # Let's create it ! 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 |