Class: Kubert::FileAccess
- Inherits:
-
Object
- Object
- Kubert::FileAccess
- Defined in:
- lib/kubert/file_access.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #clean_local ⇒ Object
- #found ⇒ Object
- #get ⇒ Object
-
#initialize(type, key = nil) ⇒ FileAccess
constructor
A new instance of FileAccess.
- #local? ⇒ Boolean
- #read ⇒ Object
- #set(value) ⇒ Object
- #write ⇒ Object
- #write_local ⇒ Object
Constructor Details
#initialize(type, key = nil) ⇒ FileAccess
Returns a new instance of FileAccess.
4 5 6 7 8 9 10 |
# File 'lib/kubert/file_access.rb', line 4 def initialize(type, key = nil) @type = type @key = key @s3_path = Kubert.public_send("s3_#{type}_path") @file_name = Kubert.public_send("#{type}_file_name") @data = read end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/kubert/file_access.rb', line 3 def data @data end |
Instance Method Details
#clean_local ⇒ Object
46 47 48 |
# File 'lib/kubert/file_access.rb', line 46 def clean_local File.delete(local_path) unless local? end |
#found ⇒ Object
12 13 14 |
# File 'lib/kubert/file_access.rb', line 12 def found data[:data].select {|k, _v| k == key } end |
#get ⇒ Object
29 30 31 |
# File 'lib/kubert/file_access.rb', line 29 def get data[:data][key] end |
#local? ⇒ Boolean
33 34 35 |
# File 'lib/kubert/file_access.rb', line 33 def local? !s3_path end |
#read ⇒ Object
16 17 18 |
# File 'lib/kubert/file_access.rb', line 16 def read YAML.load(file_read).with_indifferent_access end |
#set(value) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/kubert/file_access.rb', line 20 def set(value) if value.nil? data[:data].delete(key) else data[:data][key] = value end self end |
#write ⇒ Object
37 38 39 40 |
# File 'lib/kubert/file_access.rb', line 37 def write return write_local if local? s3_object.put(body: data.to_plain_yaml, content_encoding: 'application/octet-stream', content_type: "text/vnd.yaml", metadata: {author: `whoami`}) end |
#write_local ⇒ Object
42 43 44 |
# File 'lib/kubert/file_access.rb', line 42 def write_local File.write(local_path, data.to_plain_yaml) end |