Class: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemEntry
- Inherits:
-
FileSystemEntry
show all
- Defined in:
- lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb
Overview
ChefRepositoryFileSystemEntry works just like FileSystemEntry, except can inflate Chef objects
Instance Attribute Summary
#file_path
Attributes inherited from BaseFSObject
#name, #parent, #path
Instance Method Summary
collapse
#children, #create_child, #delete, #dir?, #exists?, #path_for_printing, #read
Methods inherited from BaseFSDir
#dir?, #empty?
#child, #children, #compare_to, #create_child, #delete, #dir?, #exists?, #path_for_printing, #read, #root
Constructor Details
#initialize(name, parent, file_path = nil, data_handler = nil) ⇒ ChefRepositoryFileSystemEntry
Returns a new instance of ChefRepositoryFileSystemEntry.
30
31
32
33
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 30
def initialize(name, parent, file_path = nil, data_handler = nil)
super(name, parent, file_path)
@data_handler = data_handler
end
|
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
56
57
58
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 56
def can_have_child?(name, is_dir)
!is_dir && name[-5..-1] == ".json"
end
|
#chef_object ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 47
def chef_object
begin
return data_handler.chef_object(Chef::JSONCompat.parse(read))
rescue
Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}")
end
nil
end
|
#data_handler ⇒ Object
43
44
45
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 43
def data_handler
@data_handler || parent.data_handler
end
|
#minimize(file_contents, entry) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 67
def minimize(file_contents, entry)
object = Chef::JSONCompat.parse(file_contents)
object = data_handler.normalize(object, entry)
object = data_handler.minimize(object, entry)
Chef::JSONCompat.to_json_pretty(object)
end
|
#write(file_contents) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 60
def write(file_contents)
if file_contents && write_pretty_json && name[-5..-1] == ".json"
file_contents = minimize(file_contents, self)
end
super(file_contents)
end
|
#write_pretty_json ⇒ Object
39
40
41
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 39
def write_pretty_json
@write_pretty_json.nil? ? root.write_pretty_json : @write_pretty_json
end
|
#write_pretty_json=(value) ⇒ Object
35
36
37
|
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_entry.rb', line 35
def write_pretty_json=(value)
@write_pretty_json = value
end
|