Class: StoreAgent::Node::FileObject
- Defined in:
- lib/store_agent/node/object/file_object.rb
Overview
ファイル
Instance Attribute Summary collapse
-
#body ⇒ Object
writeonly
Sets the attribute body.
Attributes inherited from Object
Instance Method Summary collapse
-
#children ⇒ Object
:nodoc:.
- #chown ⇒ Object
- #copy(dest_path = nil) ⇒ Object
- #create(*params, &block) ⇒ Object
- #delete ⇒ Object
-
#directory(_) ⇒ Object
:nodoc:.
-
#file(_) ⇒ Object
:nodoc:.
-
#file? ⇒ Boolean
:nodoc:.
-
#find_object(_) ⇒ Object
:nodoc:.
-
#get_metadata ⇒ Object
:nodoc:.
-
#get_permissions ⇒ Object
:nodoc:.
- #move(dest_path = nil) ⇒ Object
- #read(revision: nil) ⇒ Object
- #save ⇒ Object
- #set_permission ⇒ Object
- #touch ⇒ Object
- #unset_permission ⇒ Object
- #update(*params, &block) ⇒ Object
Methods inherited from Object
#default_metadata, #directory?, #exists?, #filetype, #initial_metadata, #initial_owner, #initial_owner=, #initial_permission, #initial_permission=, #initialize, #metadata, #parent_directory, #permission, #revisions, #root?, #storage_object_path
Methods included from Validator
#validates_to_be_excluded_slash!, #validates_to_be_not_guest_identifier!, #validates_to_be_not_nil_value!, #validates_to_be_not_superuser_identifier!, #validates_to_be_string_or_symbol!
Constructor Details
This class inherits a constructor from StoreAgent::Node::Object
Instance Attribute Details
#body=(value) ⇒ Object (writeonly)
Sets the attribute body
21 22 23 |
# File 'lib/store_agent/node/object/file_object.rb', line 21 def body=(value) @body = value end |
Instance Method Details
#children ⇒ Object
:nodoc:
154 155 156 |
# File 'lib/store_agent/node/object/file_object.rb', line 154 def children # :nodoc: [] end |
#chown ⇒ Object
118 119 120 121 |
# File 'lib/store_agent/node/object/file_object.rb', line 118 def chown(*) super do end end |
#copy(dest_path = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/store_agent/node/object/file_object.rb', line 73 def copy(dest_path = nil, *) super do file_body = read dest_file = build_dest_file(dest_path) if dest_file.exists? dest_file.update(file_body) else dest_file.create(read) end end end |
#create(*params, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/store_agent/node/object/file_object.rb', line 23 def create(*params, &block) super do set_body(*params, &block) save workspace.version_manager.add(storage_object_path) end end |
#delete ⇒ Object
59 60 61 62 63 64 |
# File 'lib/store_agent/node/object/file_object.rb', line 59 def delete(*) super do FileUtils.rm(storage_object_path) workspace.version_manager.remove(storage_object_path) end end |
#directory(_) ⇒ Object
:nodoc:
137 138 139 |
# File 'lib/store_agent/node/object/file_object.rb', line 137 def directory(_) # :nodoc: raise "#{@path} is not directory" end |
#file(_) ⇒ Object
:nodoc:
141 142 143 |
# File 'lib/store_agent/node/object/file_object.rb', line 141 def file(_) # :nodoc: raise "#{@path} is not directory" end |
#file? ⇒ Boolean
:nodoc:
158 159 160 |
# File 'lib/store_agent/node/object/file_object.rb', line 158 def file? # :nodoc: true end |
#find_object(_) ⇒ Object
:nodoc:
133 134 135 |
# File 'lib/store_agent/node/object/file_object.rb', line 133 def find_object(_) # :nodoc: raise "#{@path} is not directory" end |
#get_metadata ⇒ Object
:nodoc:
108 109 110 111 |
# File 'lib/store_agent/node/object/file_object.rb', line 108 def (*) # :nodoc: super do end end |
#get_permissions ⇒ Object
:nodoc:
113 114 115 116 |
# File 'lib/store_agent/node/object/file_object.rb', line 113 def (*) # :nodoc: super do end end |
#move(dest_path = nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/store_agent/node/object/file_object.rb', line 85 def move(dest_path = nil, *) super do dest_file = build_dest_file(dest_path) if dest_file.exists? disk_usage_diff = .disk_usage - dest_file..disk_usage file_count = 0 else disk_usage_diff = .disk_usage file_count = 1 end FileUtils.mv(storage_object_path, dest_file.storage_object_path) FileUtils.mv(.file_path, dest_file..file_path) FileUtils.mv(.file_path, dest_file..file_path) dest_file.touch dest_file.parent_directory..update(disk_usage: disk_usage_diff, directory_file_count: file_count, tree_file_count: file_count, recursive: true) parent_directory..update(disk_usage: -dest_file..disk_usage, directory_file_count: -1, tree_file_count: -1, recursive: true) [storage_object_path, .file_path, .file_path].each do |file_path| workspace.version_manager.remove(file_path) end end end |
#read(revision: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/store_agent/node/object/file_object.rb', line 31 def read(revision: nil) super do if revision.nil? encoded_data = open(storage_object_path) do |f| f.read end else encoded_data = workspace.version_manager.read(path: storage_object_path, revision: revision) end StoreAgent.config..reverse.inject(encoded_data) do |data, encoder| encoder.decode(data) end end end |
#save ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/store_agent/node/object/file_object.rb', line 145 def save encoded_data = StoreAgent.config.storage_data_encoders.inject(@body) do |data, encoder| encoder.encode(data) end open(storage_object_path, "w") do |f| f.write encoded_data end end |
#set_permission ⇒ Object
123 124 125 126 |
# File 'lib/store_agent/node/object/file_object.rb', line 123 def (*) super do end end |
#touch ⇒ Object
66 67 68 69 70 71 |
# File 'lib/store_agent/node/object/file_object.rb', line 66 def touch(*) super do FileUtils.touch(storage_object_path) workspace.version_manager.add(storage_object_path) end end |
#unset_permission ⇒ Object
128 129 130 131 |
# File 'lib/store_agent/node/object/file_object.rb', line 128 def (*) super do end end |
#update(*params, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/store_agent/node/object/file_object.rb', line 46 def update(*params, &block) super do set_body(*params, &block) if @body.nil? raise "file body required" end save disk_usage_diff = @body.length - .disk_usage .update(disk_usage: disk_usage_diff, recursive: true) workspace.version_manager.add(storage_object_path) end end |