Class: AdjustableSchema::ActiveRecord::Association

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

Overview

:nodoc:

Defined Under Namespace

Modules: Hierarchy, Referenced, Roleless, Scopes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssociation

Returns a new instance of Association.



28
29
30
31
32
33
34
# File 'lib/adjustable_schema/active_record/association.rb', line 28

def initialize(...)
	super

	extend Roleless   if roleless?
	extend Hierarchy  if hierarchy?
	extend Referenced if source? and role and target.actor?
end

Instance Attribute Details

#directionObject

Returns the value of attribute direction

Returns:

  • (Object)

    the current value of direction



8
9
10
# File 'lib/adjustable_schema/active_record/association.rb', line 8

def direction
  @direction
end

#ownerObject

Returns the value of attribute owner

Returns:

  • (Object)

    the current value of owner



8
9
10
# File 'lib/adjustable_schema/active_record/association.rb', line 8

def owner
  @owner
end

#roleObject

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



8
9
10
# File 'lib/adjustable_schema/active_record/association.rb', line 8

def role
  @role
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



8
9
10
# File 'lib/adjustable_schema/active_record/association.rb', line 8

def target
  @target
end

Instance Method Details

#child?Boolean

Returns:

  • (Boolean)


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

def child?     = (recursive? and source?)

#defineObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/adjustable_schema/active_record/association.rb', line 36

def define
	association = self # save the context

	has_many name, **options do
		include Scopes
		include Scopes::Recursive if association.recursive?
	end or return

	define_scopes
	define_methods
end

#hierarchy?Boolean

Returns:

  • (Boolean)


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

def hierarchy? = (child? and roleless?)

#parent?Boolean

Returns:

  • (Boolean)


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

def parent?    = (recursive? and target?)

#recursive?Boolean

Returns:

  • (Boolean)


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

def recursive? = target == owner

#roleless?Boolean

Returns:

  • (Boolean)


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

def roleless?  = !role

#source?Boolean

Returns:

  • (Boolean)


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

def source?    = direction == :source

#target?Boolean

Returns:

  • (Boolean)


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

def target?    = direction == :target