Sha256: 329566967a37b49d90f859a6d2a8db427c0b9cd7a2db931be6078f4b7c93ff80

Contents?: true

Size: 911 Bytes

Versions: 5

Compression:

Stored size: 911 Bytes

Contents

module SonJay
  class ObjectModel

    class PropertyDefinition
      attr_reader :name, :model_class

      def initialize(name, instruction = nil)
        @name        = "#{name}".freeze
        @model_class = model_class_for_instruction( instruction )
      end

      private

      def model_class_for_instruction(instruction)
        if instruction.nil?
          nil
        elsif instruction.respond_to?( :to_ary )
          array_model_class( instruction )
        elsif instruction.respond_to?( :new )
          instruction
        end
      end

      private

      def array_model_class(instruction)
        return instruction unless instruction.respond_to?( :to_ary )
        return SonJay::ValueArray if instruction == []

        sub_instruction = instruction.first
        sub_model_class = array_model_class( sub_instruction )
        sub_model_class.array_class
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
son_jay-0.5.2 lib/son_jay/object_model/property_definition.rb
son_jay-0.5.1 lib/son_jay/object_model/property_definition.rb
son_jay-0.5.0 lib/son_jay/object_model/property_definition.rb
son_jay-0.4.1 lib/son_jay/object_model/property_definition.rb
son_jay-0.4.0 lib/son_jay/object_model/property_definition.rb