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
- #local_path_for_node(node) ⇒ Object
- #package_name(suffix) ⇒ Object
- #permissions ⇒ Object
- #remote_path ⇒ Object
- #run_after_apply(context) ⇒ Object
- #template_path ⇒ 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 or template must be provided') unless local_path or template_path raise ArgumentError.new('A file :destination must be provided') unless remote_path end |
Instance Method Details
#add_content_package ⇒ Object
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 |
# File 'lib/orca/extensions/file_sync.rb', line 65 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_for_node(node)) 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_for_node(node)).matches?(remote(fs.remote_path)) end end end |
#add_package(suffix) {|package| ... } ⇒ Object
110 111 112 113 114 115 |
# File 'lib/orca/extensions/file_sync.rb', line 110 def add_package(suffix) package = Orca.add_package(package_name(suffix)) yield(package) @parent.triggers(package.name) package end |
#add_permissions_package ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/orca/extensions/file_sync.rb', line 91 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
55 56 57 58 59 |
# File 'lib/orca/extensions/file_sync.rb', line 55 def configure fs = self add_content_package unless .nil? and user.nil? and group.nil? end |
#create_dir ⇒ Object
47 48 49 |
# File 'lib/orca/extensions/file_sync.rb', line 47 def create_dir @config[:create_dir] || @config[:create_dirs] end |
#group ⇒ Object
43 44 45 |
# File 'lib/orca/extensions/file_sync.rb', line 43 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 |
#local_path_for_node(node) ⇒ Object
26 27 28 29 |
# File 'lib/orca/extensions/file_sync.rb', line 26 def local_path_for_node(node) return local_path if local_path Orca::Template.new(node, template_path).render_to_tempfile end |
#package_name(suffix) ⇒ Object
51 52 53 |
# File 'lib/orca/extensions/file_sync.rb', line 51 def package_name(suffix) "file-#{suffix}[#{remote_path}]" end |
#permissions ⇒ Object
35 36 37 |
# File 'lib/orca/extensions/file_sync.rb', line 35 def @config[:permissions] end |
#remote_path ⇒ Object
31 32 33 |
# File 'lib/orca/extensions/file_sync.rb', line 31 def remote_path @config[:destination] end |
#run_after_apply(context) ⇒ Object
61 62 63 |
# File 'lib/orca/extensions/file_sync.rb', line 61 def run_after_apply(context) context.instance_eval(&@after_apply) if @after_apply end |
#template_path ⇒ Object
22 23 24 |
# File 'lib/orca/extensions/file_sync.rb', line 22 def template_path @config[:template] end |
#user ⇒ Object
39 40 41 |
# File 'lib/orca/extensions/file_sync.rb', line 39 def user @config[:user] end |