Class: GlobalRegistry::Bindings::Options::RelationshipInstanceOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/global_registry_bindings/options/relationship_instance_options.rb

Instance Method Summary collapse

Constructor Details

#initialize(type, model) ⇒ RelationshipInstanceOptions

Returns a new instance of RelationshipInstanceOptions.



18
19
20
21
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 18

def initialize(type, model)
  @model = model
  @class_options = model.class.global_registry_relationship(type)
end

Instance Method Details

#client_integration_idObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 40

def client_integration_id
  option = @class_options.client_integration_id
  case option
  when Proc
    option.call(@model)
  when Symbol
    @model.send(option, type)
  end
rescue ArgumentError
  @model.send(option)
end

#condition?(cond) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
133
134
135
136
137
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 127

def condition?(cond)
  option = @class_options.send(cond)
  case option
  when Proc
    option.call(type, @model)
  when Symbol
    @model.send(option, type, @model)
  else
    cond != :if
  end
end

#excludeObject



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 103

def exclude
  option = @class_options.exclude
  case option
  when Proc
    option.call(type, @model)
  when Symbol
    @model.send(option, type)
  else
    option
  end
end

#fieldsObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 115

def fields
  option = @class_options.fields
  case option
  when Proc
    option.call(type, @model)
  when Symbol
    @model.send(option, type)
  else
    option
  end
end

#id_valueObject



23
24
25
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 23

def id_value
  @model.send id_column
end

#id_value=(value) ⇒ Object



27
28
29
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 27

def id_value=(value)
  @model.send "#{id_column}=", value
end

#id_value?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 31

def id_value?
  @model.send "#{id_column}?"
end

#primaryObject



52
53
54
55
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 52

def primary
  return @model.send(@class_options.primary) if @class_options.primary.present?
  @model
end

#primary_id_valueObject



66
67
68
69
70
71
72
73
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 66

def primary_id_value
  case primary_binding
  when :entity
    primary&.global_registry_entity&.id_value
  else
    primary&.global_registry_relationship(primary_binding)&.id_value
  end
end

#primary_nameObject



75
76
77
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 75

def primary_name
  @class_options.primary_name || primary_type
end

#primary_typeObject



57
58
59
60
61
62
63
64
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 57

def primary_type
  case primary_binding
  when :entity
    primary&.global_registry_entity&.type
  else
    primary&.global_registry_relationship(primary_binding)&.type
  end
end


79
80
81
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 79

def related
  @model.send(@class_options.related) if @class_options.related.present?
end


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 87

def related_id_value
  option = @class_options.related_global_registry_id
  case option
  when Proc
    option.call(@model, type)
  when Symbol
    @model.send(option, type)
  else
    related&.global_registry_entity&.id_value
  end
end


99
100
101
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 99

def related_name
  @class_options.related_name || related_type
end


83
84
85
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 83

def related_type
  @class_options.related_type || related&.global_registry_entity&.type
end

#typeObject



35
36
37
38
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 35

def type
  t = @class_options.type
  t.is_a?(Proc) ? t.call(@model) : t
end