inossidabile/wash_out — pull request #147 by bogdanRada (2014-05-26 12:58:38+00:00)
Title: Redefining complex types to allow options to be passed like minoccurs, maxoccurs or nillable 

I made some changes to the way complex types are being defined :

Some of the old ways are still possible :

1.soap_action "integer_to_string" :args => :integer, :return => :string
2. soap_action "integer_to_string" :args => { :a => :string, :b => :string }, :return => :string # but this way you won't be able to set minoccurs , maxoccurs or nillable for this complex type
3. soap_action "integers_to_boolean", :args => { :data => [:integer] } , :return => [:boolean]
4. soap_action "integers_to_boolean", :args => [:integer] , :return => [:boolean]

Washout::Type extends now Virtus.model from virtus gem ( https://github.com/solnic/virtus )
so now you can do something like this:
class FluffyContainer < WashOut::Type
type_name "fluffy_con"
attribute name, String, :options => {:minoccurs => 0, :maxoccurs => 1, :nillable =>true }
attribute name, Integer, :options => {:minoccurs => 0, :maxoccurs => 1, :nillable =>true }
end

if no options are specified for a attribute, minoccurs will be 0, maxoccurs will be 1 , and nillable = true
but i can change the default settings if that is needed.

The only thing you would not be able to do is this:
class FluffyContainer < WashOut::Type
map :fluffy => Fluffy
end

instead you will have to do this when specifying the soap action:
soap_action "integer_to_string" :args => { :fluffy => FluffyContainer }, :return => :string

ActiveRecord models can also generate this options.
For now minoccurs is 0 by default , but will change to 1 if the attribute is required
maxoccurs is 1 by default . but will change to "unbounded" if is an array ( for serialized columns)
and nillable is set to true by default but will change to false if column is not nillable

I am not sure when ActiveRecord columns can have maxoccurs =0 for a column. But please let me know and i'll try to update the code for that too.

I know this will break everything , but i think this would be a big improvement.
I tested a bit the code, and everything seems fine. Please let me know what do you think, maybe this could be part of a major release or something.