require 'active_support/concern'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string/inflections'

module Serf

  ##
  # A module to represent a message that we're transporting over
  # the wire. This is mainly for commands and events in ED-SOA.
  # Optional, but useful for validations, etc.
  #
  module Message
    extend ActiveSupport::Concern

    included do
      class_attribute :kind
      send 'kind=', self.to_s.tableize.singularize
      class_attribute :model_name
      send 'model_name=', self.to_s
    end

    def kind
      self.class.kind
    end

    def to_hash
      attributes.merge kind: kind
    end

    def to_msgpack
      to_hash.to_msgpack
    end

    def to_json(*args)
      to_hash.to_json *args
    end

    def model
      self.class
    end

    def full_error_messages
      errors.full_messages.join '. '
    end

    module ClassMethods

      def parse(*args)
        self.new *args
      end

    end

  end

end

require 'active_support/concern'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string/inflections'

module Serf

  ##
  # A module to represent a message that we're transporting over
  # the wire. This is mainly for commands and events in ED-SOA.
  # Optional, but useful for validations, etc.
  #
  module Message
    extend ActiveSupport::Concern

    included do
      class_attribute :kind
      send 'kind=', self.to_s.tableize.singularize
      class_attribute :model_name
      send 'model_name=', self.to_s
    end

    def kind
      self.class.kind
    end

    def to_hash
      attributes.merge kind: kind
    end

    def to_msgpack
      to_hash.to_msgpack
    end

    def to_json(*args)
      to_hash.to_json *args
    end

    def model
      self.class
    end

    def full_error_messages
      errors.full_messages.join '. '
    end

    module ClassMethods

      def parse(*args, &block)
        self.new *args, &block
      end

      def build(*args, &block)
        self.new *args, &block
      end

    end

  end

end

Add 'build' method to be equivilant to 'parse' to Messages.
Add 'build' method to be equivilant to 'parse' to Messages.

Details:
* Currently, some places we want to 'parse' a message, and it makes
  more sense (sugar) to 'build' a message. They currently do the
  same thing.
* In the future, maybe figure out a semantic difference between
  building a message and parsing a message in the Serf case.
* Fixed to also pass a block to the initialize.
