Module: Pragma::Decorator::Association::ClassMethods

Defined in:
lib/pragma/decorator/association.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#associationsHash{Symbol => Reflection}

Returns the associations defined on this decorator.

Returns:

  • (Hash{Symbol => Reflection})

    the associations



31
32
33
# File 'lib/pragma/decorator/association.rb', line 31

def associations
  @associations ||= {}
end

#belongs_to(property_name, options = {}) ⇒ Object

Defines a belongs_to association on this decorator.

This will first create an association definition and then define a new property with the name of the association.

This method supports all the usual options accepted by #property.

Parameters:

  • property_name (Symbol)

    name of the association

  • options (Hash) (defaults to: {})

    the association’s options



44
45
46
# File 'lib/pragma/decorator/association.rb', line 44

def belongs_to(property_name, options = {})
  define_association :belongs_to, property_name, options
end

#has_one(property_name, options = {}) ⇒ Object

Defines a has_one association on this decorator.

This will first create an association definition and then define a new property with the name of the association.

This method supports all the usual options accepted by #property.

Parameters:

  • property_name (Symbol)

    name of the association

  • options (Hash) (defaults to: {})

    the association’s options



57
58
59
# File 'lib/pragma/decorator/association.rb', line 57

def has_one(property_name, options = {}) # rubocop:disable Naming/PredicateName
  define_association :has_one, property_name, options
end