Module: Compony::ModelMixin
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/compony/model_mixin.rb
Instance Method Summary collapse
- #feasibility_messages(action_name) ⇒ Object
-
#feasible?(action_name, recompute: false) ⇒ Boolean
Retrieves feasibility for the given instance Calling this with an invalid action name will always return true.
-
#field(field_name, controller) ⇒ Object
Calls value_for on the desired field.
- #full_feasibility_messages(action_name) ⇒ Object
Instance Method Details
#feasibility_messages(action_name) ⇒ Object
86 87 88 89 90 |
# File 'lib/compony/model_mixin.rb', line 86 def (action_name) action_name = action_name.to_sym feasible?(action_name) if &.[](action_name).nil? # If feasibility check hasn't been performed yet for this action, perform it now return [action_name] end |
#feasible?(action_name, recompute: false) ⇒ Boolean
Retrieves feasibility for the given instance Calling this with an invalid action name will always return true.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/compony/model_mixin.rb', line 68 def feasible?(action_name, recompute: false) action_name = action_name.to_sym ||= {} # Abort if check has already run and recompute is false if [action_name].nil? || recompute # Lazily autodetect feasibilities self.class.autodetect_feasibilities! # Compute feasibility and gather messages [action_name] = [] feasibility_preventions[action_name]&.each do |prevention| if instance_exec(&prevention.block) [action_name] << prevention. end end end return [action_name].none? end |
#field(field_name, controller) ⇒ Object
Calls value_for on the desired field. Do not confuse with the static method field.
99 100 101 |
# File 'lib/compony/model_mixin.rb', line 99 def field(field_name, controller) fields[field_name.to_sym].value_for(self, controller:) end |
#full_feasibility_messages(action_name) ⇒ Object
92 93 94 95 96 |
# File 'lib/compony/model_mixin.rb', line 92 def (action_name) text = (action_name).join(', ').upcase_first text += '.' if text.present? return text end |