Skip to content

Commit

Permalink
Annotate Active Support string extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewater committed Nov 9, 2023
1 parent 1c29427 commit 4914b89
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"requires": [
"active_support",
"active_support/core_ext/array",
"active_support/core_ext/string",
"active_support/test_case"
]
},
Expand Down
137 changes: 137 additions & 0 deletions rbi/annotations/activesupport.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Object
sig { returns(T::Boolean) }
def blank?; end

sig { returns(FalseClass) }
def html_safe?; end

sig { returns(T.nilable(T.self_type)) }
def presence; end

Expand Down Expand Up @@ -238,6 +241,9 @@ class Numeric
sig { returns(FalseClass) }
def blank?; end

sig { returns(TrueClass) }
def html_safe?; end

# @shim: since `present?` is always true, `presence` always returns `self`
sig { returns(T.self_type) }
def presence; end
Expand All @@ -259,3 +265,134 @@ class Time
sig { returns(TrueClass) }
def present?; end
end

class String
sig { returns(TrueClass) }
def acts_like_string?; end

sig { params(position: T.any(Integer, Regexp, String, T::Range[Integer])).returns(T.nilable(T.self_type)) }
def at(position); end

sig { params(first_letter: Symbol).returns(T.self_type) }
def camelcase(first_letter = :upper); end

sig { params(first_letter: Symbol).returns(T.self_type) }
def camelize(first_letter = :upper); end

sig { returns(T.self_type) }
def classify; end

sig { returns(T.nilable(Module)) }
def constantize; end

sig { returns(T.self_type) }
def dasherize; end

sig { returns(T.self_type) }
def deconstantize; end

sig { returns(T.self_type) }
def demodulize; end

sig { params(string: String).returns(T::Boolean) }
def exclude?(string); end

sig { params(limit: Integer).returns(T.self_type) }
def first(limit = 1); end

sig { params(separate_class_name_and_id_with_underscore: T.untyped).returns(T.self_type) }
def foreign_key(separate_class_name_and_id_with_underscore = true); end

sig { params(position: Integer).returns(T.self_type) }
def from(position); end

sig { returns(ActiveSupport::SafeBuffer) }
def html_safe; end

sig { params(capitalize: T.untyped, keep_id_suffix: T.untyped).returns(T.self_type) }
def humanize(capitalize: true, keep_id_suffix: false); end

sig { params(zone: T.nilable(T.any(ActiveSupport::TimeZone, String))).returns(T.any(ActiveSupport::TimeWithZone, Time)) }
def in_time_zone(zone = ::Time.zone); end

sig { params(amount: Integer, indent_string: T.nilable(String), indent_empty_lines: T.untyped).returns(T.self_type) }
def indent(amount, indent_string = nil, indent_empty_lines = false); end

sig { params(amount: Integer, indent_string: T.nilable(String), indent_empty_lines: T.untyped).returns(T.nilable(T.self_type)) }
def indent!(amount, indent_string = nil, indent_empty_lines = false); end

sig { returns(ActiveSupport::StringInquirer) }
def inquiry; end

sig { returns(T::Boolean) }
def is_utf8?; end

sig { params(limit: Integer).returns(T.self_type) }
def last(limit = 1); end

sig { returns(ActiveSupport::Multibyte::Chars) }
def mb_chars; end

sig { params(separator: T.nilable(String), preserve_case: T.untyped, locale: T.nilable(Symbol)).returns(T.self_type) }
def parameterize(separator: "-", preserve_case: false, locale: nil); end

sig { params(count: T.nilable(T.any(Integer, Symbol)), locale: T.nilable(Symbol)).returns(T.self_type) }
def pluralize(count = nil, locale = :en); end

sig { params(patterns: T.nilable(T.any(Regexp, String))).returns(T.self_type) }
def remove(*patterns); end

sig { params(patterns: T.nilable(T.any(Regexp, String))).returns(T.self_type) }
def remove!(*patterns); end

sig { returns(T.nilable(Module)) }
def safe_constantize; end

sig { params(locale: T.nilable(Symbol)).returns(T.self_type) }
def singularize(locale = :en); end

sig { returns(T.self_type) }
def squish; end

sig { returns(T.self_type) }
def squish!; end

sig { returns(T.self_type) }
def strip_heredoc; end

sig { returns(T.self_type) }
def tableize; end

sig { params(keep_id_suffix: T.untyped).returns(T.self_type) }
def titlecase(keep_id_suffix: false); end

sig { params(keep_id_suffix: T.untyped).returns(T.self_type) }
def titleize(keep_id_suffix: false); end

sig { params(position: Integer).returns(T.self_type) }
def to(position); end

sig { returns(T.nilable(Date)) }
def to_date; end

sig { returns(T.nilable(DateTime)) }
def to_datetime; end

sig { params(form: T.nilable(Symbol)).returns(T.nilable(Time)) }
def to_time(form = :local); end

sig { params(truncate_to: Integer, options: T::Hash[Symbol, T.untyped]).returns(T.self_type) }
def truncate(truncate_to, options = {}); end

sig { params(truncate_to: Integer, omission: T.nilable(String)).returns(T.self_type) }
def truncate_bytes(truncate_to, omission: "…"); end

sig { params(words_count: Integer, options: T::Hash[Symbol, T.untyped]).returns(T.self_type) }
def truncate_words(words_count, options = {}); end

sig { returns(T.self_type) }
def underscore; end

sig { returns(T.self_type) }
def upcase_first; end
end

0 comments on commit 4914b89

Please sign in to comment.