Class: Reactive::Mvc::View::PathSet::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/reactive-mvc/view/paths.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, load = true) ⇒ Path

Returns a new instance of Path.

Raises:

  • (ArgumentError)


54
55
56
57
58
# File 'lib/reactive-mvc/view/paths.rb', line 54

def initialize(path, load = true)
  raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
  @path = path.freeze
  reload! if load
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



51
52
53
# File 'lib/reactive-mvc/view/paths.rb', line 51

def path
  @path
end

#pathsObject (readonly)

Returns the value of attribute paths.



51
52
53
# File 'lib/reactive-mvc/view/paths.rb', line 51

def paths
  @paths
end

Class Method Details

.eager_load_templates!Object



43
44
45
# File 'lib/reactive-mvc/view/paths.rb', line 43

def self.eager_load_templates!
  @eager_load_templates = true
end

.eager_load_templates?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/reactive-mvc/view/paths.rb', line 47

def self.eager_load_templates?
  @eager_load_templates || false
end

Instance Method Details

#==(path) ⇒ Object



60
61
62
# File 'lib/reactive-mvc/view/paths.rb', line 60

def ==(path)
  to_str == path.to_str
end

#[](path) ⇒ Object



68
69
70
71
# File 'lib/reactive-mvc/view/paths.rb', line 68

def [](path)
  raise "Unloaded view path! #{@path}" unless @loaded
  @paths[path]
end

#eql?(path) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/reactive-mvc/view/paths.rb', line 64

def eql?(path)
  to_str == path.to_str
end

#loadObject



77
78
79
80
# File 'lib/reactive-mvc/view/paths.rb', line 77

def load
  reload! unless loaded?
  self
end

#loaded?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/reactive-mvc/view/paths.rb', line 73

def loaded?
  @loaded ? true : false
end

#reload!Object

Rebuild load path directory cache



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/reactive-mvc/view/paths.rb', line 83

def reload!
  @paths = {}

  templates_in_path do |template|
    # Eager load memoized methods and freeze cached template
    template.freeze if self.class.eager_load_templates?

    @paths[template.path] = template
    @paths[template.path_without_extension] ||= template
  end

  @paths.freeze
  @loaded = true
end