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
-
#__cast(val) ⇒ Object
private
Cast object from XML value.
-
#__empty(val) ⇒ Boolean
private
Is this object empty?.
-
#__export(val) ⇒ Object
private
Export value to XML/JSON.
-
#__export_to_json(val) ⇒ Object
private
Export value to JSON.
-
#__export_to_xml(val) ⇒ String
private
Export value to XML.
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
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?
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
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
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
47 48 49 |
# File 'lib/xmlable/mixins/castable.rb', line 47 def __export_to_xml(val) __export(val).to_s end |