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

#clean_pathname, #containing_workspace, #current_directory, #file_from_backtrace, #from_here, #make_pathname, #starting_directory, #up_to, #up_until

Constructor Details

#initialize(stack, root, dump_load) ⇒ Item

Returns a new instance of Item.



9
10
11
12
13
14
# File 'lib/valise/item.rb', line 9

def initialize(stack, root, dump_load)
  @stack = stack
  @root = root
  @dump_load = dump_load
  @contents = nil
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



17
18
19
# File 'lib/valise/item.rb', line 17

def contents
  @contents
end

#rootObject (readonly)

Returns the value of attribute root.



16
17
18
# File 'lib/valise/item.rb', line 16

def root
  @root
end

#stackObject (readonly)

Returns the value of attribute stack.



16
17
18
# File 'lib/valise/item.rb', line 16

def stack
  @stack
end

Instance Method Details

#depthObject



23
24
25
# File 'lib/valise/item.rb', line 23

def depth
  @stack.depth_of(self)
end

#dump_contentsObject



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

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

#full_pathObject



35
36
37
# File 'lib/valise/item.rb', line 35

def full_path
  @root.full_path(segments)
end

#inspectObject



19
20
21
# File 'lib/valise/item.rb', line 19

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

#load_contentsObject



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

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

#open(&block) ⇒ Object



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

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

#present?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/valise/item.rb', line 43

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

#raw_contentsObject



51
52
53
# File 'lib/valise/item.rb', line 51

def raw_contents
  @root.get_from(self)
end

#raw_fileObject



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

def raw_file
  File::open(full_path)
end

#rel_pathObject



31
32
33
# File 'lib/valise/item.rb', line 31

def rel_path
  @stack.rel_path
end

#saveObject



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

def save
  root.write(self)
end

#segmentsObject



27
28
29
# File 'lib/valise/item.rb', line 27

def segments
  @stack.segments
end

#writable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/valise/item.rb', line 39

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