Skip to content

Commit

Permalink
Ruby - Regenerating samples for ruby (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishrutshah authored Jun 16, 2016
1 parent 74917b9 commit 5dfea14
Show file tree
Hide file tree
Showing 25 changed files with 1,060 additions and 1,330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,44 @@ class CheckNameAvailabilityResult
# more detail.
attr_accessor :message

#
# Validate the object. Throws ValidationError if validation fails.
#
def validate
end

#
# Serializes given Model object into Ruby Hash.
# @param object Model object to serialize.
# @return [Hash] Serialized object in form of Ruby Hash.
# Mapper for CheckNameAvailabilityResult class as Ruby Hash.
# This will be used for serialization/deserialization.
#
def self.serialize_object(object)
object.validate
output_object = {}

serialized_property = object.name_available
output_object['nameAvailable'] = serialized_property unless serialized_property.nil?

serialized_property = object.reason
output_object['reason'] = serialized_property unless serialized_property.nil?

serialized_property = object.message
output_object['message'] = serialized_property unless serialized_property.nil?

output_object
end

#
# Deserializes given Ruby Hash into Model object.
# @param object [Hash] Ruby Hash object to deserialize.
# @return [CheckNameAvailabilityResult] Deserialized object.
#
def self.deserialize_object(object)
return if object.nil?
output_object = CheckNameAvailabilityResult.new

deserialized_property = object['nameAvailable']
output_object.name_available = deserialized_property

deserialized_property = object['reason']
if (!deserialized_property.nil? && !deserialized_property.empty?)
enum_is_valid = Reason.constants.any? { |e| Reason.const_get(e).to_s.downcase == deserialized_property.downcase }
warn 'Enum Reason does not contain ' + deserialized_property.downcase + ', but was received from the server.' unless enum_is_valid
end
output_object.reason = deserialized_property

deserialized_property = object['message']
output_object.message = deserialized_property

output_object
def self.mapper()
{
required: false,
serialized_name: 'CheckNameAvailabilityResult',
type: {
name: 'Composite',
class_name: 'CheckNameAvailabilityResult',
model_properties: {
name_available: {
required: false,
serialized_name: 'nameAvailable',
type: {
name: 'Boolean'
}
},
reason: {
required: false,
serialized_name: 'reason',
type: {
name: 'Enum',
module: 'Reason'
}
},
message: {
required: false,
serialized_name: 'message',
type: {
name: 'String'
}
}
}
}
}
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,36 @@ class CustomDomain
# enabled. Default value is false. This should only be set on updates
attr_accessor :use_sub_domain

#
# Validate the object. Throws ValidationError if validation fails.
#
def validate
fail MsRest::ValidationError, 'property name is nil' if @name.nil?
end

#
# Serializes given Model object into Ruby Hash.
# @param object Model object to serialize.
# @return [Hash] Serialized object in form of Ruby Hash.
# Mapper for CustomDomain class as Ruby Hash.
# This will be used for serialization/deserialization.
#
def self.serialize_object(object)
object.validate
output_object = {}

serialized_property = object.name
output_object['name'] = serialized_property unless serialized_property.nil?

serialized_property = object.use_sub_domain
output_object['useSubDomain'] = serialized_property unless serialized_property.nil?

output_object
end

#
# Deserializes given Ruby Hash into Model object.
# @param object [Hash] Ruby Hash object to deserialize.
# @return [CustomDomain] Deserialized object.
#
def self.deserialize_object(object)
return if object.nil?
output_object = CustomDomain.new

deserialized_property = object['name']
output_object.name = deserialized_property

deserialized_property = object['useSubDomain']
output_object.use_sub_domain = deserialized_property

output_object
def self.mapper()
{
required: false,
serialized_name: 'CustomDomain',
type: {
name: 'Composite',
class_name: 'CustomDomain',
model_properties: {
name: {
required: true,
serialized_name: 'name',
type: {
name: 'String'
}
},
use_sub_domain: {
required: false,
serialized_name: 'useSubDomain',
type: {
name: 'Boolean'
}
}
}
}
}
end
end
end
Expand Down
91 changes: 41 additions & 50 deletions Samples/azure-storage/Azure.Ruby/azure_storage/models/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,50 @@ class Endpoints
# @return [String] Gets the file endpoint.
attr_accessor :file

#
# Validate the object. Throws ValidationError if validation fails.
#
def validate
# Nothing to validate
end

#
# Serializes given Model object into Ruby Hash.
# @param object Model object to serialize.
# @return [Hash] Serialized object in form of Ruby Hash.
# Mapper for Endpoints class as Ruby Hash.
# This will be used for serialization/deserialization.
#
def self.serialize_object(object)
object.validate
output_object = {}

serialized_property = object.blob
output_object['blob'] = serialized_property unless serialized_property.nil?

serialized_property = object.queue
output_object['queue'] = serialized_property unless serialized_property.nil?

serialized_property = object.table
output_object['table'] = serialized_property unless serialized_property.nil?

serialized_property = object.file
output_object['file'] = serialized_property unless serialized_property.nil?

output_object
end

#
# Deserializes given Ruby Hash into Model object.
# @param object [Hash] Ruby Hash object to deserialize.
# @return [Endpoints] Deserialized object.
#
def self.deserialize_object(object)
return if object.nil?
output_object = Endpoints.new

deserialized_property = object['blob']
output_object.blob = deserialized_property

deserialized_property = object['queue']
output_object.queue = deserialized_property

deserialized_property = object['table']
output_object.table = deserialized_property

deserialized_property = object['file']
output_object.file = deserialized_property

output_object
def self.mapper()
{
required: false,
serialized_name: 'Endpoints',
type: {
name: 'Composite',
class_name: 'Endpoints',
model_properties: {
blob: {
required: false,
serialized_name: 'blob',
type: {
name: 'String'
}
},
queue: {
required: false,
serialized_name: 'queue',
type: {
name: 'String'
}
},
table: {
required: false,
serialized_name: 'table',
type: {
name: 'String'
}
},
file: {
required: false,
serialized_name: 'file',
type: {
name: 'String'
}
}
}
}
}
end
end
end
Expand Down
Loading

0 comments on commit 5dfea14

Please sign in to comment.