Skip to content

Override #to_s for top level classes #9

@PandaWhisperer

Description

@PandaWhisperer

Background

Most of the main classes that users interact with when using the service (i.e. Service, EntitySet, Entity, etc.) are extremely verbose when printed on the console, which makes exploring a service using irb somewhat difficult.

We should implement #to_s for these classes in order to show a more condensed summary with only the necessary information.

Notes

The main issue here are properties which refer to the XML metadata, those end up printing the entire tree and should therefore be omitted from #to_s.

Service

All we need is here is the name and service_url attributes, like so:

#<OData4::Service name='ODataDemo' service_url='http://services.odata.org/OData/OData.svc/'>

Schema

Should only print the attributes on the corresponding XML tag, i.e. namespace and alias (we don't use the latter at the moment).

#<OData4::Schema namespace='ODataDemo'>

EntitySet

#<OData4::EntitySet:0x007fd9eb93db00 name="Products" type="ODataDemo.Product", @namespace="ODataDemo" container="DemoService" service_name="ODataDemo">

Entity

This one is going to require the most work. Currently produces a HUGE amount of noise.

#<OData4::Entity:0x007fd9eb249c90 id=1 type="ODataDemo.Product" entity_set=#<...> properties={"ID"=>0, "ReleaseDate"=>"1992-01-01T00:00:00", "DiscontinuedDate"=>nil, "Rating"=>4, "Price"=>2.5} navigation_properties=["Categories", "Supplier", "ProductDetail"]>

For the properties field, use the result of self.to_hash. For navigation_properties, use self.navigation_properties.keys.

Property

Should only display the name, value, and options without the :service key. value should print the return value of the value getter, NOT the internal value of the @value instance variable.

#<OData4::Properties::Int32:0x007fd9ec8016c8 name="ID" value=0 options={:allows_nil=>true, :concurrency_mode=>:none}>

NavigationProperty

#<OData4::NavigationProperty:0x007fd9eb82ac18 name="Products" type="Collection(ODataDemo.Product)" nullable=true>

EnumType

#<OData4::EnumType:0x007ff5ef88d870 name="ProductStatus" namespace="ODataDemo" underlying_type="Edm.Int32" members={0 => "Available", 1 => "LowStock", 2 => "Backordered", 3 => "Discontinued"}>

ComplexType

#<OData4::ComplexType:0x007ff5ef88d870 name="Address" namespace="ODataDemo"  properties={"Street" => "Edm.String", "City" => "Edm.String", "State" => "Edm.String", "ZipCode" => "Edm.String", "Country" => "Edm.String"}>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions