Class: Ro::Root

Inherits:
Path show all
Defined in:
lib/ro/root.rb

Constant Summary collapse

@@warned_paths =
{}

Instance Method Summary collapse

Methods inherited from Path

#<=>, absolute, #absolute, absolute?, #base, #basename, #binwrite, #child?, clean, #detect, #directory?, expand, #extension, #file?, #files, #glob, #join, #key, #klass, #parent, #parent?, #parts, #pn, #relative, relative, relative?, #relative_from, #relative_to, #relative_to!, #select, #sibling?, #sort_key, #stat, #subdirectories, #subdirectory?, #subdirectory_for

Methods included from Klass

included

Methods inherited from String

#html_safe

Constructor Details

#initializeRoot

Returns a new instance of Root.



9
10
11
12
# File 'lib/ro/root.rb', line 9

def initialize(*)
  super
  check_for_unmigrated_structure!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kws, &block) ⇒ Object



76
77
78
# File 'lib/ro/root.rb', line 76

def method_missing(name, *args, **kws, &block)
  get(name) || super
end

Instance Method Details

#[](name) ⇒ Object



60
61
62
# File 'lib/ro/root.rb', line 60

def [](name)
  get(name)
end

#collection_for(subdirectory) ⇒ Object



25
26
27
# File 'lib/ro/root.rb', line 25

def collection_for(subdirectory)
  Collection.new(subdirectory)
end

#collections(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/ro/root.rb', line 14

def collections(&block)
  accum = Collection::List.for(self)

  subdirectories do |subdirectory|
    collection = collection_for(subdirectory)
    block ? block.call(collection) : accum.push(collection)
  end

  block ? self : accum
end

#get(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ro/root.rb', line 37

def get(name)
  name = name.to_s

  if name.index('/')
    collection_name, node_name = name.split('/', 2)
    collection = get(collection_name)

    if collection
      node = collection.get(node_name)
      return node
    else
      return nil
    end
  end

  paths_for(name).each do |path|
    next unless path.directory?
    return collection_for(path)
  end

  nil
end

#identifierObject



5
6
7
# File 'lib/ro/root.rb', line 5

def identifier
  self
end

#nodes(&block) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ro/root.rb', line 64

def nodes(&block)
  accum = []
  
  collections.each do |collection|
    collection.nodes do |node|
      block ? block.call(node) : accum.push(node)
    end
  end

  block ? self : accum
end

#paths_for(name) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ro/root.rb', line 29

def paths_for(name)
  [
    subdirectory_for(name),
    subdirectory_for(Slug.for(name, :join => '-')),
    subdirectory_for(Slug.for(name, :join => '_')),
  ]
end