Class: AdjustableSchema::ActiveRecord::Association

Inherits:
Struct
  • Object
show all
Defined in:
lib/adjustable_schema/active_record/association.rb,
lib/adjustable_schema/active_record/association/naming.rb

Defined Under Namespace

Modules: Scopes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directionObject

Returns the value of attribute direction

Returns:

  • (Object)

    the current value of direction



3
4
5
# File 'lib/adjustable_schema/active_record/association.rb', line 3

def direction
  @direction
end

#ownerObject

Returns the value of attribute owner

Returns:

  • (Object)

    the current value of owner



3
4
5
# File 'lib/adjustable_schema/active_record/association.rb', line 3

def owner
  @owner
end

#roleObject

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



3
4
5
# File 'lib/adjustable_schema/active_record/association.rb', line 3

def role
  @role
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



3
4
5
# File 'lib/adjustable_schema/active_record/association.rb', line 3

def target
  @target
end

Instance Method Details

#child?Boolean

Returns:

  • (Boolean)


39
# File 'lib/adjustable_schema/active_record/association.rb', line 39

def child?     = (recursive? and source?)

#defineObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/adjustable_schema/active_record/association.rb', line 7

def define
	name.tap do |association_name|
		association = self # save context

		has_many association_name, **(options = {
				through:     define_relationships,
				source:      direction,
				source_type: target.base_class.name,
				class_name:  target.name
		}) do
			include Scopes
			include Scopes::Recursive if association.recursive?
		end

		define_scopes
		define_methods

		unless role
			# HACK: using `try` to overcome a Rails bug
			# (see https://github.com/rails/rails/issues/40109)
			has_many roleless_name, -> { try :roleless }, **options if
					child?

			define_role_methods
		end
	end
end

#hierarchy?Boolean

Returns:

  • (Boolean)


41
# File 'lib/adjustable_schema/active_record/association.rb', line 41

def hierarchy? = (child? and roleless?)

#parent?Boolean

Returns:

  • (Boolean)


40
# File 'lib/adjustable_schema/active_record/association.rb', line 40

def parent?    = (recursive? and target?)

#recursive?Boolean

Returns:

  • (Boolean)


35
# File 'lib/adjustable_schema/active_record/association.rb', line 35

def recursive? = target == owner

#roleless?Boolean

Returns:

  • (Boolean)


36
# File 'lib/adjustable_schema/active_record/association.rb', line 36

def roleless?  = !role

#source?Boolean

Returns:

  • (Boolean)


37
# File 'lib/adjustable_schema/active_record/association.rb', line 37

def source?    = direction == :source

#target?Boolean

Returns:

  • (Boolean)


38
# File 'lib/adjustable_schema/active_record/association.rb', line 38

def target?    = direction == :target