Module: SmoothOperator::Serialization
- Included in:
- OpenStruct::Base
- Defined in:
- lib/smooth_operator/serialization.rb
Instance Method Summary collapse
-
#attributes ⇒ Object
alias :attributes :to_hash.
- #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
alias :attributes :to_hash
10 |
# File 'lib/smooth_operator/serialization.rb', line 10 def attributes; to_hash; end |
#read_attribute_for_serialization(attribute) ⇒ Object
18 19 20 |
# File 'lib/smooth_operator/serialization.rb', line 18 def read_attribute_for_serialization(attribute) send(attribute) end |
#serializable_hash(options = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smooth_operator/serialization.rb', line 22 def serializable_hash( = nil) hash = {} ||= {} attribute_names().each do |attribute_name| hash[attribute_name] = read_attribute_for_hashing(attribute_name, ) end method_names().each do |method_name| hash[method_name.to_s] = send(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
12 13 14 15 16 |
# File 'lib/smooth_operator/serialization.rb', line 12 def to_json( = nil) require 'json' unless defined? JSON JSON(serializable_hash() || {}) end |