Class: GlobalRegistry::Bindings::Options::EntityInstanceOptions
- Inherits:
-
Object
- Object
- GlobalRegistry::Bindings::Options::EntityInstanceOptions
- Defined in:
- lib/global_registry_bindings/options/entity_instance_options.rb
Instance Method Summary collapse
- #condition?(cond) ⇒ Boolean
- #exclude ⇒ Object
- #fields ⇒ Object
- #id_value ⇒ Object
- #id_value=(value) ⇒ Object
- #id_value? ⇒ Boolean
-
#initialize(model) ⇒ EntityInstanceOptions
constructor
A new instance of EntityInstanceOptions.
- #parent ⇒ Object
- #parent_class ⇒ Object
- #parent_id_value ⇒ Object
- #parent_is_self? ⇒ Boolean
- #parent_required? ⇒ Boolean
- #parent_type ⇒ Object
- #type ⇒ Object
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
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 |
#exclude ⇒ Object
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 |
#fields ⇒ Object
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_value ⇒ Object
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
30 31 32 |
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 30 def id_value? @model.send "#{id_column}?" end |
#parent ⇒ Object
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_class ⇒ Object
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_value ⇒ Object
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
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
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_type ⇒ Object
48 49 50 |
# File 'lib/global_registry_bindings/options/entity_instance_options.rb', line 48 def parent_type parent&.global_registry_entity&.type end |
#type ⇒ Object
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 |