Module: Pragma::Contract::ModelFinder::ClassMethods

Defined in:
lib/pragma/contract/model_finder.rb

Instance Method Summary collapse

Instance Method Details

#property(name, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pragma/contract/model_finder.rb', line 16

def property(name, options = {})
  return super if !options[:type] || options[:type].is_a?(Dry::Types::Type)

  property(name, Hash[options.reject { |k, _| k == :type }])

  define_method("#{name}=") do |value|
    finder = Pragma::Contract::ModelFinder.load_adaptor!(
      options[:type],
      Hash[options.select { |k, _| FINDER_OPTIONS.include?(k.to_sym) }]
    )

    super finder.find(value)
  end
end