Sha256: e13dbc281109b6c203f9966f83e3e86e258534aa1e8c2375f35359fc5d4e85a4

Contents?: true

Size: 1.33 KB

Versions: 22

Compression:

Stored size: 1.33 KB

Contents

# typed: strict
class ActiveFlagPlugin < SorbetRails::ModelPlugins::Base
  sig { params(root: Parlour::RbiGenerator::Namespace).void.override }
  def generate(root)
    # method added here: https://github.com/kenn/active_flag/blob/master/lib/active_flag.rb#L13
    return unless model_class.respond_to?(:active_flags)

    module_name = self.model_module_name("GeneratedActiveFlagMethods")
    module_rbi = root.create_module(module_name)

    model_class_rbi = root.create_class(self.model_class_name)
    model_class_rbi.create_include(module_name)

    module_rbi.create_method(
      "active_flags",
      return_type: "T::Hash[Symbol, ActiveFlag::Definition]",
      class_method: true
    )

    active_flag_keys(model_class).each do |flag|
      module_rbi.create_method(
        flag.to_s,
        return_type: "::ActiveFlag::Value"
      )

      module_rbi.create_method(
        "#{flag}=",
        parameters: [
          Parameter.new("value", type: "T::Array[Symbol]")
        ],
        return_type: nil
      )

      module_rbi.create_method(
        flag.to_s.pluralize,
        return_type: "::ActiveFlag::Definition",
        class_method: true
      )
    end
  end

  sig { params(model_class: T.class_of(ActiveRecord::Base)).returns(T::Array[Symbol]) }
  def active_flag_keys(model_class)
    T.unsafe(model_class).active_flags.keys
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sorbet-rails-0.7.34 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.33 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.32 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.31 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.27 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.26 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.25 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.24 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.23 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.22 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.20 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.19 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.18 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.5 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.4 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.3 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.2 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.1 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.7.0 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb
sorbet-rails-0.6.5.1 lib/sorbet-rails/gem_plugins/active_flag_plugin.rb