Class: FileScheduler::File

Inherits:
Object show all
Includes:
Content
Defined in:
lib/file_scheduler/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Content

#attributes_parser, #forced_started_time?, #parser, #repeat_constraints

Constructor Details

#initialize(path, parent = nil) ⇒ File



6
7
8
9
# File 'lib/file_scheduler/file.rb', line 6

def initialize(path, parent = nil)
  @parent = parent
  @path = Pathname.new(path)
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/file_scheduler/file.rb', line 4

def parent
  @parent
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/file_scheduler/file.rb', line 4

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



60
61
62
63
64
# File 'lib/file_scheduler/file.rb', line 60

def ==(other)
  [:parent, :path].all? do |attribute|
    other.respond_to?(attribute) and send(attribute) == other.send(attribute)
  end
end

#attributesObject



74
75
76
77
# File 'lib/file_scheduler/file.rb', line 74

def attributes
  @attributes ||=
    (parent ? parent.attributes : {}).merge(local_attributes)
end

#childrenObject



42
43
44
45
46
# File 'lib/file_scheduler/file.rb', line 42

def children
  @children ||= file_system_children.collect do |file|
    File.new(file, self)
  end.delete_if(&:hidden?)
end

#content?Boolean



56
57
58
# File 'lib/file_scheduler/file.rb', line 56

def content?
  path.file?
end

#contentsObject



48
49
50
51
52
53
54
# File 'lib/file_scheduler/file.rb', line 48

def contents
  if content?
    [self]
  else
    children.collect(&:contents).flatten
  end
end

#file_system_childrenObject



36
37
38
# File 'lib/file_scheduler/file.rb', line 36

def file_system_children
  @file_system_children ||= path.children
end

#hidden?Boolean



15
16
17
# File 'lib/file_scheduler/file.rb', line 15

def hidden?
  name.start_with?("_")
end

#local_attributesObject



70
71
72
# File 'lib/file_scheduler/file.rb', line 70

def local_attributes
  @local_attributes ||= attributes_parser.parse(name)
end

#local_time_constraintsObject



19
20
21
# File 'lib/file_scheduler/file.rb', line 19

def local_time_constraints
  parser.parse(name) if parent
end

#nameObject



11
12
13
# File 'lib/file_scheduler/file.rb', line 11

def name
  @name ||= path.basename.to_s
end

#time_constraintsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/file_scheduler/file.rb', line 23

def time_constraints
  @time_constraints ||= 
    if parent and parent.time_constraints
      if local_time_constraints
        TimeChain.new parent.time_constraints, local_time_constraints
      else
        parent.time_constraints
      end
    else
      local_time_constraints
    end
end

#to_sObject



66
67
68
# File 'lib/file_scheduler/file.rb', line 66

def to_s
  path.to_s
end