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

Version Path
sorbet-rails-0.7.27 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.26 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.25 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.24 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.23 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.22 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.20 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.19 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.18 lib/sorbet-rails/gem_plugins/aasm_plugin.rb
sorbet-rails-0.7.5 lib/sorbet-rails/gem_plugins/aasm_plugin.rb