Sha256: 049c9c84d5076416f7cab2e0e998e46779475b1f179d78d68c015cf757d25cd0

Contents?: true

Size: 761 Bytes

Versions: 2

Compression:

Stored size: 761 Bytes

Contents

module Hari
  class Entity
    class Property
      module Builder

        def property(name, options = {})
          attr_accessor name
          validates_presence_of name if options[:required]

          self.properties << Property.new(name, options)
        end

        def properties(*args)
          options = args.extract_options!
          args.each { |name| property name, options }

          @properties ||= begin
            if self == Hari::Entity
              []
            else
              entities_ancestors = ancestors.select do |a|
                a.ancestors.include? Hari::Entity
              end

              entities_ancestors[1].properties.dup # the closest
            end
          end
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hari-0.0.4 lib/hari/entity/property/builder.rb
hari-0.0.3 lib/hari/entity/property/builder.rb