Sha256: ea893311db492117e153049c733d2ffbd474ea326fd99755d32391e817176b12

Contents?: true

Size: 968 Bytes

Versions: 29

Compression:

Stored size: 968 Bytes

Contents

module Arrest
  class Attribute
    attr_accessor :name, :read_only, :clazz, :json_name
    def initialize name, read_only, clazz
      @name = name.to_sym
      @read_only = read_only
      @clazz = clazz
      @json_name = Source.json_key_converter.key_to_json(name).to_sym
    end

    def from_hash(parent, value)
      return if value == nil

      if @clazz.respond_to?(:convert)
        return @clazz.convert(value)
      end

      converter = CONVERTER[@clazz]
      if converter == nil
        puts "No converter for: #{@clazz.name}"
        converter = IdentConv
      end
      converter.convert value
    end


    def to_hash value
      return nil unless value != nil

      if @clazz.respond_to?(:mk_json)
        return @clazz.mk_json(value)
      end

      converter = CONVERTER[@clazz]
      if converter == nil
        puts "No converter for: #{@clazz.name}"
        converter = IdentConv
      end
      converter.mk_json value
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
arrest-0.0.83.1 lib/arrest/attributes/attribute.rb
arrest-0.0.83 lib/arrest/attributes/attribute.rb
arrest-0.0.82 lib/arrest/attributes/attribute.rb
arrest-0.0.80 lib/arrest/attributes/attribute.rb
arrest-0.0.79 lib/arrest/attributes/attribute.rb
arrest-0.0.78 lib/arrest/attributes/attribute.rb
arrest-0.0.77 lib/arrest/attributes/attribute.rb
arrest-0.0.76 lib/arrest/attributes/attribute.rb
arrest-0.0.75 lib/arrest/attributes/attribute.rb
arrest-0.0.74 lib/arrest/attributes/attribute.rb
arrest-0.0.73 lib/arrest/attributes/attribute.rb
arrest-0.0.72 lib/arrest/attributes/attribute.rb
arrest-0.0.71 lib/arrest/attributes/attribute.rb
arrest-0.0.70 lib/arrest/attributes/attribute.rb
arrest-0.0.69 lib/arrest/attributes/attribute.rb
arrest-0.0.68 lib/arrest/attributes/attribute.rb
arrest-0.0.67 lib/arrest/attributes/attribute.rb
arrest-0.0.66 lib/arrest/attributes/attribute.rb
arrest-0.0.65 lib/arrest/attributes/attribute.rb
arrest-0.0.64 lib/arrest/attributes/attribute.rb