Sha256: 0d6b5afce2165b2cbb03fe9504490dec99c3aa8a3bfb3c249c9f0e63ce0fcead

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Vedeu

  # A composition is a collection of interfaces.
  #
  # @api private
  class Composition

    attr_reader :attributes

    # Builds a new composition, ready to be rendered to the screen.
    #
    # @param attributes [Hash]
    # @param block [Proc]
    # @return [Hash]
    def self.build(attributes = {}, &block)
      new(attributes, &block).attributes
    end

    # Returns a new instance of Composition.
    #
    # @param attributes [Hash]
    # @param block [Proc]
    # @return [Composition]
    def initialize(attributes = {}, &block)
      @attributes = defaults.merge!(attributes)

      if block_given?
        @self_before_instance_eval = eval('self', block.binding)

        instance_eval(&block)
      end
    end

    # Returns a collection of interfaces associated with this composition.
    #
    # @return [Array]
    def interfaces
      @interfaces ||= Interface.coercer(attributes[:interfaces])
    end

    # Returns the view attributes for a Composition, which will always be none,
    # as a composition is a merely a collection of interfaces.
    #
    # @return [Hash]
    def view_attributes
      {}
    end

    private

    # The default values for a new instance of Composition.
    #
    # @api private
    # @return [Hash]
    def defaults
      {
        interfaces: []
      }
    end

    # @api private
    # @return []
    def method_missing(method, *args, &block)
      Vedeu.log("Composition#method_missing '#{method.to_s}' (args: #{args.inspect})")

      @self_before_instance_eval.send(method, *args, &block)
    end

  end # Composition

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.2.3 lib/vedeu/models/composition.rb