Module: LaserLemon::HotSerial::Serializer
- Defined in:
- lib/serializer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_includes_with_breakfast(&block) ⇒ Object
- #initialize_with_breakfast(record, options = nil) ⇒ Object
- #serializable_names_with_breakfast ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/serializer.rb', line 4 def self.included(base) puts 'Serializer' base.alias_method_chain :initialize, :breakfast base.alias_method_chain :add_includes, :breakfast base.alias_method_chain :serializable_names, :breakfast end |
Instance Method Details
#add_includes_with_breakfast(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/serializer.rb', line 26 def add_includes_with_breakfast(&block) if include_associations = .delete(:include) = include_associations.is_a?(Hash) associations = ? include_associations.keys : Array(include_associations) for association in associations records = case @record.class.reflect_on_association(association).macro when :has_many, :has_and_belongs_to_many @record.send(association).to_a when :has_one, :belongs_to @record.send(association) end unless records.nil? = ? include_associations[association] : {} .reverse_merge!(:style => [:style], :include => nil) opts = .except(:only, :except, :methods).merge() yield(association, records, opts) end end [:include] = include_associations end end |
#initialize_with_breakfast(record, options = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/serializer.rb', line 11 def initialize_with_breakfast(record, = nil) = record.class. = case when Hash .reverse_merge!(:style => record.class.default_serialization_style) = record.class..fetch([:style], ) .reverse_merge() else record.class..fetch(, ).merge(:style => ) end initialize_without_breakfast(record, ) end |
#serializable_names_with_breakfast ⇒ Object
51 52 53 |
# File 'lib/serializer.rb', line 51 def serializable_names_with_breakfast serializable_names_without_breakfast.sort_by(&:to_s) end |