Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When return from property is nil it does not continue to mapper #19

Open
arturictus opened this issue Jun 16, 2016 · 0 comments
Open

When return from property is nil it does not continue to mapper #19

arturictus opened this issue Jun 16, 2016 · 0 comments

Comments

@arturictus
Copy link
Owner

This are my mappers:
I've changed the initalize if the input is nil would build and empty skeleton.

class MobileConfigMapper < HashMap::Base
    transforms_output HashMap::UnderscoreKeys

    def initialize(hash)
      input = hash || {}
      super(input)
    end

    properties 'EnableBookingAir',
               'EnableChangeAir',
               'EnableCancelAir',
               'EnableBookingHotel',
               'EnableChangeHotel',
               'EnableCancelHotel',
               'EnableBookingCar',
               'EnableChangeCar',
               'EnableCancelCar',
               'EnableCertify',
               'EnableLyft',
               'EnableGoogleFlights',
               'EnableHilton',
               'EnableProfileAccess',
               'EnableSecureLocateMe',
               'EnableEULA'
  end

  class CompanySettingsMapper < HashMap::Base
    transforms_output HashMap::UnderscoreKeys
    from_child 'CompanySettings' do
      from_child 'CompanyIdentity' do
        property 'CompanyGuid'
      end
      properties 'IsCertifyEnabled', 'IsProfileEnabled'
      property 'PathMobileConfig', mapper: MobileConfigMapper
    end
  end

hash:

{
  "StatusCode": 200,
  "ErrorDescription": null,
  "Messages": null,
  "CompanySettings": {
    "CompanyIdentity": {
      "CompanyGuid": "0A6005FA-161D-4290-BB7D-B21B14313807",
      "PseudoCity": {
        "Code": "PARTQ2447"
      }
    },
    "IsCertifyEnabled": false,
    "IsProfileEnabled": true,
    "PathMobileConfig": null
  }
}

I expect PathMobileConfig or it's transformation path_mobile_config to be {} but it always returns `nil``

For now I will use the block turnaround:

property 'PathMobileConfig' do |settings|
  if hash = settings['PathMobileConfig']
    MobileConfigMapper.call(hash)
  else
    {}
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant