Class: PeekAView::Configuration

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/peek_a_view/configuration.rb

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



6
7
8
9
# File 'lib/peek_a_view/configuration.rb', line 6

def initialize(*)
  super
  clear_views!
end

Instance Method Details

#all_views(&block) ⇒ Object

:yields: a common view object



38
39
40
41
42
# File 'lib/peek_a_view/configuration.rb', line 38

def all_views(&block) # :yields: a common view object
  @common.tap do |common|
    @common << block
  end
end

#clear_views!Object



24
25
26
27
# File 'lib/peek_a_view/configuration.rb', line 24

def clear_views!
  @views  = { }
  @common = []
end

#load_viewsObject



15
16
17
18
19
20
21
22
# File 'lib/peek_a_view/configuration.rb', line 15

def load_views
  clear_views!
  if (file = views_file)
    load file
  else
    raise "No peek-a-view definitions found." # TODO proper exception class
  end
end

#view(*names, &block) ⇒ Object

:yields: a view object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
# File 'lib/peek_a_view/configuration.rb', line 29

def view(*names, &block) # :yields: a view object
  raise ArgumentError, "A view must have a least one name." unless names.length > 0
  names.each do |name|
    (@views[name] ||= PeekAView::View.new(name, @common)).tap do |view|
      view.record(block)
    end
  end
end

#viewsObject



44
45
46
# File 'lib/peek_a_view/configuration.rb', line 44

def views
  @views
end

#views_fileObject



11
12
13
# File 'lib/peek_a_view/configuration.rb', line 11

def views_file
  Array(views_path).map { |p| File.join(Rails.root, p) }.find { |p| File.file?(p) }
end