Sha256: 7787f5f5247b525fde5f2df0f192d4d9b180e7d561555bcbb7f8192036bf271b

Contents?: true

Size: 678 Bytes

Versions: 2

Compression:

Stored size: 678 Bytes

Contents

class ContextExposer::ViewContext
  attr_reader   :controller
  attr_accessor :page

  def initialize controller = nil, page = nil
    @controller = controller
    self.page   = page if page
  end

  def page= page
    validate_page! page
    @page = page
  end

  protected

  def validate_page! page
    raise ArgumentError, "Must be a kind of #{valid_page_class}, was: #{page}" unless valid_page? page
  end

  def valid_page? page
    page.kind_of? valid_page_class
  end

  def valid_page_class
    ContextExposer::Page
  end

  def define_singleton_method(name, &block)
    eigenclass = class<<self; self end
    eigenclass.class_eval {define_method name, block}
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
context_exposer-0.4.1 lib/context_exposer/view_context.rb
context_exposer-0.4.0 lib/context_exposer/view_context.rb