Skip to content

Instantly share code, notes, and snippets.

@davidteren
Created August 11, 2023 18:53
Show Gist options
  • Save davidteren/417b49bf36685d4ec3751e5cf7205bfc to your computer and use it in GitHub Desktop.
Save davidteren/417b49bf36685d4ec3751e5cf7205bfc to your computer and use it in GitHub Desktop.
A simple way to get all the classes and their members from a struct

Sometimes Structs have a number of class types each with their own members.

response = mediaconvert.create_job(job_params)

# This output exampled has been shortened a lot
# => #<struct Aws::MediaConvert::Types::CreateJobResponse job=#<struct Aws::MediaConvert::Types::Job arn="arn:aws:mediaconvert:us-west-1:<protected>:jobs/<hidden>-nedzn7", ...,  error_message=nil, id="1691778742640-nedzn7", job_template="arn:aws:mediaconvert:us-west-1:<protected>:jobTemplates/Test Job Template - no Audio", output_group_details=nil, queue="arn:aws:mediaconvert:us-west-1:<protected>:queues/Default", caption_selectors=nil, deblock_filter=nil, denoise_filter=nil, file_input="https://some-bucket.s3-eu-west-1.amazonaws.com/some-path/somehash/test%20vid%20copy%208.mp4", filter_enable=nil, filter_strength=nil, input_clippings=nil, program_number=nil, psi_control=nil, timecode_source="ZEROBASED", video_selector=#<struct Aws::MediaConvert::Types::VideoSelector, output_groups=[#<struct Aws::MediaConvert::Types::OutputGroup custom_name=nil, name="File Group", output_group_settings=#<struct Aws::MediaConvert::Types::OutputGroupSettings cmaf_group_settings=nil, dash_iso_group_settings=nil, file_group_settings=#<struct timestamp_offset=nil>, timed_metadata_insertion=nil>, status="SUBMITTED", timing=#<struct Aws::MediaConvert::Types::Timing finish_time=nil, start_time=nil, submit_time=2023-08-11 20:32:22 +0200>, user_metadata={}>>

To get a list of Classes and members you can do something like this

def print_members(obj, prefix='')
  if obj.respond_to?(:members)
    puts "#{prefix}#{obj.class}"
    obj.members.each do |member|
      puts "#{prefix}- #{member}"
      print_members(obj.send(member), "#{prefix}  ")
    end
  else
    puts "#{prefix}- #{obj.class}"
  end
end
response = mediaconvert.create_job(job_params)
print_members response
0> response = mediaconvert.create_job(job_params)
1> print_members response
Seahorse::Client::Response
- job
  Aws::MediaConvert::Types::Job
  - arn
    - String
  - created_at
    - Time
  - error_code
    - NilClass
  - error_message
    - NilClass
  - id
    - String
  - job_template
    - String
  - output_group_details
    - NilClass
  - queue
    - String
  - role
    - String
  - settings
    Aws::MediaConvert::Types::JobSettings
    - ad_avail_offset
      - NilClass
    - avail_blanking
      - NilClass
    - inputs
      - Array
    - nielsen_configuration
      - NilClass
    - output_groups
      - Array
    - timecode_config
      Aws::MediaConvert::Types::TimecodeConfig
      - anchor
        - NilClass
      - source
        - String
      - start
        - NilClass
      - timestamp_offset
        - NilClass
    - timed_metadata_insertion
      - NilClass
  - status
    - String
  - timing
    Aws::MediaConvert::Types::Timing
    - finish_time
      - NilClass
    - start_time
      - NilClass
    - submit_time
      - Time
  - user_metadata
    - Hash
=> [:job]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment