Module: Caprese::Serializer::Links::ClassMethods
- Defined in:
- lib/caprese/serializer/concerns/links.rb
Instance Method Summary collapse
- #belongs_to(name, options = {}, &block) ⇒ Object
-
#caprese_default_url_options_host ⇒ Object
Fetches the host from Caprese.config.default_url_options or fails if it is not set.
-
#has_many(name, options = {}, &block) ⇒ Object
Overridden so we can define relationship links without any code in a specific serializer.
- #has_one(name, options = {}, &block) ⇒ Object
Instance Method Details
#belongs_to(name, options = {}, &block) ⇒ Object
50 51 52 |
# File 'lib/caprese/serializer/concerns/links.rb', line 50 def belongs_to(name, = {}, &block) super name, , &build_association_block(name) end |
#caprese_default_url_options_host ⇒ Object
Note:
default_url_options is used to render the host in links that are serialized in the response
Fetches the host from Caprese.config.default_url_options or fails if it is not set
28 29 30 31 32 |
# File 'lib/caprese/serializer/concerns/links.rb', line 28 def Caprese.config..fetch(:host) do fail 'Caprese requires that config.default_url_options[:host] be set when rendering links.' end end |
#has_many(name, options = {}, &block) ⇒ Object
Overridden so we can define relationship links without any code in a specific serializer
36 37 38 39 40 41 42 |
# File 'lib/caprese/serializer/concerns/links.rb', line 36 def has_many(name, = {}, &block) super name, , &build_association_block(name) define_method name do self.relationship_scope(name, object.send(name)) end end |
#has_one(name, options = {}, &block) ⇒ Object
45 46 47 |
# File 'lib/caprese/serializer/concerns/links.rb', line 45 def has_one(name, = {}, &block) super name, , &build_association_block(name) end |