Module: Serializable::InstanceMethods
- Defined in:
- lib/acts_as_serializable.rb
Overview
This module contains instance methods
Instance Method Summary collapse
- #serialize(builder, options = {}, &block) ⇒ Object
- #serialize_for(builder, options = {}, &block) ⇒ Object
- #to_hash(options = {}, &block) ⇒ Object
- #to_json(options = {}, &block) ⇒ Object
- #to_xml(options = {}, &block) ⇒ Object
Instance Method Details
#serialize(builder, options = {}, &block) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/acts_as_serializable.rb', line 119 def serialize(builder, = {}, &block) if version_number = [:version] version = version_number.is_a?(Serializable::Version) ? version_number : Version.new(version_number) if found_version = self.class.serialization_versions.find_version(version) return self.send("serialize_to_version_#{found_version.to_s_underscored}", builder, , &block) else raise "Version #{version} given but no serialization method found" end else if version = self.class.default_serialization_version return self.send("serialize_to_version_#{version.to_s_underscored}", builder, , &block) else raise "No serialization method found" end end end |
#serialize_for(builder, options = {}, &block) ⇒ Object
136 137 138 |
# File 'lib/acts_as_serializable.rb', line 136 def serialize_for(builder, = {}, &block) self.send(builder.serialization_method!, , &block) end |
#to_hash(options = {}, &block) ⇒ Object
107 108 109 |
# File 'lib/acts_as_serializable.rb', line 107 def to_hash( = {}, &block) serialize(Builder::HashStructure.new, , &block) end |
#to_json(options = {}, &block) ⇒ Object
111 112 113 |
# File 'lib/acts_as_serializable.rb', line 111 def to_json( = {}, &block) serialize(Builder::HashStructure.new, , &block).to_json end |
#to_xml(options = {}, &block) ⇒ Object
115 116 117 |
# File 'lib/acts_as_serializable.rb', line 115 def to_xml( = {}, &block) serialize(Builder::XmlMarkup.new, , &block) end |