Class: GlobalRegistry::Bindings::Options::EntityInstanceOptions

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

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ EntityInstanceOptions

Returns a new instance of EntityInstanceOptions.



17
18
19
20
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 17

def initialize(model)
  @model = model
  @class_options = model.class.global_registry_entity
end

Instance Method Details

#condition?(cond) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#excludeObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 64

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



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 76

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



22
23
24
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 22

def id_value
  @model.send id_column
end

#id_value=(value) ⇒ Object



26
27
28
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 26

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

#id_value?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 30

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

#parentObject



39
40
41
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 39

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

#parent_classObject



43
44
45
46
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 43

def parent_class
  return if @class_options.parent.blank?
  @class_options.parent_class
end

#parent_id_valueObject



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

def parent_id_value
  parent&.global_registry_entity&.id_value
end

#parent_is_self?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 60

def parent_is_self?
  @class_options.parent.present? && parent_class == @model.class
end

#parent_required?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 56

def parent_required?
  @class_options.parent.present? && !parent_is_self?
end

#parent_typeObject



48
49
50
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 48

def parent_type
  parent&.global_registry_entity&.type
end

#typeObject



34
35
36
37
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 34

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