Class: Valise::Item

Inherits:
Object
  • Object
show all
Includes:
Unpath
Defined in:
lib/valise/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Unpath

#repath, #unpath

Constructor Details

#initialize(stack, root, dump_load) ⇒ Item

Returns a new instance of Item.



46
47
48
49
50
51
# File 'lib/valise/item.rb', line 46

def initialize(stack, root, dump_load)
  @stack = stack
  @root = root
  @dump_load = dump_load || Serialization::Raw
  @contents = nil
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



54
55
56
# File 'lib/valise/item.rb', line 54

def contents
  @contents
end

#rootObject (readonly)

Returns the value of attribute root.



53
54
55
# File 'lib/valise/item.rb', line 53

def root
  @root
end

#stackObject (readonly)

Returns the value of attribute stack.



53
54
55
# File 'lib/valise/item.rb', line 53

def stack
  @stack
end

Instance Method Details

#dump_contentsObject



98
99
100
# File 'lib/valise/item.rb', line 98

def dump_contents
  @dump_load.dump(load_contents) #@contents?
end

#full_pathObject



64
65
66
# File 'lib/valise/item.rb', line 64

def full_path
  @root.full_path(segments)
end

#inspectObject



56
57
58
# File 'lib/valise/item.rb', line 56

def inspect
  "#{@root.inspect}//#{@stack.inspect}"
end

#load_contentsObject



102
103
104
# File 'lib/valise/item.rb', line 102

def load_contents
  @contents ||= @dump_load.load(@root.get_from(self))
end

#open(&block) ⇒ Object



80
81
82
# File 'lib/valise/item.rb', line 80

def open(&block)
  File::open(full_path, "r", &block)
end

#present?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/valise/item.rb', line 72

def present?
  @root.present?(segments)
end

#raw_fileObject



76
77
78
# File 'lib/valise/item.rb', line 76

def raw_file
  File::open(full_path)
end

#saveObject



84
85
86
# File 'lib/valise/item.rb', line 84

def save
  root.write(self)
end

#segmentsObject



60
61
62
# File 'lib/valise/item.rb', line 60

def segments
  @stack.segments
end

#writable?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/valise/item.rb', line 68

def writable?
  @root.writable?(segments)
end