Class: Azeroth::Decorator
- Inherits:
-
Object
- Object
- Azeroth::Decorator
- Extended by:
- ClassMethods
- Defined in:
- lib/azeroth/decorator.rb,
lib/azeroth/decorator/options.rb,
lib/azeroth/decorator/hash_builder.rb,
lib/azeroth/decorator/class_methods.rb,
lib/azeroth/decorator/method_builder.rb,
lib/azeroth/decorator/key_value_extractor.rb
Overview
Class to be used when decorating outputs
Defined Under Namespace
Modules: ClassMethods Classes: HashBuilder, KeyValueExtractor, MethodBuilder, Options
Class Method Summary collapse
-
.expose(attribute, **options_hash) ⇒ Array<Symbol>
Expose attributes on json decorated.
Instance Method Summary collapse
-
#as_json(*args) ⇒ Hash
private
Builds hash / Json from the given object.
-
#initialize(object) ⇒ Decorator
constructor
private
A new instance of Decorator.
Methods included from ClassMethods
Constructor Details
#initialize(object) ⇒ Decorator #initialize(array) ⇒ Decorator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Decorator.
86 87 88 |
# File 'lib/azeroth/decorator.rb', line 86 def initialize(object) @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Method called when method is missing
This delegates method calls to the given object
152 153 154 155 156 157 158 |
# File 'lib/azeroth/decorator.rb', line 152 def method_missing(method_name, *args) if object.respond_to?(method_name) object.public_send(method_name, *args) else super end end |
Class Method Details
.expose(attribute, **options_hash) ⇒ Array<Symbol>
Expose attributes on json decorated
|
# File 'lib/azeroth/decorator.rb', line 51
|
Instance Method Details
#as_json(*args) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds hash / Json from the given object
When object is an iterator, decoration is applied to each and an array is returned
100 101 102 103 104 105 106 |
# File 'lib/azeroth/decorator.rb', line 100 def as_json(*args) return nil if object.nil? return array_as_json(*args) if enum? HashBuilder.new(self).as_json end |