Sha256: 3600854f5d32ec3aeb1c7769eda07482bbbb5320ae059155eb9bc980f00cd0f4

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# encoding: utf-8
require "hexx-cli"

module ServiceObjects

  module Parsers

    # Parses and decorates a string, describing a notification
    #
    # @example
    #   result = ServiceObjects::Parsers::Dependency.new "add_item{get_item}"
    #   result.name     # => add_item
    #   result.type     # => GetItem
    #   result.listener # => AddItemListener
    class Dependency

      # @!scope class
      # @!method new(source)
      # Constructs the object from source
      #
      # @param  [#to_s] source
      #
      # @return [Hexx::Services::Parsers::Dependency]
      def initialize(source)
        @source = source.to_s
      end

      # The name for the dependency default implementation
      #
      # @return [String]
      def name
        @name ||= injector.item
      end

      # The type for the dependency default implementation
      #
      # @return [String]
      def type
        @type ||= injection.type
      end

      # The listener name for the dependency
      #
      # @return [String]
      def listener
        @listener ||= "#{ injector.const }Listener"
      end

      private

      attr_reader :source

      def matcher
        @matcher ||= source.match(/^(.+){(.+)}$/)
      end

      def injector
        @injector ||= Hexx::CLI::Name.new matcher[1]
      end

      def injection
        @injection ||= Hexx::CLI::Name.new matcher[2]
      end

    end # class Dependency

  end # module Parsers

end # module ServiceObjects

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
service_objects-0.1.0 lib/service_objects/parsers/dependency.rb