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.
- #full_feasibility_messages(action_name) ⇒ Object
Instance Method Details
#feasibility_messages(action_name) ⇒ Object
76 77 78 79 80 |
# File 'lib/compony/model_mixin.rb', line 76 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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/compony/model_mixin.rb', line 58 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 |
#full_feasibility_messages(action_name) ⇒ Object
82 83 84 85 86 |
# File 'lib/compony/model_mixin.rb', line 82 def (action_name) text = (action_name).join(', ').upcase_first text += '.' if text.present? return text end |