Module: Cult::Transferable
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #binary? ⇒ Boolean
- #collection_name ⇒ Object
- #contents(project, role, node, pwd: nil) ⇒ Object
- #file_mode ⇒ Object
- #name ⇒ Object
- #remote_path ⇒ Object
- #role_relative_path ⇒ Object
Class Method Details
.included(cls) ⇒ Object
10 11 12 |
# File 'lib/cult/transferable.rb', line 10 def self.included(cls) cls.extend(ClassMethods) end |
Instance Method Details
#binary? ⇒ Boolean
30 31 32 |
# File 'lib/cult/transferable.rb', line 30 def binary? !! File.read(path, 512).match(/[\x00-\x08]/) end |
#collection_name ⇒ Object
15 16 17 |
# File 'lib/cult/transferable.rb', line 15 def collection_name self.class.collection_name end |
#contents(project, role, node, pwd: nil) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/cult/transferable.rb', line 35 def contents(project, role, node, pwd: nil) if binary? File.read(path) else erb = Template.new(project: project, pwd: pwd, role: role, node: node) erb.process(File.read(path), filename: path) end end |
#file_mode ⇒ Object
53 54 55 |
# File 'lib/cult/transferable.rb', line 53 def file_mode File.stat(path).mode & 0777 end |
#name ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cult/transferable.rb', line 45 def name prefix = File.join(role.path, collection_name) + "/" if path.start_with?(prefix) path[prefix.size .. -1] end end |
#remote_path ⇒ Object
20 21 22 |
# File 'lib/cult/transferable.rb', line 20 def remote_path File.join(role.remote_path, role_relative_path) end |
#role_relative_path ⇒ Object
25 26 27 |
# File 'lib/cult/transferable.rb', line 25 def role_relative_path File.join(collection_name, relative_path) end |