Sha256: 25e1bb02b3407c51c71f376d4a9fdc52d5bd988de23ebf11d8ae28821717e3cc

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

# TODO move somewhere
require 'active_support/all'
require 'seory'

module Seory
  class Runtime
    delegate :action_name, to: :controller

    attr_reader :controller

    def initialize(page_contents, controller)
      @page_contents = page_contents
      @controller    = controller
    end

    def assigns(name)
      @controller.view_assigns[name.to_s]
    end

    def misc(name)
      calculate_content_for(name)
    end

    Seory::CONTENTS.each do |name|
      define_method(name) { misc(name) }
    end

    private

    def calculate_content_for(name)
      case page_content = @page_contents.content_for(name)
      when String
        page_content
      when ->(o) { o.respond_to?(:call) }
        instance_exec(&page_content)
      else
        raise 'BUG'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seory-0.0.3 lib/seory/runtime.rb