Sha256: bad7c945374a2b3433d0b25443934efeb7fdf206fd56dacd00a01bf1614db770
Contents?: true
Size: 1.18 KB
Versions: 10
Compression:
Stored size: 1.18 KB
Contents
# typed: false class AasmPlugin < SorbetRails::ModelPlugins::Base sig { override.params(root: Parlour::RbiGenerator::Namespace).void } def generate(root) return unless @model_class.include?(::AASM) model_rbi = root.create_class( model_class_name ) aasm_events = @model_class.aasm.events.map(&:name) aasm_states = @model_class.aasm.states.map(&:name) # If you have an event like :bazify, you get these methods: # - `may_bazify?` # - `bazify` # - `bazify!` # - `bazify_without_validation!` aasm_events.each do |event| model_rbi.create_method( "may_#{event}?", return_type: 'T::Boolean' ) model_rbi.create_method( event.to_s, return_type: 'T::Boolean' ) model_rbi.create_method( "#{event}!", return_type: 'T::Boolean' ) model_rbi.create_method( "#{event}_without_validation!", return_type: 'T::Boolean' ) end # - If you have a state like :baz, you get these methods: # - `baz?` aasm_states.each do |state| model_rbi.create_method( "#{state}?", return_type: 'T::Boolean' ) end end end
Version data entries
10 entries across 10 versions & 1 rubygems