Class: OdataDuty::CreateComplexTypeHashWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/odata_duty/create_complex_type_hash_wrapper.rb

Constant Summary collapse

SETTABLE_BY_OPERATION =
{ create: :settable_on_create?, update: :settable_on_update? }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(hash, complex_type, operation:, context:) ⇒ CreateComplexTypeHashWrapper

Returns a new instance of CreateComplexTypeHashWrapper.



5
6
7
8
9
10
# File 'lib/odata_duty/create_complex_type_hash_wrapper.rb', line 5

def initialize(hash, complex_type, operation:, context:)
  @hash = hash
  @complex_type = complex_type
  @operation = operation
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/odata_duty/create_complex_type_hash_wrapper.rb', line 12

def method_missing(method_name, *args)
  matching_prop = @complex_type.properties.find { |p| p.name == method_name }
  unless matching_prop && args.empty?
    raise NoSuchPropertyError, "No such property '#{method_name}'"
  end

  __load(matching_prop, method_name, @hash[method_name.to_s])
end

Instance Method Details

#respond_to_missing?(method_name, _include_private) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/odata_duty/create_complex_type_hash_wrapper.rb', line 21

def respond_to_missing?(method_name, _include_private)
  @complex_type.properties.any? { |p| p.name == method_name }
end