Module: SmoothOperator::Serialization
- Included in:
- OpenStruct
- Defined in:
- lib/smooth_operator/serialization.rb
Defined Under Namespace
Modules: HelperMethods
Instance Method Summary collapse
- #attributes ⇒ Object
- #read_attribute_for_serialization(attribute) ⇒ Object
- #serializable_hash(options = nil) ⇒ Object
- #to_hash(options = nil) ⇒ Object
- #to_json(options = nil) ⇒ Object
Instance Method Details
#attributes ⇒ Object
9 |
# File 'lib/smooth_operator/serialization.rb', line 9 def attributes; to_hash; end |
#read_attribute_for_serialization(attribute) ⇒ Object
17 18 19 |
# File 'lib/smooth_operator/serialization.rb', line 17 def read_attribute_for_serialization(attribute) send(attribute) end |
#serializable_hash(options = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smooth_operator/serialization.rb', line 21 def serializable_hash( = nil) hash = {} ||= {} method_names = HelperMethods.method_names(self, ) attribute_names = HelperMethods.attribute_names(self, ) attribute_names.each do |attribute_name| attribute_name, attribute_value = HelperMethods .serialize_normal_or_rails_way(self, attribute_name, ) hash[attribute_name] = attribute_value end method_names.each do |method_name| hash[method_name.to_s] = HelperMethods.serialize_normal_attribute(send(method_name), method_name, [method_name]) end hash end |
#to_hash(options = nil) ⇒ Object
5 6 7 |
# File 'lib/smooth_operator/serialization.rb', line 5 def to_hash( = nil) Helpers.symbolyze_keys(serializable_hash() || {}) end |
#to_json(options = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/smooth_operator/serialization.rb', line 11 def to_json( = nil) require 'json' unless defined? JSON JSON(serializable_hash() || {}) end |