Sha256: a188774d14ab2f3ea2ab11ad0d80f47f05890f1596f7ebfd4c23fae39c699333
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
require 'seory/runtime' module Seory class DuplicateDefault < Seory::Error; end class Repository class << self def extract_label_from_trace(trace) trace.first.split(':').first end end attr_accessor :helper def initialize @page_groups = [] end def <<(page_group) remove_old_group!(page_group.name) @page_groups << page_group clear_page_order_pre_calculation! end def lookup(controller) page = pre_orderd_pages.detect {|pg| pg.match?(controller) } || default Seory::Runtime.new(page, controller, default).tap do |runtime| runtime.extend helper if helper end end def default @default ||= @page_groups.map(&:default).compact.tap {|defaults| raise DuplicateDefault if defaults.size > 1 }.first end private def pre_orderd_pages @pre_orderd_pages ||= @page_groups.sort_by(&:name).flat_map(&:pages) end def remove_old_group!(page_group_name) @page_groups.reject! {|pg| pg.name == page_group_name } end def clear_page_order_pre_calculation! @pre_orderd_pages = nil @default = nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
seory-0.1.0 | lib/seory/repository.rb |