Module: FleetVentures::Serialization
- Defined in:
- lib/rdf_for_sqlite.rb
Overview
Rather than going through a Rails commit process, I’ve just hijacked this code and run it as my own module. For Spira models, the attributes hash uses symbols rather than strings, and so I have to map them to strings on line 15 below.
Instance Method Summary collapse
Instance Method Details
#serializable_hash(options = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rdf_for_sqlite.rb', line 19 def serializable_hash( = nil) ||= {} [:only] = Array.wrap([:only]).map { |n| n.to_s } [:except] = Array.wrap([:except]).map { |n| n.to_s } attribute_names = attributes.keys.map {|k| k.to_s}.sort if [:only].any? attribute_names &= [:only] elsif [:except].any? attribute_names -= [:except] end method_names = Array.wrap([:methods]).inject([]) do |methods, name| methods << name if respond_to?(name.to_s) methods end (attribute_names + method_names).inject({}) { |hash, name| hash[name] = send(name) hash } end |