Module: ActiveGraph::Shared::RelTypeConverters
- Included in:
- Node::HasN::Association, Relationship::Types::ClassMethods
- Defined in:
- lib/active_graph/shared/rel_type_converters.rb
Overview
This module controls changes to relationship type based on ActiveGraph::Config.transform_rel_type. It's used whenever a rel type is automatically determined based on Relationship model name or association type.
Class Method Summary collapse
-
.decorated_rel_type(type) ⇒ String
A string that conforms to the set rel type conversion setting.
-
.rel_transformer ⇒ Object
Determines how relationship types should look when inferred based on association or Relationship model name.
Instance Method Summary collapse
Class Method Details
.decorated_rel_type(type) ⇒ String
Returns A string that conforms to the set rel type conversion setting.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/active_graph/shared/rel_type_converters.rb', line 25 def decorated_rel_type(type) type = type.to_s decorated_type = case rel_transformer when :upcase type.underscore.upcase when :downcase type.underscore.downcase when :legacy "##{type.underscore.downcase}" when :none type else type.underscore.upcase end decorated_type.tap { |s| s.gsub!('/', '::') if type.include?('::') } end |
.rel_transformer ⇒ Object
Determines how relationship types should look when inferred based on association or Relationship model name. With the exception of `:none`, all options will call `underscore`, so `ThisClass` becomes `this_class`, with capitalization determined by the specific option passed. Valid options:
-
:upcase - `:this_class`, `ThisClass`, `thiS_claSs` (if you don't like yourself) becomes `THIS_CLASS`
-
:downcase - same as above, only… downcased.
-
:legacy - downcases and prepends `#`, so ThisClass becomes `#this_class`
-
:none - uses the string version of whatever is passed with no modifications
19 20 21 |
# File 'lib/active_graph/shared/rel_type_converters.rb', line 19 def rel_transformer @rel_transformer ||= ActiveGraph::Config[:transform_rel_type].nil? ? :upcase : ActiveGraph::Config[:transform_rel_type] end |
Instance Method Details
#decorated_rel_type(type) ⇒ Object
6 7 8 |
# File 'lib/active_graph/shared/rel_type_converters.rb', line 6 def decorated_rel_type(type) @decorated_rel_type ||= ActiveGraph::Shared::RelTypeConverters.decorated_rel_type(type) end |