Class: Orca::FileSync
- Inherits:
-
Object
- Object
- Orca::FileSync
- Defined in:
- lib/orca/extensions/file_sync.rb
Instance Method Summary collapse
- #add_content_package ⇒ Object
- #add_package(suffix) {|package| ... } ⇒ Object
- #add_permissions_package ⇒ Object
- #configure ⇒ Object
- #create_dir ⇒ Object
- #group ⇒ Object
-
#initialize(parent, config, &blk) ⇒ FileSync
constructor
A new instance of FileSync.
- #local_path ⇒ Object
- #package_name(suffix) ⇒ Object
- #permissions ⇒ Object
- #remote_path ⇒ Object
- #run_after_apply(context) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(parent, config, &blk) ⇒ FileSync
Returns a new instance of FileSync.
10 11 12 13 14 15 16 |
# File 'lib/orca/extensions/file_sync.rb', line 10 def initialize(parent, config, &blk) @parent = parent @config = config @after_apply = blk raise ArgumentError.new('A file :source must be provided') unless local_path raise ArgumentError.new('A file :destination must be provided') unless remote_path end |
Instance Method Details
#add_content_package ⇒ Object
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 |
# File 'lib/orca/extensions/file_sync.rb', line 56 def add_content_package fs = self add_package('content') do |package| package.command :apply do if fs.create_dir mk_dir = fs.create_dir == true ? File.dirname(fs.remote_path) : fs.create_dir sudo("mkdir -p #{mk_dir}") sudo("chown #{fs.user}:#{fs.group || fs.user} #{mk_dir}") if fs.user end local_file = local(fs.local_path) tmp_path = "orca-upload-#{local_file.hash}" local_file.copy_to(remote(tmp_path)) sudo("mv #{tmp_path} #{fs.remote_path}") fs.run_after_apply(self) end package.command :remove do remote(fs.remote_path).delete! end package.command :validate do local(fs.local_path).matches?(remote(fs.remote_path)) end end end |
#add_package(suffix) {|package| ... } ⇒ Object
101 102 103 104 105 106 |
# File 'lib/orca/extensions/file_sync.rb', line 101 def add_package(suffix) package = Orca.add_package(package_name(suffix)) yield(package) @parent.triggers(package.name) package end |
#add_permissions_package ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/orca/extensions/file_sync.rb', line 82 def fs = self add_package('permissions') do |package| package.command :apply do remote(fs.remote_path).set_owner(fs.user, fs.group) unless fs.user.nil? and fs.group.nil? remote(fs.remote_path).(fs.) unless fs..nil? fs.run_after_apply(self) end package.command :validate do r_file = remote(fs.remote_path) valid = r_file. == fs. valid = valid && r_file.user == fs.user if fs.user valid = valid && r_file.group == fs.group if fs.group valid end end end |
#configure ⇒ Object
46 47 48 49 50 |
# File 'lib/orca/extensions/file_sync.rb', line 46 def configure fs = self add_content_package unless .nil? and user.nil? and group.nil? end |
#create_dir ⇒ Object
38 39 40 |
# File 'lib/orca/extensions/file_sync.rb', line 38 def create_dir @config[:create_dir] || @config[:create_dirs] end |
#group ⇒ Object
34 35 36 |
# File 'lib/orca/extensions/file_sync.rb', line 34 def group @config[:group] end |
#local_path ⇒ Object
18 19 20 |
# File 'lib/orca/extensions/file_sync.rb', line 18 def local_path @config[:source] end |
#package_name(suffix) ⇒ Object
42 43 44 |
# File 'lib/orca/extensions/file_sync.rb', line 42 def package_name(suffix) "file-#{suffix}[#{remote_path}]" end |
#permissions ⇒ Object
26 27 28 |
# File 'lib/orca/extensions/file_sync.rb', line 26 def @config[:permissions] end |
#remote_path ⇒ Object
22 23 24 |
# File 'lib/orca/extensions/file_sync.rb', line 22 def remote_path @config[:destination] end |
#run_after_apply(context) ⇒ Object
52 53 54 |
# File 'lib/orca/extensions/file_sync.rb', line 52 def run_after_apply(context) context.instance_eval(&@after_apply) end |
#user ⇒ Object
30 31 32 |
# File 'lib/orca/extensions/file_sync.rb', line 30 def user @config[:user] end |