Sha256: b5021b53c2d9ecf899504f426a790b9a8d50897bd769b8d9880e1ea4d4df53ff

Contents?: true

Size: 1.26 KB

Versions: 30

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

class ReeMapper::MapperStrategy
  attr_reader :method, :always_optional

  contract(Symbol, ReeMapper::StrategyOutput, Bool => Any)
  def initialize(method:, output:, always_optional:)
    @method          = method
    @output          = output
    @always_optional = always_optional
  end

  contract None => ReeMapper::StrategyOutput
  def output
    @output
  end

  contract ReeMapper::StrategyOutput => ReeMapper::StrategyOutput
  def output=(output)
    @output = output
  end

  contract(Any)
  def build_object
    output.build_object
  end

  contract(Any, ReeMapper::Field, Any => nil)
  def assign_value(object, field, value)
    output.assign_value(object, field, value)
  end

  contract(Any, ReeMapper::Field => Bool)
  def has_value?(obj, field)
    if obj.is_a?(Hash)
      obj.key?(field.from) || obj.key?(field.from_as_str)
    else
      obj.respond_to?(field.from)
    end
  end

  contract(Any, ReeMapper::Field => Any)
  def get_value(obj, field)
    if obj.is_a?(Hash)
      obj.key?(field.from) ? obj[field.from] : obj[field.from_as_str]
    else
      obj.public_send(field.from)
    end
  end

  contract(Class => Class)
  def dto=(dto)
    output.dto = dto
  end

  contract(None => Nilor[Class])
  def dto
    output.dto
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ree_lib-1.0.30 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.29 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.28 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.27 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.26 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.24 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.23 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.22 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.21 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.20 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.19 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.18 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.17 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.16 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.15 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.14 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.13 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.12 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.11 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb
ree_lib-1.0.10 lib/ree_lib/packages/ree_mapper/package/ree_mapper/mapper_strategy.rb