Module: Alba::Resource
Overview
This module represents what should be serialized
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Instance Attribute Summary collapse
-
#object ⇒ Object
included
from InstanceMethods
readonly
Returns the value of attribute object.
-
#params ⇒ Object
included
from InstanceMethods
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.association(name, condition = nil, resource: nil, key: nil, params: {}, **options, &block) ⇒ void
(also: #one, #many, #has_one, #has_many)
extended
from ClassMethods
Set association.
-
.attribute(name, **options, &block) ⇒ void
extended
from ClassMethods
Set an attribute with the given block.
-
.attributes(*attrs, if: nil, **attrs_with_types) ⇒ void
extended
from ClassMethods
Set multiple attributes at once.
-
.collection_key(key) ⇒ Object
extended
from ClassMethods
Sets key for collection serialization.
-
.helper(mod = @_helper || Module.new, &block) ⇒ Object
extended
from ClassMethods
Define helper methods.
-
.layout(file: nil, inline: nil) ⇒ Object
extended
from ClassMethods
Set layout.
-
.meta(key = :meta, &block) ⇒ Object
extended
from ClassMethods
Set metadata.
-
.method_added(method_name) ⇒ Object
extended
from ClassMethods
This ‘method_added` is used for defining “resource methods”.
-
.nested_attribute(name, **options, &block) ⇒ void
(also: #nested)
extended
from ClassMethods
Set a nested attribute with the given block.
-
.on_error(handler = nil, &block) ⇒ Object
extended
from ClassMethods
Set error handler If this is set it’s used as a error handler overriding global one.
-
.on_nil(&block) ⇒ Object
extended
from ClassMethods
Set nil handler.
-
.prefer_object_method! ⇒ Object
extended
from ClassMethods
DSL for alias, purely for readability.
-
.prefer_resource_method! ⇒ Object
extended
from ClassMethods
DSL for alias, purely for readability.
-
.root_key(key, key_for_collection = nil) ⇒ Object
extended
from ClassMethods
Set root key.
-
.root_key! ⇒ Object
extended
from ClassMethods
Set root key to true.
-
.root_key_for_collection(key) ⇒ Object
extended
from ClassMethods
Set root key for collection.
-
.transform_keys(type, root: true, cascade: true) ⇒ Object
extended
from ClassMethods
Transform keys as specified type.
-
.transform_keys!(type) ⇒ Object
extended
from ClassMethods
Transform keys as specified type AFTER the class is defined Note that this is an experimental API and may be removed/changed.
Instance Method Summary collapse
-
#as_json(_options = {}, root_key: nil, meta: {}) ⇒ Hash
included
from InstanceMethods
Returns a Hash corresponding InstanceMethods#serialize.
- #initialize(object, params: {}, within: WITHIN_DEFAULT) ⇒ Object included from InstanceMethods
-
#serializable_hash ⇒ Hash
(also: #to_h)
included
from InstanceMethods
A Hash for serialization.
-
#serialize(root_key: nil, meta: {}) ⇒ String
included
from InstanceMethods
Serialize object into JSON string.
-
#to_json(options = {}, root_key: nil, meta: {}) ⇒ Object
included
from InstanceMethods
For Rails compatibility The first options is a dummy parameter.
Instance Attribute Details
#object ⇒ Object (readonly) Originally defined in module InstanceMethods
Returns the value of attribute object.
#params ⇒ Object (readonly) Originally defined in module InstanceMethods
Returns the value of attribute params.
Class Method Details
.association(name, condition = nil, resource: nil, key: nil, params: {}, **options, &block) ⇒ void Also known as: one, many, has_one, has_many Originally defined in module ClassMethods
This method returns an undefined value.
Set association
.attribute(name, **options, &block) ⇒ void Originally defined in module ClassMethods
This method returns an undefined value.
Set an attribute with the given block
.attributes(*attrs, if: nil, **attrs_with_types) ⇒ void Originally defined in module ClassMethods
This method returns an undefined value.
Set multiple attributes at once
.collection_key(key) ⇒ Object Originally defined in module ClassMethods
Sets key for collection serialization
.helper(mod = @_helper || Module.new, &block) ⇒ Object Originally defined in module ClassMethods
Define helper methods
.layout(file: nil, inline: nil) ⇒ Object Originally defined in module ClassMethods
Set layout
.meta(key = :meta, &block) ⇒ Object Originally defined in module ClassMethods
Set metadata
.method_added(method_name) ⇒ Object Originally defined in module ClassMethods
This ‘method_added` is used for defining “resource methods”
.nested_attribute(name, **options, &block) ⇒ void Also known as: nested Originally defined in module ClassMethods
This method returns an undefined value.
Set a nested attribute with the given block
.on_error(handler = nil, &block) ⇒ Object Originally defined in module ClassMethods
Set error handler If this is set it’s used as a error handler overriding global one
.on_nil(&block) ⇒ Object Originally defined in module ClassMethods
Set nil handler
.prefer_object_method! ⇒ Object Originally defined in module ClassMethods
DSL for alias, purely for readability
.prefer_resource_method! ⇒ Object Originally defined in module ClassMethods
DSL for alias, purely for readability
.root_key(key, key_for_collection = nil) ⇒ Object Originally defined in module ClassMethods
Set root key
.root_key! ⇒ Object Originally defined in module ClassMethods
Set root key to true
.root_key_for_collection(key) ⇒ Object Originally defined in module ClassMethods
Set root key for collection
.transform_keys(type, root: true, cascade: true) ⇒ Object Originally defined in module ClassMethods
Transform keys as specified type
.transform_keys!(type) ⇒ Object Originally defined in module ClassMethods
Transform keys as specified type AFTER the class is defined Note that this is an experimental API and may be removed/changed
Instance Method Details
#as_json(_options = {}, root_key: nil, meta: {}) ⇒ Hash Originally defined in module InstanceMethods
Returns a Hash corresponding #serialize
#initialize(object, params: {}, within: WITHIN_DEFAULT) ⇒ Object Originally defined in module InstanceMethods
#serializable_hash ⇒ Hash Also known as: to_h Originally defined in module InstanceMethods
A Hash for serialization
#serialize(root_key: nil, meta: {}) ⇒ String Originally defined in module InstanceMethods
Serialize object into JSON string
#to_json(options = {}, root_key: nil, meta: {}) ⇒ Object Originally defined in module InstanceMethods
For Rails compatibility The first options is a dummy parameter