Sha256: 324732d06483a9801c845cffc143c3011b89d2f4a5ae1395c70b2304ad08338c

Contents?: true

Size: 808 Bytes

Versions: 10

Compression:

Stored size: 808 Bytes

Contents

require "attentive/entity"

module Attentive
  class CompositeEntity < Entity
    attr_reader :entities

    @entities = []
    class << self
      attr_accessor :entities

      def define(entity_name, *entities)
        options = entities.last.is_a?(::Hash) ? entities.pop : {}

        create! entity_name do |entity_klass|
          entity_klass.entities = entities.map { |entity| Entity[entity] }
          entity_klass.published = options.fetch(:published, true)
        end
      end
    end

    def initialize(*args)
      super
      @entities = self.class.entities.map { |entity_klass| entity_klass.new(variable_name) }
    end

    def matches?(cursor)
      entities.each do |entity|
        match = entity.matches?(cursor)
        return match if match
      end
      false
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
attentive-0.3.9 lib/attentive/composite_entity.rb
attentive-0.3.8 lib/attentive/composite_entity.rb
attentive-0.3.7 lib/attentive/composite_entity.rb
attentive-0.3.6 lib/attentive/composite_entity.rb
attentive-0.3.5 lib/attentive/composite_entity.rb
attentive-0.3.4 lib/attentive/composite_entity.rb
attentive-0.3.3 lib/attentive/composite_entity.rb
attentive-0.3.2 lib/attentive/composite_entity.rb
attentive-0.3.1 lib/attentive/composite_entity.rb
attentive-0.3.0 lib/attentive/composite_entity.rb