Module: CerealBox
- Defined in:
- lib/cereal_box.rb,
lib/cereal_box/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
- #apply(message, options = {}) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #as_xml(options = {}) ⇒ Object
- #cereal_box_node_name ⇒ Object
- #initialize(base) ⇒ Object
- #serializable_hash(options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 |
# File 'lib/cereal_box.rb', line 5 def self.included(base) base.send(:attr_accessor, :cereal_box_base_instance) base.send(:attr_accessor, :cereal_box_previous_filter) end |
Instance Method Details
#apply(message, options = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/cereal_box.rb', line 30 def apply(, = {}) target = @cereal_box_previous_filter ? @cereal_box_previous_filter : @cereal_box_base_instance target.send(.to_sym, ).merge( { cereal_box_node_name => self.send(:attributes, @cereal_box_base_instance) } ) end |
#as_json(options = {}) ⇒ Object
22 23 24 |
# File 'lib/cereal_box.rb', line 22 def as_json( = {}) apply(:as_json, ) end |
#as_xml(options = {}) ⇒ Object
26 27 28 |
# File 'lib/cereal_box.rb', line 26 def as_xml( = {}) apply(:as_xml, ) end |
#cereal_box_node_name ⇒ Object
14 15 16 |
# File 'lib/cereal_box.rb', line 14 def cereal_box_node_name self.class.to_s.split(/(?=[A-Z])/).map{ |w| w.downcase }[0...-1].join("_").to_sym end |
#initialize(base) ⇒ Object
10 11 12 |
# File 'lib/cereal_box.rb', line 10 def initialize(base) @cereal_box_base_instance = base end |
#serializable_hash(options = {}) ⇒ Object
18 19 20 |
# File 'lib/cereal_box.rb', line 18 def serializable_hash( = {}) apply(:serializable_hash, ) end |