Class: GlobalRegistry::Bindings::Options::RelationshipInstanceOptions
- Inherits:
-
Object
- Object
- GlobalRegistry::Bindings::Options::RelationshipInstanceOptions
- Defined in:
- lib/global_registry_bindings/options/relationship_instance_options.rb
Instance Method Summary collapse
- #client_integration_id ⇒ Object
- #condition?(cond) ⇒ Boolean
- #exclude ⇒ Object
- #fields ⇒ Object
- #id_value ⇒ Object
- #id_value=(value) ⇒ Object
- #id_value? ⇒ Boolean
-
#initialize(type, model) ⇒ RelationshipInstanceOptions
constructor
A new instance of RelationshipInstanceOptions.
- #primary ⇒ Object
- #primary_id_value ⇒ Object
- #primary_name ⇒ Object
- #primary_type ⇒ Object
- #related ⇒ Object
- #related_id_value ⇒ Object
- #related_name ⇒ Object
- #related_type ⇒ Object
- #type ⇒ Object
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_id ⇒ Object
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
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 |
#exclude ⇒ Object
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 |
#fields ⇒ Object
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_value ⇒ Object
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
31 32 33 |
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 31 def id_value? @model.send "#{id_column}?" end |
#primary ⇒ Object
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_value ⇒ Object
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_name ⇒ Object
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_type ⇒ Object
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 |
#related ⇒ Object
79 80 81 |
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 79 def @model.send(@class_options.) if @class_options..present? end |
#related_id_value ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 87 def option = @class_options. case option when Proc option.call(@model, type) when Symbol @model.send(option, type) else &.global_registry_entity&.id_value end end |
#related_name ⇒ Object
99 100 101 |
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 99 def @class_options. || end |
#related_type ⇒ Object
83 84 85 |
# File 'lib/global_registry_bindings/options/relationship_instance_options.rb', line 83 def @class_options. || &.global_registry_entity&.type end |
#type ⇒ Object
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 |