Module: Caprese::Serializer::Links::ClassMethods

Defined in:
lib/caprese/serializer/concerns/links.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, options = {}, &block) ⇒ Object

See Also:



50
51
52
# File 'lib/caprese/serializer/concerns/links.rb', line 50

def belongs_to(name, options = {}, &block)
  super name, options, &build_association_block(name)
end

#caprese_default_url_options_hostObject

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_default_url_options_host
  Caprese.config.default_url_options.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, options = {}, &block)
  super name, options, &build_association_block(name)

  define_method name do
    self.relationship_scope(name, object.send(name))
  end
end

#has_one(name, options = {}, &block) ⇒ Object

See Also:



45
46
47
# File 'lib/caprese/serializer/concerns/links.rb', line 45

def has_one(name, options = {}, &block)
  super name, options, &build_association_block(name)
end