Module: Cult::Transferable

Included in:
Artifact, Task
Defined in:
lib/cult/transferable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/cult/transferable.rb', line 30

def binary?
  !! File.read(path, 512).match(/[\x00-\x08]/)
end

#collection_nameObject



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_modeObject



53
54
55
# File 'lib/cult/transferable.rb', line 53

def file_mode
  File.stat(path).mode & 0777
end

#nameObject



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_pathObject



20
21
22
# File 'lib/cult/transferable.rb', line 20

def remote_path
  File.join(role.remote_path, role_relative_path)
end

#role_relative_pathObject



25
26
27
# File 'lib/cult/transferable.rb', line 25

def role_relative_path
  File.join(collection_name, relative_path)
end