Class: Cult::Artifact

Inherits:
Object
  • Object
show all
Includes:
SingletonInstances, Transferable
Defined in:
lib/cult/artifact.rb

Overview

I’d love to just call this “File”, but the ambiguity with ::File would make it a pain.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SingletonInstances

included

Methods included from Transferable

#binary?, #collection_name, #contents, #file_mode, included, #name, #remote_path, #role_relative_path

Constructor Details

#initialize(role, path) ⇒ Artifact

Returns a new instance of Artifact.



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

def initialize(role, path)
  @role = role
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/cult/artifact.rb', line 21

def path
  @path
end

#roleObject (readonly)

Returns the value of attribute role.



22
23
24
# File 'lib/cult/artifact.rb', line 22

def role
  @role
end

Class Method Details

.all_for_role(project, role) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/cult/artifact.rb', line 36

def self.all_for_role(project, role)
  Dir.glob(File.join(role.path, "files", "**/*")).map do |filename|
    next if File.directory?(filename)
    new(role, filename).tap do |new_file|
      yield new_file if block_given?
    end
  end.compact.to_named_array
end

.collection_nameObject



11
12
13
# File 'lib/cult/artifact.rb', line 11

def self.collection_name
  "files"
end

Instance Method Details

#inspectObject Also known as: to_s



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

def inspect
  "\#<#{self.class.name} role:#{role&.name.inspect} name:#{name.inspect}>"
end

#relative_pathObject



16
17
18
# File 'lib/cult/artifact.rb', line 16

def relative_path
  name
end