Module: ActiveGraph::Relationship::Types::ClassMethods

Includes:
Shared::RelTypeConverters
Defined in:
lib/active_graph/relationship/types.rb

Instance Method Summary collapse

Methods included from Shared::RelTypeConverters

#decorated_rel_type, decorated_rel_type, rel_transformer

Instance Method Details

#_wrapped_classesObject


57
58
59
# File 'lib/active_graph/relationship/types.rb', line 57

def _wrapped_classes
  WRAPPED_CLASSES
end

#add_wrapped_class(type) ⇒ Object


61
62
63
64
# File 'lib/active_graph/relationship/types.rb', line 61

def add_wrapped_class(type)
  # WRAPPED_CLASSES[type.to_sym.downcase] = self.name
  _wrapped_classes[type.to_sym] = self.name
end

#inherited(subclass) ⇒ Object


27
28
29
# File 'lib/active_graph/relationship/types.rb', line 27

def inherited(subclass)
  subclass.type subclass.namespaced_model_name, true
end

#namespaced_model_nameObject


46
47
48
49
50
51
52
53
54
55
# File 'lib/active_graph/relationship/types.rb', line 46

def namespaced_model_name
  case ActiveGraph::Config[:module_handling]
  when :demodulize
    self.name.demodulize
  when Proc
    ActiveGraph::Config[:module_handling].call(self.name)
  else
    self.name
  end
end

#type(given_type = nil, auto = false) ⇒ Object

When called without arguments, it will return the current setting or supply a default. When called with arguments, it will change the current setting.

Parameters:

  • given_type (String) (defaults to: nil)

    sets the relationship type when creating relationships via this class

  • auto (Boolean) (defaults to: false)

    Should the given_type be changed in compliance with the gem's rel decorator setting?


35
36
37
38
39
40
41
42
43
44
# File 'lib/active_graph/relationship/types.rb', line 35

def type(given_type = nil, auto = false)
  case
  when !given_type && type?
    @type
  when given_type
    assign_type!(given_type, auto)
  else
    assign_type!(namespaced_model_name, true)
  end
end

#type?Boolean

Returns:


66
67
68
# File 'lib/active_graph/relationship/types.rb', line 66

def type?
  !!@type
end