Module: Mutils::Serialization::Methods::Attributes
- Defined in:
- lib/mutils/serialization/methods/attributes.rb
Overview
Module Attributes
Instance Method Summary collapse
- #add_single_attribute(method_name, options, is_method) ⇒ Object
- #attribute(method_name, options = {}, &proc) ⇒ Object
- #attributes(*attributes_list) ⇒ Object
- #custom_method(method_name, options = {}) ⇒ Object
- #custom_methods(*attributes_list) ⇒ Object
- #parse_attributes_methods(list, is_method) ⇒ Object
Instance Method Details
#add_single_attribute(method_name, options, is_method) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/mutils/serialization/methods/attributes.rb', line 43 def add_single_attribute(method_name, , is_method) self.attributes_to_serialize = {} if attributes_to_serialize.nil? always_include = [:always_include].nil? ? false : [:always_include] value = { method: is_method, always_include: always_include, if: [:if] } attributes_to_serialize[method_name] = value end |
#attribute(method_name, options = {}, &proc) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mutils/serialization/methods/attributes.rb', line 27 def attribute(method_name, = {}, &proc) raise "if: should be a Proc object for attribute #{method_name}" if [:if] && ![:if].instance_of?(Proc) if proc.instance_of? Proc self.attributes_to_serialize_blocks = {} if attributes_to_serialize_blocks.nil? [:block] = proc attributes_to_serialize_blocks[method_name] = else add_single_attribute(method_name, , false) end end |
#attributes(*attributes_list) ⇒ Object
11 12 13 |
# File 'lib/mutils/serialization/methods/attributes.rb', line 11 def attributes(*attributes_list) parse_attributes_methods(attributes_list, false) end |
#custom_method(method_name, options = {}) ⇒ Object
39 40 41 |
# File 'lib/mutils/serialization/methods/attributes.rb', line 39 def custom_method(method_name, = {}) add_single_attribute(method_name, , true) end |
#custom_methods(*attributes_list) ⇒ Object
15 16 17 |
# File 'lib/mutils/serialization/methods/attributes.rb', line 15 def custom_methods(*attributes_list) parse_attributes_methods(attributes_list, true) end |
#parse_attributes_methods(list, is_method) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/mutils/serialization/methods/attributes.rb', line 19 def parse_attributes_methods(list, is_method) self.attributes_to_serialize = {} if attributes_to_serialize.nil? list&.each do |attr| value = { method: is_method, always_include: true } attributes_to_serialize[attr] = value end end |