Sha256: 3f7d4d3a54cbc9c96b26f3e9b736e778bd0f1d130f314c2aa49eefe49563f47d

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

require 'alephant/publisher/views'
require 'hashie'

module Alephant
  module Publisher
    module Views
      module Base
        def self.included base
          base.send :include, InstanceMethods
          base.extend ClassMethods
        end

        module InstanceMethods
          attr_reader :data, :content_type, :base_path

          def initialize(data = {})
            @data = Hashie::Mash.new data
            @base_path = self.class.base_path

            setup
          end

          def to_h
            whitelist.reduce({}) { |m,s| m.tap { |m| m[s] = self.send(s) } }
          end

          def setup; end
          def whitelist; [] end
        end

        module ClassMethods
          attr_accessor :base_path

          def inherited(subclass)
            current_dir = File.dirname(caller.first[/\/[^:]+/])
            dir_path    = Pathname.new(File.join(current_dir,'..')).realdirpath

            subclass.base_path = dir_path.to_s

            Alephant::Publisher::Views.register(subclass)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
alephant-publisher-0.6.10 lib/alephant/publisher/views/base.rb
alephant-publisher-0.6.9 lib/alephant/publisher/views/base.rb
alephant-publisher-0.6.8 lib/alephant/publisher/views/base.rb
alephant-publisher-0.6.7 lib/alephant/publisher/views/base.rb
alephant-publisher-0.6.6 lib/alephant/publisher/views/base.rb
alephant-publisher-0.6.5 lib/alephant/publisher/views/base.rb
alephant-publisher-0.6.4 lib/alephant/publisher/views/base.rb