Class: Chef::ChefFS::FileSystem::Repository::DataBagItem
- Inherits:
-
Object
- Object
- Chef::ChefFS::FileSystem::Repository::DataBagItem
- Defined in:
- lib/chef/chef_fs/file_system/repository/data_bag_item.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #can_have_child?(name, is_dir) ⇒ Boolean
- #compare_to(other) ⇒ Object
- #create(file_contents) ⇒ Object
- #delete(recurse) ⇒ Object
-
#dir? ⇒ Boolean
Public API callied by chef_fs/file_system.
- #exists? ⇒ Boolean
- #fs_entry_valid? ⇒ Boolean
-
#initialize(name, parent) ⇒ DataBagItem
constructor
A new instance of DataBagItem.
- #name_valid? ⇒ Boolean
- #path_for_printing ⇒ Object
- #read ⇒ Object
- #root ⇒ Object
- #write(content) ⇒ Object
- #write_pretty_json ⇒ Object
- #write_pretty_json=(value) ⇒ Object
Constructor Details
#initialize(name, parent) ⇒ DataBagItem
Returns a new instance of DataBagItem.
33 34 35 36 37 38 39 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 33 def initialize(name, parent) @parent = parent @name = name @path = Chef::ChefFS::PathUtils.join(parent.path, name) @data_handler = Chef::ChefFS::DataHandler::DataBagItemDataHandler.new @file_path = "#{parent.file_path}/#{name}" end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
31 32 33 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 31 def file_path @file_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 28 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
29 30 31 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 29 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 30 def path @path end |
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
62 63 64 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 62 def can_have_child?(name, is_dir) false end |
#compare_to(other) ⇒ Object
106 107 108 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 106 def compare_to(other) nil end |
#create(file_contents) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 54 def create(file_contents) if exists? raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self) else write(file_contents) end end |
#delete(recurse) ⇒ Object
78 79 80 81 82 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 78 def delete(recurse) File.delete(file_path) rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end |
#dir? ⇒ Boolean
Public API callied by chef_fs/file_system
42 43 44 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 42 def dir? false end |
#exists? ⇒ Boolean
84 85 86 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 84 def exists? File.exists?(file_path) end |
#fs_entry_valid? ⇒ Boolean
50 51 52 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 50 def fs_entry_valid? name_valid? && File.file?(file_path) end |
#name_valid? ⇒ Boolean
46 47 48 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 46 def name_valid? !name.start_with?(".") && name.end_with?(".json") end |
#path_for_printing ⇒ Object
74 75 76 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 74 def path_for_printing file_path end |
#read ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 88 def read begin File.open(file_path, "rb") { |f| f.read } rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end end |
#root ⇒ Object
102 103 104 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 102 def root parent.root end |
#write(content) ⇒ Object
96 97 98 99 100 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 96 def write(content) File.open(file_path, "wb") do |file| file.write(content) end end |
#write_pretty_json ⇒ Object
70 71 72 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 70 def write_pretty_json @write_pretty_json.nil? ? root.write_pretty_json : @write_pretty_json end |
#write_pretty_json=(value) ⇒ Object
66 67 68 |
# File 'lib/chef/chef_fs/file_system/repository/data_bag_item.rb', line 66 def write_pretty_json=(value) @write_pretty_json = value end |