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
83 84 85 86 87 |
# File 'lib/compony/model_mixin.rb', line 83 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/compony/model_mixin.rb', line 65 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.
96 97 98 |
# File 'lib/compony/model_mixin.rb', line 96 def field(field_name, controller) fields[field_name.to_sym].value_for(self, controller:) end |
#full_feasibility_messages(action_name) ⇒ Object
89 90 91 92 93 |
# File 'lib/compony/model_mixin.rb', line 89 def (action_name) text = (action_name).join(', ').upcase_first text += '.' if text.present? return text end |