Module: XMLable::Mixins::Castable

Defined in:
lib/xmlable/mixins/castable.rb

Overview

Castable module contains the logic that helps to cast values from

different forms to XML/JSON and back.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/xmlable/mixins/castable.rb', line 8

def self.included(base)
  base.send(:extend, ClassMethods)
end

Instance Method Details

#__cast(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Cast object from XML value

Parameters:

  • val (String)

Returns:



21
22
23
# File 'lib/xmlable/mixins/castable.rb', line 21

def __cast(val)
  val
end

#__empty(val) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Is this object empty?

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/xmlable/mixins/castable.rb', line 71

def __empty(val)
  val.respond_to?(:empty?) && val.empty? ||
    val.is_a?(String) && val == '' ||
    val.nil?
end

#__export(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Export value to XML/JSON

Parameters:

Returns:



34
35
36
# File 'lib/xmlable/mixins/castable.rb', line 34

def __export(val)
  val.to_s
end

#__export_to_json(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Export value to JSON

Parameters:

Returns:



60
61
62
# File 'lib/xmlable/mixins/castable.rb', line 60

def __export_to_json(val)
  __export(val).to_s
end

#__export_to_xml(val) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Export value to XML

Parameters:

Returns:

  • (String)


47
48
49
# File 'lib/xmlable/mixins/castable.rb', line 47

def __export_to_xml(val)
  __export(val).to_s
end