Module: AdjustableSchema::ActiveRecord::Builder

Included in:
AdjustableSchema
Defined in:
lib/adjustable_schema/active_record/builder.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#relationship!(*models, roles: [], **mapping) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/adjustable_schema/active_record/builder.rb', line 6

def relationship! *models, roles: [], **mapping
	return relationship!({ **Hash[*models], **mapping }, roles:) if
			mapping.any? # support keyword arguments syntax

	case models
	in [
			String | Symbol | Class => source,
			String | Symbol | Class => target,
	]
		define_relationship source, target,
				roles:
	in [ Hash => models ]
		define_relationships models,
				roles:
	in [ String | Symbol | Class => model ]
		define_recursive_relationship model,
				roles:
	end
end

#role!(name) ⇒ Object



26
27
28
# File 'lib/adjustable_schema/active_record/builder.rb', line 26

def role! name
	Relationship::Role.find_or_create_by! name:
end