Class: Puppet::FileBucket::File

Inherits:
Object
  • Object
show all
Extended by:
Indirector
Defined in:
lib/puppet/file_bucket/file.rb

Defined Under Namespace

Modules: IndirectionHooks

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

indirects

Constructor Details

#initialize(contents, options = {}) ⇒ File

Returns a new instance of File.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/puppet/file_bucket/file.rb', line 17

def initialize( contents, options = {} )
  raise ArgumentError if !contents.is_a?(String)
  @contents  = contents

  @bucket_path = options.delete(:bucket_path)
  raise ArgumentError if options != {}
end

Instance Attribute Details

#bucket_pathObject (readonly)

Returns the value of attribute bucket_path.



15
16
17
# File 'lib/puppet/file_bucket/file.rb', line 15

def bucket_path
  @bucket_path
end

#contentsObject (readonly)

Returns the value of attribute contents.



14
15
16
# File 'lib/puppet/file_bucket/file.rb', line 14

def contents
  @contents
end

Class Method Details

.from_pson(pson) ⇒ Object



53
54
55
# File 'lib/puppet/file_bucket/file.rb', line 53

def self.from_pson( pson )
  self.new( pson["contents"] )
end

.from_s(contents) ⇒ Object



45
46
47
# File 'lib/puppet/file_bucket/file.rb', line 45

def self.from_s( contents )
  self.new( contents )
end

Instance Method Details

#checksumObject



29
30
31
# File 'lib/puppet/file_bucket/file.rb', line 29

def checksum
  "{#{checksum_type}}#{checksum_data}"
end

#checksum_dataObject



33
34
35
# File 'lib/puppet/file_bucket/file.rb', line 33

def checksum_data
  @checksum_data ||= Digest::MD5.hexdigest(contents)
end

#checksum_typeObject



25
26
27
# File 'lib/puppet/file_bucket/file.rb', line 25

def checksum_type
  'md5'
end

#nameObject



41
42
43
# File 'lib/puppet/file_bucket/file.rb', line 41

def name
  "#{checksum_type}/#{checksum_data}"
end

#to_psonObject



49
50
51
# File 'lib/puppet/file_bucket/file.rb', line 49

def to_pson
  { "contents" => contents }.to_pson
end

#to_sObject



37
38
39
# File 'lib/puppet/file_bucket/file.rb', line 37

def to_s
  contents
end