Sha256: fdbda8cf8e6eddbc172493b4c1485147853ae38b7382ba3167f8668efb6cf4b7

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module Brief
  module Handlers
    class Base
      attr_accessor :element, :prepared

      def initialize(element)
        @element = element
      end

      def method_missing meth, *args, &block
        if element.respond_to?(meth)
          return element.send(meth, *args, &block)
        end

        super
      end

      def content
        element.content
      end

      def document
        get_manager.try :document
      end

      def document_settings
        document.try(:settings)
      end

      def get_manager &block
        if block_given?
          @get_manager = block
        end

        @get_manager && @get_manager.call()
      end

      def parent &block
        if block_given?
          @find_parent_block = block
        end

        @find_parent_block && @find_parent_block.call(element.parent_id)
      end

      # Your handler should implement this method, the goal is to transform the
      # element we are passed into an object that is suitable for whatever integration
      # you have planned for it.  For example, preparing the necessary attributes for
      # a submission to github issues or milestones
      def prepare!
        @prepared ||= begin
                        element
                      end
      end

      # Do whatever you want to do with the prepared element
      def handle!
        prepare!
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brief-0.0.5 lib/brief/handlers/base.rb
brief-0.0.4 lib/brief/handlers/base.rb
brief-0.0.3 lib/brief/handlers/base.rb
brief-0.0.2 lib/brief/handlers/base.rb