Sha256: 5e244aae343d3aba7fdff81ffca6275e35e8a5ac5299c9aefdd2adec8e681577

Contents?: true

Size: 514 Bytes

Versions: 19

Compression:

Stored size: 514 Bytes

Contents

module Acfs::Model::Attributes

  class Base
    attr_reader :options

    def initialize(opts = {})
      @options = opts
      @options.reverse_merge! allow_nil: true
    end

    def nil_allowed?
      !!options[:allow_nil]
    end

    def default_value
      options[:default].is_a?(Proc) ? options[:default] : cast(options[:default])
    end

    def cast(obj)
      return nil if obj.nil? && nil_allowed?
      cast_type obj
    end

    def cast_type(obj)
      raise NotImplementedError
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
acfs-0.24.0.1.b214 lib/acfs/model/attributes/base.rb
acfs-0.24.0.1.b212 lib/acfs/model/attributes/base.rb
acfs-0.24.0.b210 lib/acfs/model/attributes/base.rb
acfs-0.24.0 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b209 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b208 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b206 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b205 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b204 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b203 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b200 lib/acfs/model/attributes/base.rb
acfs-0.23.2.b199 lib/acfs/model/attributes/base.rb
acfs-0.23.2 lib/acfs/model/attributes/base.rb
acfs-0.23.1.b198 lib/acfs/model/attributes/base.rb
acfs-0.23.1 lib/acfs/model/attributes/base.rb
acfs-0.23.0.b197 lib/acfs/model/attributes/base.rb
acfs-0.22.2.b196 lib/acfs/model/attributes/base.rb
acfs-0.23.0 lib/acfs/model/attributes/base.rb
acfs-0.22.2.b194 lib/acfs/model/attributes/base.rb