repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/version.rb
lib/stripe/cli/version.rb
module Stripe module CLI VERSION = "1.8.4" end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/runner.rb
lib/stripe/cli/runner.rb
module Stripe module CLI class Runner < Thor map "-v" => :version map "--version" => :version register Commands::Cards, 'cards', 'cards', 'find, list, create, & delete cards for both customers & recipients' register Commands::Charges, 'charges', 'charges', 'find, list, create, capture, & refund charges' register Commands::Customers, 'customers', 'customers', 'find, list, create, & delete customers' register Commands::Tokens, 'tokens', 'tokens', 'find & create tokens for bank accounts & credit cards' register Commands::Plans, 'plans', 'plans', 'find, list, create, & delete plans' register Commands::Coupons, 'coupons', 'coupons', 'find, list, create, & delete coupons' register Commands::Events, 'events', 'events', 'find & list events' register Commands::Invoices, 'invoices', 'invoices', 'find, list, pay, & close invoices' register Commands::InvoiceItems, 'invoice_items', 'invoice_items', 'find, list, create, & delete invoice items' register Commands::Transactions, 'transactions', 'transactions', 'find & list balance transactions' register Commands::Balance, 'balance', 'balance', 'show currently available & pending balance amounts' register Commands::Recipients, 'recipients', 'recipients', 'find, list, create, & delete recipients' register Commands::Refunds, 'refunds', 'refunds', 'find, list, & create refunds' register Commands::Subscriptions, 'subscriptions', 'subscriptions', 'find, list, create, cancel & reactivate multiple subscriptions per customer' register Commands::Transfers, 'transfers', 'transfers', 'find, list, & create transfers' register Commands::Version, 'version', 'version', 'display current gem version', :hide => true end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands.rb
lib/stripe/cli/commands.rb
module Stripe module CLI module Commands autoload :Cards, 'stripe/cli/commands/cards' autoload :Charges, 'stripe/cli/commands/charges' autoload :Customers, 'stripe/cli/commands/customers' autoload :Tokens, 'stripe/cli/commands/tokens' autoload :Plans, 'stripe/cli/commands/plans' autoload :Coupons, 'stripe/cli/commands/coupons' autoload :Events, 'stripe/cli/commands/events' autoload :Invoices, 'stripe/cli/commands/invoices' autoload :InvoiceItems, 'stripe/cli/commands/invoice_items' autoload :Transactions, 'stripe/cli/commands/transactions' autoload :Balance, 'stripe/cli/commands/balance' autoload :Recipients, 'stripe/cli/commands/recipients' autoload :Refunds, 'stripe/cli/commands/refunds' autoload :Subscriptions, 'stripe/cli/commands/subscriptions' autoload :Transfers, 'stripe/cli/commands/transfers' autoload :Version, 'stripe/cli/commands/gem_version' end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/customers.rb
lib/stripe/cli/commands/customers.rb
require 'chronic' module Stripe module CLI module Commands class Customers < Command include Stripe::Utils desc "list", "List customers" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" def list super Stripe::Customer, options end desc "find ID", "Find a customer" def find customer_id super Stripe::Customer, customer_id end desc "delete ID", "Delete a customer" def delete customer_id super Stripe::Customer, customer_id end desc "create", "Create a new customer" option :description, :desc => "Arbitrary description to be displayed in Stripe Dashboard." option :email, :desc => "Customer's email address. Will be displayed in Stripe Dashboard." option :plan, :desc => "The ID of a Plan this customer should be subscribed to. Requires a credit card." option :coupon, :desc => "The ID of a Coupon to be applied to all of Customer's recurring charges" option :quantity, :desc => "A multiplier for the plan option. defaults to `1'" option :trial_end, :desc => "apply a trial period until this date. Override plan's trial period." option :account_balance, :desc => "customer's starting account balance in cents. A positive amount will be added to the next invoice while a negitive amount will act as a credit." option :card, :aliases => "--token", :desc => "credit card Token or ID. May also be created interactively." option :card_number, :aliases => "--number", :desc => "credit card number. usually 16 digits long" option :card_exp_month, :aliases => "--exp-month", :desc => "Two digit expiration month of card" option :card_exp_year, :aliases => "--exp-year", :desc => "Four digit expiration year of card" option :card_cvc, :aliases => "--cvc", :desc => "Three or four digit security code located on the back of card" option :card_name, :aliases => "--name", :desc => "Cardholder's full name as displayed on card" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" def create options[:email] ||= ask('Customer\'s Email:') options[:description] ||= ask('Provide a description:') options[:plan] ||= ask('Assign a plan:') if options[:plan] == "" options.delete :plan else options[:coupon] ||= ask('Apply a coupon:') end options.delete( :coupon ) if options[:coupon] == "" if options[:plan] options[:card] ||= credit_card( options ) options[:trial_end] = Chronic.parse(options[:trial_end]).to_i.to_s if options[:trial_end] end super Stripe::Customer, options end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/events.rb
lib/stripe/cli/commands/events.rb
module Stripe module CLI module Commands class Events < Command desc "list", "List events" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :object_id, :desc => "only list events pertaining to the object with this ID" option :type, :desc => "only list events of type TYPE" def list super Stripe::Event, options end desc "find ID", "Find a event" def find event_id super Stripe::Event, event_id end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/tokens.rb
lib/stripe/cli/commands/tokens.rb
module Stripe module CLI module Commands class Tokens < Command include Stripe::Utils desc "find ID", "Find a Token" def find event_id super Stripe::Token, event_id end desc "create TYPE", "create a new token of type TYPE(card or account)" option :card, :type => :hash, :default => {}, :desc => "hash of card params. may also be provided individually or added interactively." option :card_number, :aliases => "--number", :desc => "credit card number. usually 16 digits long" option :card_exp_month, :aliases => "--exp-month", :desc => "Two digit expiration month of card" option :card_exp_year, :aliases => "--exp-year", :desc => "Four digit expiration year of card" option :card_cvc, :aliases => "--cvc", :desc => "Three or four digit security code located on the back of card" option :card_name, :aliases => "--name", :desc => "Cardholder's full name as displayed on card" option :bank_account, :aliases => "--account", :type => :hash, :default => {}, :desc => "hash of account params. may also be provided individually or added interactively." option :country, :desc => "country of bank account. currently supports 'US' only" option :routing_number, :desc => "ACH routing number for bank account" option :account_number, :desc => "account number of bank account. Must be a checking account" def create type opt_symbol, value_hash = case type when 'card', 'credit_card', 'credit card' [ :card, credit_card( options ) ] when 'account', 'bank_account', 'bank account' [ :bank_account, bank_account( options ) ] end options.delete_if {|option,_| strip_list.include? option } options[opt_symbol] = value_hash super Stripe::Token, options end private def strip_list %i( card card_number card_exp_month card_exp_year card_cvc card_name bank_account country routing_number account_number ) end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/charges.rb
lib/stripe/cli/commands/charges.rb
module Stripe module CLI module Commands class Charges < Command include Stripe::Utils desc "list", "List charges (optionally by customer_id)" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :customer, :desc => "ID of customer who's charges we want to list" def list super Stripe::Charge, options end desc "find ID", "Find a charge" def find charge_id super Stripe::Charge, charge_id end desc "refund ID", "Refund a charge" option :amount, :type => :numeric, :desc => "Refund amount in dollars. (or cents when --no-dollar-amounts) defaults to entire charge" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" option :refund_application_fee, :type => :boolean, :default => false, :desc => "Whether or not to refund the application fee" def refund charge_id options[:amount] = convert_amount(options[:amount]) if options[:amount] if charge = retrieve_charge(charge_id) request charge.refunds, :create, options end end desc "capture ID", "Capture a charge" def capture charge_id request Stripe::Charge.new(charge_id, api_key), :capture end desc "create", "Create a charge" option :customer, :desc => "The ID of an existing customer to charge" option :card, :aliases => "--token", :desc => "credit card Token or ID. May also be created interactively." option :card_number, :aliases => "--number", :desc => "credit card number. usually 16 digits long" option :card_exp_month, :aliases => "--exp-month", :desc => "Two digit expiration month of card" option :card_exp_year, :aliases => "--exp-year", :desc => "Four digit expiration year of card" option :card_cvc, :aliases => "--cvc", :desc => "Three or four digit security code located on the back of card" option :card_name, :aliases => "--name", :desc => "Cardholder's full name as displayed on card" option :amount, :type => :numeric, :desc => "Charge amount in dollars (or cents when --no-dollar-amounts)" option :currency, :default => "usd", :desc => "3-letter ISO code for currency" option :description, :desc => "Arbitrary description of charge" option :capture, :type => :boolean, :default => true, :desc => "Whether or not to immediately capture the charge. Uncaptured charges expire in 7 days" option :metadata, :type => :hash, :desc => "A key/value store of additional user-defined data" option :statement_description, :desc => "Displayed alongside your company name on your customer's card statement (15 character max)" option :receipt_email, :desc => "Email address to send receipt to. Overrides default email settings." def create options[:amount] = convert_amount(options[:amount]) options[:card] ||= credit_card( options ) unless options[:customer] super Stripe::Charge, options end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/balance.rb
lib/stripe/cli/commands/balance.rb
module Stripe module CLI module Commands class Balance < Command desc "current", "show currently available and pending balance figures" def current request Stripe::Balance, :retrieve, api_key end default_command :current end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/coupons.rb
lib/stripe/cli/commands/coupons.rb
require 'chronic' module Stripe module CLI module Commands class Coupons < Command desc "list", "List coupons" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" def list super Stripe::Coupon, options end desc "find ID", "Find a coupon" def find coupon_id super Stripe::Coupon, coupon_id end desc "delete ID", "Delete a coupon" def delete coupon_id super Stripe::Coupon, coupon_id end desc "create", "Create a new Coupon" option :id, :desc => "Unique name to identify this coupon" option :percent_off, :type => :numeric, :desc => "a discount of this percentage of the total amount due" option :amount_off, :type => :numeric, :desc => "a discount of this amount. Regardless of the total due" option :duration, :enum => %w( forever once repeating ), :desc => "describes how long to apply the discount" option :redeem_by, :desc => "coupon will no longer be accepted after this date." option :max_redemptions, :type => :numeric, :desc => "The maximum number of times this coupon may be redeemed" option :duration_in_months, :desc => "number of months to apply the discount. *Only if `duration` is `repeating`*" option :currency, :default => 'usd', :desc => "3-letter ISO code for currency" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" def create unless options[:percent_off] || options[:amount_off] discount = ask('(e.g. 25% or $10) specify discount:') if discount.end_with?( '%' ) options[:percent_off] = discount.gsub(/[^\d]/,"").to_i else options[:amount_off] = discount.gsub(/[^\d]/,"").to_i end end options[:id] ||= ask('Coupon ID:') options[:duration] ||= ask('(`forever`,`once`, or `repeating`) duration:') options[:duration_in_months] ||= ask('for how many months?') if options[:duration] == "repeating" options[:redeem_by] ||= ask('expire on:') if options[:redeem_by].empty? options.delete(:redeem_by) else options[:redeem_by] = Chronic.parse(options[:redeem_by]).to_i.to_s end super Stripe::Coupon, options end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/invoices.rb
lib/stripe/cli/commands/invoices.rb
module Stripe module CLI module Commands class Invoices < Command desc "list", "List invoices (optionally by customer_id)" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :customer, :desc => "ID of customer who's invoices we want to list" def list super Stripe::Invoice, options end desc "find ID", "Find an invoice" def find invoice_id super Stripe::Invoice, invoice_id end desc "close ID", "close an unpaid invoice" def close invoice_id request Stripe::Invoice.new(invoice_id, api_key), :close end desc "pay ID", "trigger an open invoice to be paid immediately" def pay invoice_id request Stripe::Invoice.new(invoice_id, api_key), :pay end desc "upcoming CUSTOMER", "find the upcoming invoice for CUSTOMER" def upcoming customer_id request Stripe::Invoice, :upcoming, {:customer => customer_id}, api_key end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/refunds.rb
lib/stripe/cli/commands/refunds.rb
module Stripe module CLI module Commands class Refunds < Command include Stripe::Utils desc "list", "List refunds for CHARGE charge" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :charge, :aliases => :c, :required => true, :desc => "Id of charge who's refunds we want to list" def list if charge = retrieve_charge(options.delete :charge) super charge.refunds, options end end desc "find ID", "Find ID refund of CHARGE charge" option :charge, :aliases => :c, :required => true, :desc => "Id of charge who's refund we want to find" def find refund_id if charge = retrieve_charge(options.delete :charge) super charge.refunds, refund_id end end desc "create", "apply a new refund to CHARGE charge" option :amount, :type => :numeric, :desc => "Refund amount in dollars. (or cents when --no-dollar-amounts) defaults to entire charged amount" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" option :refund_application_fee, :type => :boolean, :default => false, :desc => "Whether or not to refund the application fee" option :charge, :aliases => :c, :required => true, :desc => "Id of charge to apply refund" def create options[:amount] = convert_amount(options[:amount]) if options[:amount] if charge = retrieve_charge(options.delete :charge) super charge.refunds, options end end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/plans.rb
lib/stripe/cli/commands/plans.rb
module Stripe module CLI module Commands class Plans < Command include Stripe::Utils desc "list", "List plans" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" def list super Stripe::Plan, options end desc "find ID", "Find a plan" def find plan_id super Stripe::Plan, plan_id end desc "delete ID", "Delete a plan" def delete plan_id super Stripe::Plan, plan_id end desc "create", "Create a new plan" option :name, :desc => "Name displayed on invoices and in the Dashboard" option :id, :desc => "Unique name used to identify this plan when subscribing a customer" option :amount, :type => :numeric, :desc => "Amount in dollars (or cents when --no-dollar-amounts)" option :interval, :enum => %w( day week month year ), :default => "month", :desc => "Billing frequency" option :interval_count, :type => :numeric, :default => 1, :desc => "The number of intervals between each subscription billing." option :currency, :default => "usd", :desc => "3-letter ISO code for currency" option :trial_period_days, :type => :numeric, :default => 0, :desc => "Number of days to delay a customer's initial bill" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" def create options[:amount] = convert_amount(options[:amount]) options[:name] ||= ask('Plan name:') options[:id] ||= ask('Plan id:') super Stripe::Plan, options end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/transfers.rb
lib/stripe/cli/commands/transfers.rb
module Stripe module CLI module Commands class Transfers < Command include Stripe::Utils desc "list", "List transfers, optionaly filter by recipient or transfer status: ( pending paid failed )" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :recipient, :desc => "limit result set to RECIPIENT's transfers" option :status, :desc => "filter by transfer status: ( pending paid failed )", :enum => %w( pending paid failed ) def list super Stripe::Transfer, options end desc "find ID", "Find a transfer" def find transfer_id super Stripe::Transfer, transfer_id end desc "create", "create a new outgoing money transfer" option :amount, :desc => "transfer amount in dollars (or cents when --no-dollar-amounts)" option :recipient, :desc => "ID of transfer recipient. May also be created interactively." option :currency, :default => 'usd' option :description, :desc => "Arbitrary description of transfer" option :statement_description, :desc => "Displayed alongside your company name on your customer's card statement (15 character max)" option :balance, :type => :boolean, :desc => "Sugar for specifying that amount should be equal to current balance" option :self, :type => :boolean, :desc => "Sugar for specifying a transfer into your own account" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" def create if options.delete(:balance) == true options[:amount] = Stripe::Balance.retrieve(api_key).available.first.amount else options[:amount] = convert_amount(options[:amount]) end if options.delete(:self) == true options[:recipient] = 'self' else options[:recipient] ||= ask('Recipient ID or self:') options[:recipient] = create_recipient[:id] if options[:recipient] == "" end super Stripe::Transfer, options end private def create_recipient Stripe::CLI::Runner.start [ "recipients", "create" ] end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/recipients.rb
lib/stripe/cli/commands/recipients.rb
module Stripe module CLI module Commands class Recipients < Command include Stripe::Utils desc "list", "List recipients" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :verified, :type => :boolean, :desc => "Only return recipients that are verified or unverified" def list super Stripe::Recipient, options end desc "find ID", "Find a recipient" def find recipient_id super Stripe::Recipient, recipient_id end desc "delete ID", "delete a recipient" def delete recipient_id super Stripe::Recipient, recipient_id end desc "create", "create a new recipient. Either an Individual or a Corporation." option :name, :desc => "Full legal name of Individual or Corporation" option :type, :enum => %w( individual corporation ), :desc => "recipient type," option :individual, :type => :boolean, :aliases => :i, :desc => "flag specifying recipient should be of type Individual" option :corporation, :type => :boolean, :aliases => :c, :desc => "flag specifying recipient should be of type Corporation" option :tax_id, :type => :numeric, :desc => "Full SSN for individuals or full EIN for corporations" option :email, :desc => "Recipient's email address" option :description, :desc => "Arbitrary description of recipient" option :bank_account, :aliases => "--account", :desc => "dictionary of bank account attributes as 'key':'value' pairs" option :country, :desc => "country of bank account. currently supports 'US' only" option :account_number, :desc => "account number of bank account. Must be a checking account" option :routing_number, :desc => "ACH routing number for bank account" option :card, :aliases => "--token", :desc => "credit card Token or ID. May also be created interactively." option :card_number, :aliases => "--number", :desc => "credit card number. usually 16 digits long" option :card_exp_month, :aliases => "--exp-month", :desc => "Two digit expiration month of card" option :card_exp_year, :aliases => "--exp-year", :desc => "Four digit expiration year of card" option :card_cvc, :aliases => "--cvc", :desc => "Three or four digit security code located on the back of card" option :card_name, :desc => "Cardholder's full name as displayed on card" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" def create options[:type] ||= recipient_type(options) case options[:type] when 'individual' options[:name] ||= ask('Recipient\'s full, legal name:') options[:tax_id] ||= ask('Tax ID (SSN):') when 'corporation' options[:name] ||= ask('Full Incorporated Name:') options[:tax_id] ||= ask('Tax ID (EIN):') end unless options[:name] && options[:tax_id] options[:tax_id].gsub!(/[^\d]/,"") options[:email] ||= ask('Email Address:') unless options[:card] || no?('add a Debit Card? [yN]',:yellow) options[:card_name] ||= options[:name] if yes?('Name on card same as recipient name? [yN]') options[:card] = credit_card( options ) end unless options[:bank_account] || no?('add a Bank Account? [yN]',:yellow) options[:bank_account] = bank_account( options ) end options.delete_if {|option,_| strip_list.include? option } super Stripe::Recipient, options end private def recipient_type opt opt.delete(:individual) ? 'individual' : opt.delete(:corporation) ? 'corporation' : yes?('Corporation? [yN]') ? 'corporation' : 'individual' end def strip_list %i( card_number card_exp_month card_exp_year card_cvc card_name country routing_number account_number ) end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/invoice_items.rb
lib/stripe/cli/commands/invoice_items.rb
module Stripe module CLI module Commands class InvoiceItems < Command include Stripe::Utils desc "list", "List invoice items (optionally by customer_id)" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :customer, :desc => "ID of customer who's invoice items we want to list" def list super Stripe::InvoiceItem, options end desc "find ID", "Find an invoice item" def find invoice_item_id super Stripe::InvoiceItem, invoice_item_id end desc "create", "Create a new invoice item for customer" option :customer, :desc => "The ID of customer for the invoice item" option :amount, :type => :numeric, :desc => "Amount in dollars (or cents when --no-dollar-amounts)" option :currency, :default => "usd", :desc => "3-letter ISO code for currency" option :description, :desc => "Arbitrary description of charge" option :invoice, :desc => "The ID of an existing invoice to add this invoice item to" option :subscription, :desc => "The ID of a subscription to add this invoice item to" option :discountable, :type => :boolean, :desc => "Controls whether discounts apply to this invoice item" option :metadata, :type => :hash, :desc => "A key/value store of additional user-defined data" def create options[:customer] ||= ask('Customer ID:') options[:amount] = convert_amount(options[:amount]) super Stripe::InvoiceItem, options end desc "delete ID", "Delete a invoice item" def delete invoice_item_id super Stripe::InvoiceItem, invoice_item_id end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/subscriptions.rb
lib/stripe/cli/commands/subscriptions.rb
require 'chronic' module Stripe module CLI module Commands class Subscriptions < Command include Stripe::Utils desc "list", "List subscriptions for CUSTOMER customer" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :customer, :aliases => :c, :required => true, :desc => "ID of customer who's subscriptions we want to list" def list if cust = retrieve_customer(options.delete :customer) super cust.subscriptions, options end end desc "find ID", "find ID subscription for CUSTOMER customer" option :customer, :aliases => :c, :required => true, :desc => "ID of customer who's subscription we want to find" def find subscription_id if cust = retrieve_customer(options.delete :customer) super cust.subscriptions, subscription_id end end desc "create", "create a subscription for CUSTOMER customer" option :plan, :desc => "the plan to assign to CUSTOMER customer" option :coupon, :desc => "id of a coupon to apply" option :trial_end, :desc => "apply a trial period until this date. Override plan's trial period." option :card, :aliases => "--token", :desc => "credit card Token or ID. May also be created interactively." option :card_number, :aliases => "--number", :desc => "credit card number. usually 16 digits long" option :card_exp_month, :aliases => "--exp-month", :desc => "Two digit expiration month of card" option :card_exp_year, :aliases => "--exp-year", :desc => "Four digit expiration year of card" option :card_cvc, :aliases => "--cvc", :desc => "Three or four digit security code located on the back of card" option :card_name, :aliases => "--name", :desc => "Cardholder's full name as displayed on card" option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data" option :customer, :aliases => :c, :required => true, :desc => "ID of customer receiving the new subscription" def create options[:plan] ||= ask('Assign a plan:') options.delete( :plan ) if options[:plan] == "" options[:coupon] ||= ask('Apply a coupon:') options.delete( :coupon ) if options[:coupon] == "" options[:card] ||= credit_card( options ) if yes?("add a new credit card? [yN]",:yellow) options[:trial_end] = Chronic.parse(options[:trial_end]).to_i.to_s if options[:trial_end] if cust = retrieve_customer(options.delete :customer) super cust.subscriptions, options end end desc "cancel ID", "cancel ID subscription for CUSTOMER customer" option :at_period_end, :type => :boolean, :default => false, :desc => "delay cancellation until end of current period" option :customer, :aliases => :c, :required => true, :desc => "ID of customer who's subscription we want to cancel" def cancel subscription_id options[:at_period_end] ||= yes?("delay until end of current period? [yN]",:yellow) if cust = retrieve_customer(options.delete :customer) and subscription = retrieve_subscription(cust, subscription_id) request subscription, :delete, options end end desc "reactivate ID", "reactivate auto-renewal if `cancel-at-period-end` was set to true" option :customer, :aliases => :c, :required => true, :desc => "ID of customer who's subscription we want to reactivate" def reactivate subscription_id if cust = retrieve_customer(options.delete :customer) and subscription = retrieve_subscription(cust, subscription_id) request subscription, :save end end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/gem_version.rb
lib/stripe/cli/commands/gem_version.rb
module Stripe module CLI module Commands class Version < Command desc "version", "display the current gem version number" option :hide def version puts "stripe-cli v#{Stripe::CLI::VERSION}" end default_command :version end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/transactions.rb
lib/stripe/cli/commands/transactions.rb
module Stripe module CLI module Commands class Transactions < Command desc "list [TYPE]", "List transactions, optionaly filter by type: ( charges, refunds, adjustments, application_fees, application_fee_refunds, transfers, transfer_failures )" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :type, :enum => %w( charge refund adjustment application_fee application_fee_refund transfer transfer_failure ) option :source def list type = 'all' options[:type] = type.sub(/s$/,'') unless type == 'all' super Stripe::BalanceTransaction, options end desc "find ID", "Find a transaction" def find transaction_id super Stripe::BalanceTransaction, transaction_id end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
stripe-contrib/stripe-cli
https://github.com/stripe-contrib/stripe-cli/blob/ee98caab204fabf3d5cc34d1baef33c1cc45c881/lib/stripe/cli/commands/cards.rb
lib/stripe/cli/commands/cards.rb
module Stripe module CLI module Commands class Cards < Command include Stripe::Utils desc "list", "List cards for OWNER (customer or recipient)" option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination." option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list." option :limit, :desc => "a limit on the number of resources returned, between 1 and 100" option :offset, :desc => "the starting index to be used, relative to the entire list" option :count, :desc => "deprecated: use limit" option :owner, :required => true, :desc => "id of customer or recipient to search within" def list if owner = retrieve_owner(options.delete :owner) super owner.cards, options end end desc "find ID", "find ID card for OWNER (customer or recipient)" option :owner, :required => true, :desc => "id of customer or recipient to search within" def find card_id if owner = retrieve_owner(options.delete :owner) super owner.cards, card_id end end desc "create", "create a new card for OWNER (customer or recipient)" option :card, :aliases => "--token", :desc => "credit card Token or ID. May also be created interactively." option :card_number, :aliases => "--number", :desc => "credit card number. usually 16 digits long" option :card_exp_month, :aliases => "--exp-month", :desc => "Two digit expiration month of card" option :card_exp_year, :aliases => "--exp-year", :desc => "Four digit expiration year of card" option :card_cvc, :aliases => "--cvc", :desc => "Three or four digit security code located on the back of card" option :card_name, :aliases => "--name", :desc => "Cardholder's full name as displayed on card" option :owner, :aliases => %w( --customer --recipient ), :required => true, :desc => "id of customer or recipient receiving new card" def create card = options.delete(:card) options[:card] = card || credit_card( options ) if owner = retrieve_owner(options.delete :owner) super owner.cards, options end end desc "delete ID", "delete ID card for OWNER (customer or recipient)" option :owner, :required => true, :desc => "id of customer or recipient to search within" def delete card_id if owner = retrieve_owner(options.delete :owner) and card = retrieve_card(owner, card_id) request card, :delete end end end end end end
ruby
MIT
ee98caab204fabf3d5cc34d1baef33c1cc45c881
2026-01-04T17:48:21.359522Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/jobs/application_job.rb
app/jobs/application_job.rb
# frozen_string_literal: true class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/jobs/types/sample_job.rb
app/jobs/types/sample_job.rb
# frozen_string_literal: true class Types::SampleJob < ApplicationJob retry_on Exception, wait: :exponentially_longer, attempts: 50 queue_as :default def perform(sample, source_ip) sample = ::Types::Sample.create(**sample, source_ip:) Rails.logger.debug sample.inspect raise "Couldn't process sample" unless sample.persisted? end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/helpers/meta_helper.rb
app/helpers/meta_helper.rb
# frozen_string_literal: true module MetaHelper def default_meta_tags { site: "gem.sh", title: "", reverse: true, separator: "-", description: "Beautiful documentation for any Ruby gem", keywords: "ruby, rails, rubyonrails, programming, documentation", canonical: request.original_url, noindex: !Rails.env.production?, og: { site_name: "gem.sh", # title: "gem.sh - Beautiful documentation for any Ruby gem", description: "Beautiful documentation for any Ruby gem", type: "website", url: request.original_url, image: image_url("social.png"), }, twitter: { card: "summary_large_image", creator: "@marcoroth_", }, } end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/helpers/heroicon_helper.rb
app/helpers/heroicon_helper.rb
# frozen_string_literal: true module HeroiconHelper include Heroicon::Engine.helpers end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/helpers/application_helper.rb
app/helpers/application_helper.rb
# frozen_string_literal: true module ApplicationHelper def to_short_sentence(array, limit: 3) if array.length > limit remaining = array.length - limit "#{array.first(3).join(', ')} and #{remaining} more" else array.to_sentence end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/helpers/markdown_helper.rb
app/helpers/markdown_helper.rb
# frozen_string_literal: true module MarkdownHelper def render_markdown(content) MarkdownRenderer.new(sanitize(content)).render end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/helpers/yard_helpers.rb
app/helpers/yard_helpers.rb
# frozen_string_literal: true # rubocop:disable Rails/HelperInstanceVariable module YARDHelpers def yard_docs parser = YARD::DocstringParser.new @object.comments.each do |c| parser.parse(c) end if parser.tags.any? parser.tags.group_by(&:tag_name).map do |tag_name, tags| case tag_name when "option" option_tags(tags) when "param" param_tags(tags) when "raise" raise_tags(tags) when "return" return_tags(tags) when "overload" overload_tags(tags) when "deprecated" deprecated_tags(tags) else other_tags(tags) end end.join("<br/>") else comments_content end end def option_tags(tags) items = tags.map { |tag| option_tag(tag) } %( <b>Options Hash</b>: <code>(**#{tags.first.name})</code><br/> <ul>#{items.join}</ul> ) end def option_tag(tag) %( <li> <b><code>#{tag.pair.name}</code></b> (<code>#{tag.pair.types.join(', ')}</code>) -- #{tag.pair.text} </li> ) end def param_tags(tags) items = tags.map { |tag| param_tag(tag) } %( <b>Parameters</b>:</code><br/> <ul>#{items.join}</ul> ) end def param_tag(tag) %( <li> <b><code>#{tag.name}</code></b> (<code>#{tag.try(:types).to_a.join(', ')}</code>) -- #{tag.try(:text)} </li> ) end def raise_tags(tags) items = tags.map { |tag| raise_tag(tag) } %( <b>Raises</b>:</code><br/> <ul>#{items.join}</ul> ) end def raise_tag(tag) %( <li> <b><code>(#{tag.types.join(', ')})</code></b> - #{tag.text} </li> ) end def return_tags(tags) items = tags.map { |tag| return_tag(tag) } %( <b>Returns</b>:</code><br/> <ul>#{items.join}</ul> ) end def return_tag(tag) %( <li> <b><code>(#{tag.types.join(', ')})</code></b> - #{tag.text} </li> ) end def deprecated_tags(tags) items = tags.map { |tag| deprecated_tag(tag) } %( <b>Deprecated</b>:</code><br/> <ul>#{items.join}</ul> ) end def deprecated_tag(tag) %( <li>#{tag.text}</li> ) end def overload_tags(tags) items = tags.map { |tag| overload_tag(tag) } %( <b>Overloads</b>:</code><br/> <ul>#{items.join}</ul> ) end def overload_tag(tag) %( <li> <b><code>#{tag.signature.gsub('$0', @object.name)}</code></b> </li> ) end def other_tags(tags) items = tags.map { |tag| other_tag(tag) } %( <b>Other tags</b>:</code><br/> <ul>#{items.join}</ul> ) end def other_tag(tag) %(<b>#{tag.tag_name.capitalize}</b>: #{tag.name} - #{tag.try(:text)} <br/>) end end # rubocop:enable Rails/HelperInstanceVariable
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/errors/gem_constant_not_found_error.rb
app/errors/gem_constant_not_found_error.rb
# frozen_string_literal: true class GemConstantNotFoundError < StandardError end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/errors/gem_not_found_error.rb
app/errors/gem_not_found_error.rb
# frozen_string_literal: true class GemNotFoundError < StandardError def initialize(name, version = nil) super(name) @name = name @version = version end def message if @name && @version %(Couldn't find gem "#{@name} with version "#{@version}") else %(Couldn't find gem "#{@name}") end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/page_controller.rb
app/controllers/page_controller.rb
# frozen_string_literal: true class PageController < ApplicationController def home @featured_gems = [ GemSpec.find("nokogiri"), GemSpec.find("async"), GemSpec.find("roda"), ] @images = [ "https://nokogiri.org/images/nokogiri-serif-black.png", "https://github.com/socketry/async/raw/main/assets/logo-v1.svg", "https://github.com/jeremyevans/roda/raw/master/www/public/images/roda-logo.svg", ] end def types @sample_count = ::Types::Sample.count @samples = ::Types::Sample.group(:gem_name, :gem_version).order(count: :desc).count rescue StandardError @sample_count = 0 @samples = [] end def docs end def community end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems_controller.rb
app/controllers/gems_controller.rb
# frozen_string_literal: true class GemsController < ApplicationController include GemScoped before_action :set_gem, except: :index def index @gems = Gems.just_updated end def show @getting_started = [ { title: "Installation", url: readme_gem_version_gem_path(@gem.name, @gem.version), description: "Learn more about how to install and configure the gem", icon: "arrow-down-tray" }, { title: "Documentation", url: readme_gem_version_gem_path(@gem.name, @gem.version), description: "Learn more about the details", icon: "book-open" }, { title: "Guides", url: gem_version_guides_path(@gem.name, @gem.version), description: "Learn more about the gem in the written guides", icon: "document-text" }, { title: "Reference", url: reference_gem_version_gem_path(@gem.name, @gem.version), description: "Learn more about the classes and modules", icon: "code-bracket" }, ] end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/application_controller.rb
app/controllers/application_controller.rb
# frozen_string_literal: true class ApplicationController < ActionController::Base end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/search_controller.rb
app/controllers/search_controller.rb
# frozen_string_literal: true class SearchController < ApplicationController def index @result = GemSearch.search(params[:name]) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/concerns/gem_module_scoped.rb
app/controllers/concerns/gem_module_scoped.rb
# frozen_string_literal: true module GemModuleScoped extend ActiveSupport::Concern included do before_action :set_module, except: :index end private def set_module @module = @gem.find_module!(params[:id]) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/concerns/gem_target_scoped.rb
app/controllers/concerns/gem_target_scoped.rb
# frozen_string_literal: true module GemTargetScoped extend ActiveSupport::Concern included do before_action :set_target end private def set_target if params[:class_id] @target = @gem.find_class!(params[:class_id]) @namespace = @gem.find_namespace(@target.qualified_namespace) elsif params[:module_id] @target = @gem.find_module!(params[:module_id]) else @target = @gem.info.analyzer end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/concerns/gem_scoped.rb
app/controllers/concerns/gem_scoped.rb
# frozen_string_literal: true module GemScoped extend ActiveSupport::Concern included do before_action :set_gem rescue_from "GemNotFoundError", "Gems::NotFound" do |exception| redirect_to gems_path, notice: exception.message end rescue_from "GemConstantNotFoundError" do |exception| redirect_to gem_version_gem_path(@gem.name, @gem.version), notice: exception.message end end private def set_gem if params[:version] @gem = GemSpec.find(params[:gem], params[:version]) || raise(GemNotFoundError.new(params[:gem], params[:version])) else version = GemSpec.latest_version_for(params[:gem]) gem = version ? GemSpec.find(params[:gem], version) : nil @gem = gem || raise(GemNotFoundError.new(params[:gem], version)) end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/concerns/gem_file_scoped.rb
app/controllers/concerns/gem_file_scoped.rb
# frozen_string_literal: true module GemFileScoped extend ActiveSupport::Concern included do before_action :set_file end private def set_file SourceFile.new(file: params[:id], gem: @gem).tap do |file| @file = file if file.exist? end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/concerns/gem_class_scoped.rb
app/controllers/concerns/gem_class_scoped.rb
# frozen_string_literal: true module GemClassScoped extend ActiveSupport::Concern included do before_action :set_class, except: :index end private def set_class @class = @gem.find_class!(params[:id]) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/files_controller.rb
app/controllers/gems/files_controller.rb
# frozen_string_literal: true class Gems::FilesController < ApplicationController include GemScoped include GemFileScoped def index end def show end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/docs_controller.rb
app/controllers/gems/docs_controller.rb
# frozen_string_literal: true class Gems::DocsController < ApplicationController include GemScoped def index end def show end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/class_methods_controller.rb
app/controllers/gems/class_methods_controller.rb
# frozen_string_literal: true class Gems::ClassMethodsController < ApplicationController include GemScoped include GemTargetScoped def show @method = @target.class_methods.find { |class_method| class_method.name == params[:id] } raise(GemConstantNotFoundError, "Class method '#{params[:id]}' not found on '#{@target.try(:qualified_name)}'") if @method.nil? render "gems/methods/show" end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/modules_controller.rb
app/controllers/gems/modules_controller.rb
# frozen_string_literal: true class Gems::ModulesController < ApplicationController include GemScoped include GemModuleScoped def index end def show @modules = @gem.modules.select { |mod| mod.qualified_namespace == @module.qualified_name } @classes = @gem.classes.select { |klass| klass.qualified_namespace == @module.qualified_name } end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/guides_controller.rb
app/controllers/gems/guides_controller.rb
# frozen_string_literal: true class Gems::GuidesController < ApplicationController include GemScoped def index end def show end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/classes_controller.rb
app/controllers/gems/classes_controller.rb
# frozen_string_literal: true class Gems::ClassesController < ApplicationController include GemScoped include GemClassScoped def index end def show @classes = @gem.classes.select { |klass| klass.qualified_namespace == @class.qualified_name } @namespace = @gem.find_namespace(@class.qualified_namespace) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/types_controller.rb
app/controllers/gems/types_controller.rb
# frozen_string_literal: true class Gems::TypesController < ApplicationController include GemScoped def index @samples = Types::Sample .group(:gem_name, :gem_version, :receiver, :method_name) .where(gem_name: @gem.name) .where("gem_version LIKE ?", "#{@gem.version.to_s.split('-').first}%") .order(count: :desc) .count rescue StandardError @samples = [] end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/rbs_controller.rb
app/controllers/gems/rbs_controller.rb
# frozen_string_literal: true class Gems::RBSController < ApplicationController include GemScoped def index require_samples = params[:require_samples].present? signature = @gem.rbs_signature(require_samples:) filename = "#{@gem.name}-#{@gem.version}-#{require_samples ? 'only-samples' : 'complete'}.rbs" if params[:download].present? send_data signature, type: "application/x-ruby", disposition: "attachment", filename: filename else render plain: signature end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/versions_controller.rb
app/controllers/gems/versions_controller.rb
# frozen_string_literal: true class Gems::VersionsController < ApplicationController include GemScoped def index end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/pages_controller.rb
app/controllers/gems/pages_controller.rb
# frozen_string_literal: true class Gems::PagesController < ApplicationController include GemScoped def show render params[:id].to_sym end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/search_controller.rb
app/controllers/gems/search_controller.rb
# frozen_string_literal: true class Gems::SearchController < ApplicationController include GemScoped def index query = params[:q].to_s.downcase @modules = @gem.modules.select { |mod| mod.qualified_name.downcase.include?(query) } @classes = @gem.classes.select { |klass| klass.qualified_name.downcase.include?(query) } @methods = @gem.all_methods.select { |method| method.name.downcase.include?(query) } respond_to do |format| format.html { redirect_to gem_version_gem_path(@gem.name, @gem.version) } format.turbo_stream end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/gems/instance_methods_controller.rb
app/controllers/gems/instance_methods_controller.rb
# frozen_string_literal: true class Gems::InstanceMethodsController < ApplicationController include GemScoped include GemTargetScoped def show @method = @target.instance_methods.find { |instance_method| instance_method.name == params[:id] } raise(GemConstantNotFoundError, "Instance method '#{params[:id]}' not found on '#{@target.try(:qualified_name)}'") if @method.nil? render "gems/methods/show" end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/controllers/api/v1/types/samples_controller.rb
app/controllers/api/v1/types/samples_controller.rb
# frozen_string_literal: true module API module V1 module Types class SamplesController < ApplicationController skip_before_action :verify_authenticity_token def create ::Types::SampleJob.perform_later(sample_params, request.remote_ip) head :ok end private def sample_params params.require(:sample).permit(:gem_name, :gem_version, :receiver, :method_name, :application_name, :type_fusion_version, :location, return_value: [], parameters: []).tap do |whitelisted| whitelisted[:parameters] = params.dig(:sample, :parameters) whitelisted[:return_value] = params.dig(:sample, :return_value) end end end end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/rbs_signature.rb
app/components/rbs_signature.rb
# frozen_string_literal: true class RBSSignature < ViewComponent::Base def initialize(rbs:, samples: []) @rbs = rbs @samples = samples end def sample_count @samples.to_a.length end def application_count @samples.pluck(:application_name).uniq.count end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/method_details.rb
app/components/method_details.rb
# frozen_string_literal: true class MethodDetails < ViewComponent::Base include YARDHelpers def initialize(object:, parent:, gem:) @object = object @parent = parent @gem = gem end def comments_content @object.comments.join("<br>").force_encoding("UTF-8") rescue StandardError "" end def yard YARD::Templates::Helpers::Markup::RDocMarkup.new(comments_content).to_html end def rdoc @rdoc ||= RDoc::Markup::ToHtml.new(RDoc::Options.new) end def rbs_signature? @object.try(:samples, @gem).present? end def samples @object.samples(@gem) end def rbs_signature @object.rbs_signature(@gem) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/gems/heading.rb
app/components/gems/heading.rb
# frozen_string_literal: true class Gems::Heading < ViewComponent::Base def initialize(title:) @title = title end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/gems/wrapper.rb
app/components/gems/wrapper.rb
# frozen_string_literal: true class Gems::Wrapper < ViewComponent::Base renders_one :sidebar def initialize(gem:, modules:, classes:, class_methods:, instance_methods:) @gem = gem @modules = modules @classes = classes @class_methods = class_methods @instance_methods = instance_methods end def overview_tabs [ ["Home", gem_version_gem_path(@gem.name, @gem.version)], (["Guides", gem_version_guides_path(@gem.name, @gem.version)] if @gem.guide_files.any?), ["Reference", reference_gem_version_gem_path(@gem.name, @gem.version)], ["Types", gem_version_types_path(@gem.name, @gem.version)], ["Changelogs", changelogs_gem_version_gem_path(@gem.name, @gem.version)], ].compact end def tabs [ ["Versions", gem_version_versions_path(@gem.name, @gem.version)], ["Source", gem_version_files_path(@gem.name, @gem.version)], ["Playground", playground_gem_version_gem_path(@gem.name, @gem.version)], ["Stats", stats_gem_version_gem_path(@gem.name, @gem.version)], ["Metadata", metadata_gem_version_gem_path(@gem.name, @gem.version)], ["Wiki", wiki_gem_version_gem_path(@gem.name, @gem.version)], ["Announcements", announcements_gem_version_gem_path(@gem.name, @gem.version)], ] end def community_tabs [ ["Articles", articles_gem_version_gem_path(@gem.name, @gem.version)], ["Tutorials", tutorials_gem_version_gem_path(@gem.name, @gem.version)], ["Videos", videos_gem_version_gem_path(@gem.name, @gem.version)], ["Community", community_gem_version_gem_path(@gem.name, @gem.version)], ] end def docs_tabs [ ["README", readme_gem_version_gem_path(@gem.name, @gem.version)], *(@gem.documentation_files - [@gem.readme]).sort.map do |file| name = file.split("/").last.split(".").first.humanize [name, gem_version_doc_path(@gem.name, @gem.version, file)] end, # ["Getting Started", gem_version_guide_path(@gem.name, @gem.version, title)], # ["Installation", gem_version_guide_path(@gem.name, @gem.version, title)], # ["Upgrade Guide", gem_version_guide_path(@gem.name, @gem.version, title)], ] end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/gems/metadata.rb
app/components/gems/metadata.rb
# frozen_string_literal: true class Gems::Metadata < ViewComponent::Base def initialize(gem:) @gem = gem end def types_status @gem.rbs_files.any? ? :green : :default end def types_tooltip (types_status == :green) ? "This gem ships type annotations" : "No type annotations detected" end def docs_status @gem.documentation_files.any? ? :green : :default end def docs_tooltip (docs_status == :green) ? "This gem ships docs" : "No docs detected" end def guides_status @gem.guide_files.any? ? :green : :default end def guides_tooltip (guides_status == :green) ? "This gem ships guides" : "No guides detected" end def zeitwerk_status @gem.metadata.dependencies.map(&:name).include?("zeitwerk") ? :green : :default end def zeitwerk_tooltip (zeitwerk_status == :green) ? "This gem conforms to the Zeitwerk conventions" : "This gem doesn't seem to conform to the Zeitwerk conventions" end def namespace_status :default end def namespace_tooltip (namespace_status == :default) ? "Does this gem follow the Rubygems namespace conventions?" : "TODO" end def optimized_status :default end def optimized_tooltip (optimized_status == :green) ? "TODO" : "Not optimized for gem.sh yet" end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/status_badge.rb
app/components/ui/status_badge.rb
# frozen_string_literal: true class UI::StatusBadge < ViewComponent::Base CLASSES = ClassVariants.build( base: "rounded-md bg-white px-2.5 py-1 text-xs font-semibold text-gray-900 ring-1 ring-inset ring-gray-300 flex", variants: {}, defaults: {}, ) def initialize(label:, status: :default, tooltip: nil) @status = status @tooltip = tooltip @label = label end def data if @tooltip { controller: "tippy", tippy_content: @tooltip } else {} end end def classes CLASSES.render end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/card.rb
app/components/ui/card.rb
# frozen_string_literal: true class UI::Card < ViewComponent::Base renders_one :badge, UI::Badge def initialize(title:, description:) @title = title @description = description end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/badge.rb
app/components/ui/badge.rb
# frozen_string_literal: true class UI::Badge < ViewComponent::Base CLASSES = ClassVariants.build( base: "rounded-md py-1 px-2 fs-step--2 monospace-font-family font-medium ring-1 ring-inset self-end", variants: { color: { gray: "bg-gray-50 text-gray-600 ring-gray-600/10", red: "bg-red-50 text-red-700 ring-red-600/10", yellow: "bg-yellow-50 text-yellow-800 ring-yellow-600/20", green: "bg-green-50 text-green-700 ring-green-600/20", blue: "bg-blue-50 text-blue-700 ring-blue-700/10", indigo: "bg-indigo-50 text-indigo-700 ring-indigo-700/10", purple: "bg-purple-50 text-purple-70 ring-purple-700/100", pink: "bg-pink-50 text-pink-700 ring-pink-700/10", }, }, defaults: { color: :gray, }, ) def initialize(label:, style: :gray) @label = label @style = style end def classes CLASSES.render(color: @style) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/code_block.rb
app/components/ui/code_block.rb
# frozen_string_literal: true class UI::CodeBlock < ViewComponent::Base def initialize(language: "ruby") @language = language end def formatter @formatter ||= Rouge::Formatters::HTML.new end def lexer "Rouge::Lexers::#{@language.camelize}".constantize.new rescue StandardError Rouge::Lexers::PlainText.new end def id @id ||= "code-block-#{rand(10_000)}" end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/subheading.rb
app/components/ui/subheading.rb
# frozen_string_literal: true class UI::Subheading < ViewComponent::Base def initialize(title:) @title = title end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/heading.rb
app/components/ui/heading.rb
# frozen_string_literal: true class UI::Heading < ViewComponent::Base def initialize(title:) @title = title end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/code_list.rb
app/components/ui/code_list.rb
# frozen_string_literal: true class UI::CodeList < ViewComponent::Base def initialize(items:, gem:, title: "Items") items = items.to_a if items.is_a?(Set) @items = Array.wrap(items).sort_by { |item| item.try(:title) || item.to_s } @gem = gem @title = title end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/status.rb
app/components/ui/status.rb
# frozen_string_literal: true class UI::Status < ViewComponent::Base CLASSES = ClassVariants.build( base: "flex-none rounded-full p-1 ", variants: { status: { default: "text-gray-500", orange: "text-orange-400", green: "text-green-400", red: "text-rose-400", }, }, defaults: { status: :default, }, ) def initialize(status:) @status = status end def classes CLASSES.render(status: @status) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/components/ui/container.rb
app/components/ui/container.rb
# frozen_string_literal: true class UI::Container < ViewComponent::Base end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/gem_info.rb
app/models/gem_info.rb
# frozen_string_literal: true class GemInfo attr_accessor :analyzer def self.for(name) new(GemSpec.find(name)) end def initialize(gemspec) @gemspec = gemspec @analyzer = Analyzer.new(gemspec) analyze end delegate :classes, to: :@analyzer def analyze @gemspec.files.each do |file| path = "#{@gemspec.unpack_data_path}/#{file}" @analyzer.analyze(path) end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/source_file.rb
app/models/source_file.rb
# frozen_string_literal: true SourceFile = Data.define(:file, :gem) do def initialize(file:, gem: nil) super end def url(gem) Router.gem_version_file_path(gem.name, gem.version, file) end def source_path "#{gem.unpack_data_path}/#{file}" end def exist? file && gem.files.include?(file) && File.exist?(source_path) end def content exist? && File.read(source_path) end def title file end def to_s title end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/markdown_renderer.rb
app/models/markdown_renderer.rb
# frozen_string_literal: true class MarkdownRenderer class DefaultRenderer < Redcarpet::Render::HTML include Redcarpet::Render::SmartyPants def block_code(code, language) ApplicationController.render(UI::CodeBlock.new(language:).with_content(code), layout: false) end end def initialize(content) @content = content end def render return "" if content.blank? renderer.render(content) end private attr_reader :content def renderer Redcarpet::Markdown.new( DefaultRenderer.new(**markdown_settings), renderer_settings, ) end def markdown_settings { hard_wrap: true, no_images: false, no_links: false, with_toc_data: false, } end def renderer_settings { autolink: true, disable_indented_code_blocks: true, fenced_code_blocks: true, footnotes: true, gh_blockcode: true, highlight: true, lax_spacing: true, no_intra_emphasis: true, strikethrough: true, superscript: true, tables: true, underline: true, } end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/class_definition.rb
app/models/class_definition.rb
# frozen_string_literal: true ClassDefinition = Struct.new(:namespace, :name, :qualified_name, :node, :location, :superclass, :instance_methods, :class_methods, :extended_modules, :included_modules, :comments, :defined_files, :referenced_files) do include MethodFinders include RBSNamespaceHelpers def initialize( namespace: nil, name: nil, qualified_name: nil, node: nil, location: nil, superclass: nil, instance_methods: [], class_methods: [], extended_modules: [], included_modules: [], comments: [], defined_files: [], referenced_files: [] ) super end def url(gem) Router.gem_version_class_path(gem.name, gem.version, qualified_name) end def eql?(other) qualified_name == other.qualified_name end def object_name "class" end def to_s "#{object_name} #{qualified_name}" end def to_param qualified_name end def title qualified_name end def qualified_namespace namespace.join("::") end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/constant_reference.rb
app/models/constant_reference.rb
# frozen_string_literal: true ConstantReference = Data.define(:path, :location) do def initialize(path:, location: nil) super end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/router.rb
app/models/router.rb
# frozen_string_literal: true module Router class << self include Rails.application.routes.url_helpers end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/method_definition.rb
app/models/method_definition.rb
# frozen_string_literal: true MethodDefinition = Struct.new(:name, :target, :node, :location, :comments, :defined_files) do include RBSHelpers def initialize( name: nil, target: nil, node: nil, location: nil, comments: [], defined_files: [] ) super end def instance_method? false end def class_method? false end def eql?(other) name == other.name && target.qualified_name == other.target.qualified_name end def to_s "#{object_name} #{name}" end def to_param name end def seo_title if target "#{name} (#{target.qualified_name})" else name end end def title to_s end def code @code ||= LocationToContent.new(defined_files.first, location) end def samples(gem) @samples ||= begin Types::Sample .where( gem_name: gem.name, receiver: target.qualified_name, method_name: name, ) .where("gem_version LIKE ?", "#{gem.version.to_s.split('-').first}%") .to_a rescue StandardError [] end end def clear_sample_cache! @samples = nil end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/analyzer.rb
app/models/analyzer.rb
# frozen_string_literal: true class Analyzer class Visitor < Prism::Visitor # This object represents a set of comments being returned from the parser # for a given file. It can be used to quickly access a set of comments at # a given line number. class CommentSet attr_reader :comments def initialize(comments) @comments = comments.each_with_object({}) do |comment, indexed| indexed[comment.location.start_line] = comment.location.slice[1..].strip end end def for(node) start_line = node.location.start_line start_line -= 1 unless comments.key?(start_line) start_line.downto(1).lazy.take_while { |line| comments.key?(line) }.map(&comments).force end end # This object represents the constant nesting. It internally keeps an array # of constant paths, which are arrays of constant names. # # For example, the constant path for: # # module Foo # class Bar::Baz # class Qux # end # end # end # # would be `[["Foo"], ["Bar", "Baz"], ["Qux"]]`. For the most part, the # internal nesting doesn't matter, so most consumers will end up flattening # the list of constant names or joining them with "::". There are # implications for constant lookup, though, so it's important to maintain # those delimiters. class ConstantNesting ROOT = Object.new attr_reader :path def initialize @path = [] end def initialize_copy(other) super @path = [*other.path] end # Updates the nesting for the given constant path for the duration of the # given block. Yields the current nesting and the name of the constant. def with(node) previous_path = path next_path = path_for(node) @path = if next_path == :unprocessable next_path elsif next_path[0] == ROOT next_path[1..] else [*previous_path, next_path] end begin yield path ensure @path = previous_path end end private # Returns the components of the constant path for the given node. def path_for(node) case node.type when :constant_path_node if node.parent path_for(node.parent).concat(path_for(node.child)) else [ROOT].concat(path_for(node.child)) end when :constant_read_node [node.location.slice] else :unprocessable end end end attr_reader :analyzer, :gem, :path, :comment_set, :constant_nesting def initialize(analyzer, gem, path, comments) super() @analyzer = analyzer @gem = gem @path = path @comment_set = CommentSet.new(comments) @constant_nesting = ConstantNesting.new end def visit_class_node(node) superclass = if node.superclass constant_nesting.with(node.superclass) do |constant_path| # Constant paths can be any valid Ruby expression, so it's # possible we couldn't parse it. In this case we don't know what # to do with the superclass, so we'll return nil break if constant_path == :unprocessable # Otherwise we can process the superclass as a normal constant # path. *namespace, name = constant_path.flatten ClassDefinition.new( namespace: namespace, name: name, qualified_name: constant_path.join("::"), location: node.location, ) end end constant_nesting.with(node.constant_path) do |constant_path| constant_path = Array.wrap(constant_path) qualified_name = constant_path.join("::") reopen = NamespaceReopen.new(path: path, location: node.location, gem: gem) if (found = analyzer.classes.find { |clazz| clazz.qualified_name == qualified_name }) found.defined_files << reopen else *namespace, name = constant_path.flatten found = ClassDefinition.new( namespace: namespace, name: name, qualified_name: qualified_name, location: node.location, superclass: superclass, comments: comment_set.for(node), defined_files: [reopen], ) analyzer.classes << found end statements = case node.body&.type when nil [] when :statements_node node.body.body when :begin_node node.body.statements.body else raise "Unexpected statements node: #{node.body.inspect}" end # Here we're going to look for Kernel#include and Kernel#extend calls. # This kind of static analysis is difficult to do without a full type # system in place to determine the actual method being called, so we're # going to be a little loose here and just look for the method name # being called as a top-level statement inside of a class definition. statements.each do |statement| # Only looking at calls. next unless statement.is_a?(Prism::CallNode) # Only looking at #include and #extend. next unless ["include", "extend"].include?(statement.message) # Only looking for calls that have arguments. next unless statement.arguments.is_a?(Prism::ArgumentsNode) target = if statement.message == "include" found.included_modules else found.extended_modules end statement.arguments.arguments.each do |argument| constant_nesting.with(argument) do |argument_constant_path| # It's possible to include a module by variable reference, in # which case we wouldn't know what kind of module it is. In this # case we'll just ignore it. next if argument_constant_path == :unprocessable # Otherwise we can process the module as a normal constant path. namespace, name = find_module(argument_constant_path) qualified_name = [*namespace, name].join("::") target << ModuleDefinition.new( namespace: namespace, name: name, qualified_name: qualified_name, location: argument.location, referenced_files: [ConstantReference.new(path: path, location: argument.location)], ) end end end super end end def visit_constant_write_node(node) constant_nesting.with(Prism::ConstantReadNode.new(node.name, node.name_loc)) do |constant_path| analyzer.consts << constant_path.join("::") super end end def visit_def_node(node) constant_path = Array.wrap(constant_nesting.path) qualified_name = constant_path.join("::") # Note that we're using reverse_each here because it's likely that we're # finding the most recently inserted class or module. context = analyzer.classes.reverse_each.find { |clazz| clazz.qualified_name == qualified_name } || analyzer.modules.reverse_each.find { |mod| mod.qualified_name == qualified_name } || analyzer kwargs = { name: node.name.to_s, target: context, location: node.location, comments: comment_set.for(node), defined_files: [path], } case node.receiver when nil context.instance_methods << InstanceMethod.new(**kwargs) when Prism::SelfNode context.class_methods << ClassMethod.new(**kwargs) else # rubocop:disable Style/EmptyElse # In this case, we don't actually know what to do. The receiver of the # method definition is not nil (in which case it would be the current # context) and is not self (in which case it would be a class method). # For now, we'll ignore it. end super end def visit_module_node(node) constant_nesting.with(node.constant_path) do |constant_path| constant_path = Array.wrap(constant_path) qualified_name = constant_path.join("::") reopen = NamespaceReopen.new(path: path, location: node.location, gem: gem) if (found = analyzer.modules.find { |mod| mod.qualified_name == qualified_name }) found.defined_files << reopen else *namespace, name = constant_path.flatten analyzer.modules << ModuleDefinition.new( namespace: namespace, name: name, qualified_name: qualified_name, location: node.location, comments: comment_set.for(node), defined_files: [reopen], ) end super end end private # When we're looking at modules that are being included into a class or # module, we have to perform our own version of constant lookup like Ruby. # For example, when you have: # # module Foo # module Bar # include Baz # end # end # # It's possible that you're including Foo::Bar::Baz, Foo::Baz, or just Baz. # To determine which one, Ruby will look for a constant by each of those # names in turn. We'll do the same thing here. def find_module(constant_path) # From our example, this is going to be Foo::Bar::Baz and Foo::Baz. qualified_names = (constant_path.length - 2).downto(0).map do |index| constant_path[0..index].push(constant_path.last).join("::") end # Now we'll push on Baz. qualified_names << Array.wrap(constant_path.last).join("::") # Now we'll look for the first one that we find in our list of modules. If # we find multiple matches then we'll grab the one with the longest name # to replicate Ruby's behavior. candidate = analyzer .modules .select { |mod| qualified_names.include?(mod.qualified_name) } .max_by { _1.qualified_name.length } if candidate [candidate.namespace, candidate.name] else # If we don't find one, then it's possible it was dynamically defined or # we got the order of files wrong. In this case it's difficult to know # what the correct behavior is. We'll return the most nested possible # definition for now. *namespace, name = constant_path.flatten [namespace, name] end end end attr_accessor :classes, :modules, :consts, :instance_methods, :class_methods def self.call(source) new.analyze(source) end def initialize(gem = nil) @gem = gem @classes = Set.new @modules = Set.new @consts = Set.new @instance_methods = Set.new @class_methods = Set.new end def qualified_name "global" end def object_name "global" end def url(gem) Router.gem_version_gem_path(gem.name, gem.version) end def to_s "global" end def analyze_code(path, code) result = Prism.parse(code) result.value.accept(Visitor.new(self, @gem, path, result.comments)) self end def analyze(path) analyze_code(path, File.read(path)) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/application_record.rb
app/models/application_record.rb
# frozen_string_literal: true class ApplicationRecord < ActiveRecord::Base primary_abstract_class end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/types.rb
app/models/types.rb
# frozen_string_literal: true module Types def self.table_name_prefix "types_" end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/location_to_content.rb
app/models/location_to_content.rb
# frozen_string_literal: true class LocationToContent attr_reader :path, :location def initialize(path, location) @path = path.to_s @location = location end def lines File.exist?(path) ? File.readlines(path) : [] end def code lines.pluck(location.start_column..) end def location_content code[location.start_line - 1..location.end_line - 1].join end def signature code[location.start_line - 1..location.start_line - 1].join end def content code.join end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/module_definition.rb
app/models/module_definition.rb
# frozen_string_literal: true ModuleDefinition = Struct.new(:namespace, :name, :qualified_name, :node, :location, :instance_methods, :class_methods, :included_modules, :extended_modules, :comments, :defined_files, :referenced_files) do include MethodFinders include RBSNamespaceHelpers def initialize( namespace: nil, name: nil, qualified_name: nil, node: nil, location: nil, instance_methods: [], class_methods: [], included_modules: [], extended_modules: [], comments: [], defined_files: [], referenced_files: [] ) super end def url(gem) Router.gem_version_module_path(gem.name, gem.version, self) end def eql?(other) qualified_name == other.qualified_name end def object_name "module" end def to_s "#{object_name} #{qualified_name}" end def to_param qualified_name end def title qualified_name end def qualified_namespace namespace.join("::") end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/namespace_reopen.rb
app/models/namespace_reopen.rb
# frozen_string_literal: true NamespaceReopen = Data.define(:path, :gem, :location) do def initialize(path:, gem:, location: nil) super end def relative_path path.delete_prefix("#{gem.unpack_data_path}/") end def url(gem = nil) Router.gem_version_file_path(gem.name, gem.version, relative_path) end def title relative_path end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/class_method.rb
app/models/class_method.rb
# frozen_string_literal: true class ClassMethod < MethodDefinition def url(gem) if target.is_a?(ModuleDefinition) Router.gem_version_module_class_method_path(gem.name, gem.version, target.qualified_name, name) elsif target.is_a?(ClassDefinition) Router.gem_version_class_class_method_path(gem.name, gem.version, target.qualified_name, name) else Router.gem_version_class_method_path(gem.name, gem.version, name) end end def object_name "::" end def class_method? true end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/instance_method.rb
app/models/instance_method.rb
# frozen_string_literal: true class InstanceMethod < MethodDefinition def url(gem) if target.is_a?(ModuleDefinition) Router.gem_version_module_instance_method_path(gem.name, gem.version, target.qualified_name, name) elsif target.is_a?(ClassDefinition) Router.gem_version_class_instance_method_path(gem.name, gem.version, target.qualified_name, name) else Router.gem_version_instance_method_path(gem.name, gem.version, name) end end def object_name "#" end def instance_method? true end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/gem_spec.rb
app/models/gem_spec.rb
# frozen_string_literal: true class GemSpec def self.latest_version_for(name) return nil if name.blank? Gem.latest_spec_for(name).try(:version) end def self.find(name, version = nil) return nil if name.nil? version ||= latest_version_for(name) return nil if version.nil? info = Gems::V2.info(name, version) return nil if info.nil? new(info) end def initialize(version_info) @version_info = version_info return if exists? download_gem unpack end def name @version_info["name"] end def version @version_info["version"] end def summary @version_info["summary"] end def description @version_info["description"] end def released_at Date.parse(@version_info["version_created_at"]) end def downloads @version_info["downloads"] end def gem_uri @version_info["gem_uri"] end def versions Gems.versions(name).uniq { |version| version["number"] } end def grouped_versions versions.group_by { |version| version["number"].split(".")[0..1].join(".") } end def namespaces classes + modules end def classes info.analyzer.classes.sort_by(&:qualified_name) end def modules info.analyzer.modules.sort_by(&:qualified_name) end def methods instance_methods + class_methods end def instance_methods info.analyzer.instance_methods.sort_by(&:name) end def class_methods info.analyzer.class_methods.sort_by(&:name) end def samples Types::Sample .where(gem_name: name) .where("gem_version LIKE ?", "#{version.to_s.split('-').first}%") end def type_sampled_methods samples.group(:receiver, :method_name).count.map do |(receiver, method_name), count| namespace = find_namespace(receiver) method = namespace&.find_method(method_name) [namespace, method, count] if namespace.present? && method.present? end.compact end delegate :count, to: :type_sampled_methods, prefix: true def all_methods methods + namespaces.flat_map(&:methods) end def methods_count methods.count + namespaces.sum { |namespace| namespace.methods.count } end def typing_progress ((type_sampled_methods_count.to_f / methods_count) * 100).round(1) end def top_level_modules modules.select { |mod| mod.namespace.blank? } end def top_level_classes classes.select { |klass| klass.namespace.blank? } end def most_used_constant constant = namespaces.map { |const| const.qualified_name.split("::").first }.flatten.tally.max_by(&:last) constant ? constant.first : name.capitalize end def find_class(name) classes.find { |klass| klass.qualified_name == name } end def find_class!(name) find_class(name) || raise(GemConstantNotFoundError, "Couldn't find class '#{name}'") end def find_module(name) modules.find { |namespace| namespace.qualified_name == name } end def find_module!(name) find_module(name) || raise(GemConstantNotFoundError, "Couldn't find module '#{name}'") end def find_namespace(name) find_module(name) || find_class(name) end def find_namespace!(name) find_namespace(name) || raise(GemConstantNotFoundError, "Couldn't find namespace '#{name}'") end def rbs_signature(require_samples: false) rbs_file = rbs_file_path(require_samples) return File.read(rbs_file) if File.exist?(rbs_file) rbs_method_signatures = namespaces.map { |namespace| namespace.rbs_signature(self, require_samples:) }.compact rbs_method_signatures.join("\n\n").tap do |content| File.write(rbs_file, content) end end def files metadata .files .select { |file| file.ends_with?(".rb") } .select { |file| file.start_with?("lib/", "app/") } end def markdown_files metadata.files.select { |file| file.end_with?(".md") } end def documentation_files metadata.files.select { |file| (file.include?("doc/") || file.include?("docs/")) && file.end_with?(".md") } end def guide_files metadata.files.select { |file| (file.include?("guide/") || file.include?("guides/")) && file.end_with?(".md") } end def rbs_files metadata.files.select { |file| file.end_with?(".rbs") } end def readme markdown_files.find { |file| file.downcase.include?("readme") } || markdown_files.first end def readme_content if readme File.read("#{unpack_data_path}/#{readme}") else "No README" end end def content_for_markdown(file) file = "#{file}.md" if markdown_files.include?(file) File.read("#{unpack_data_path}/#{file}") else %(File "#{file}" not found) end end def download_path "tmp/gems/#{name}".tap do |path| FileUtils.mkdir_p(path) end end def unpack_path "tmp/gems/#{name}/#{version}".tap do |path| FileUtils.mkdir_p(path) end end def unpack_data_path "#{unpack_path}/data".tap do |path| FileUtils.mkdir_p(path) end end def unpack_data_archive "#{unpack_path}/data.tar.gz" end def unpack_metadata_archive "#{unpack_path}/metadata.gz" end def unpack_metadata_file "#{unpack_path}/metadata" end def rbs_file_path(require_samples) "#{unpack_path}/#{name}_#{require_samples}.rbs" end def metadata @metadata ||= YAML.load_file( unpack_metadata_file, aliases: true, permitted_classes: [ Gem::Dependency, Gem::Requirement, Gem::Specification, Gem::Version, Gem::Version::Requirement, # TODO: not sure why Psych still complains about DisallowedClass for `Gem::Version::Requirement` Time, Symbol, ], ) rescue Psych::DisallowedClass => e Rails.logger.debug e.inspect Metadata.new end def download_filename "#{download_path}/#{version}.gem" end def exists? File.exist?(download_filename) end def download_gem File.open(download_filename, "w") do |file| file.binmode HTTParty.get(gem_uri, stream_body: true) do |fragment| file.write(fragment) end end end def unpack system("tar xvf #{download_filename} --directory #{unpack_path}") system("tar xvf #{unpack_data_archive} --directory #{unpack_data_path}") system("gunzip #{unpack_metadata_archive}") end def info @info ||= GemInfo.new(self) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/gem_search.rb
app/models/gem_search.rb
# frozen_string_literal: true class GemSearch def self.search(query) return [] if query.blank? Gems.search(query) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/metadata.rb
app/models/metadata.rb
# frozen_string_literal: true Metadata = Data.define(:files, :dependencies, :authors, :error) do def initialize(files: [], dependencies: [], authors: [], error: nil) super end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/concerns/rbs_namespace_helpers.rb
app/models/concerns/rbs_namespace_helpers.rb
# frozen_string_literal: true module RBSNamespaceHelpers def rbs_signature(gem, require_samples: true) rbs_method_signatures = methods.map { |method| method.rbs_signature(gem, require_samples:) }.compact return nil if rbs_method_signatures.empty? rbs_superclass = (defined?(superclass) && superclass) ? " < #{superclass.qualified_name}" : nil <<~RBS # #{defined_files.first.path.gsub("#{gem.unpack_data_path}/lib/", 'sig/')}s #{object_name} #{qualified_name}#{rbs_superclass} #{rbs_method_signatures.map { |sig| sig.gsub("\n", "\n ") }.join("\n ")} end RBS end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/concerns/rbs_helpers.rb
app/models/concerns/rbs_helpers.rb
# frozen_string_literal: true module RBSHelpers def rbs_signature(gem, require_samples: true) return nil if require_samples && samples(gem).empty? signature = "def #{class_method? ? 'self.' : ''}#{name}: (#{rbs_parameters(gem)}) -> #{rbs_return_value(gem)}" if custom_types.any? types = custom_types.uniq.map { |name, t| "type #{name} = #{t}" }.join("\n") "\n#{types}\n\n#{signature}" else signature end end def custom_types @custom_types ||= [] end private def rbs_parameters(gem) parameters = samples(gem).map(&:parameters).compact.flatten(1).group_by { |p| [p[0], p[1]] } params_to_rbs(parameters).join(", ") end def rbs_return_value(gem) return "void" if instance_method? && name == "initialize" return_values = samples(gem).map(&:return_value).compact if return_values.any? type_list_to_rbs(return_values, "return_value") else "untyped" end end def params_to_rbs(params) params.to_h.map do |(param_name, param_type), types| type_list = types.map(&:last) param_type_to_rbs_symbol(param_type, param_name, type_list_to_rbs(type_list, param_name)) end end def param_type_to_rbs_symbol(param_type, param_name, rbs_type) case param_type when "req" "#{rbs_type} #{param_name}" when "opt" "?#{rbs_type} #{param_name}" when "rest" "*#{rbs_type} #{param_name}" when "key", "keyreq" "#{param_name}: #{rbs_type}" when "keyopt" "?#{param_name}: #{rbs_type}" when "keyrest" "**#{rbs_type} #{param_name}" when "block" # TODO: fix block syntax # Example: def method: () { () -> untyped } -> untyped # "#{param_name}: #{rbs_type}" else raise "Don't know about param_type: #{param_type}" end end def type_to_rbs(type) case type when Array first = type.shift if first == "Array" if type.any? "Array[#{type.map { |t| type_to_rbs(t) }.join(', ')}]" else "Array" end elsif first == "Hash" hash_types = type.map { |t| t.map { |h| [h.first, type_to_rbs(h.second)].join(": ") }.join(", ") } _hash_type = "{ #{hash_types.first} }" if hash_types.uniq.one? "Hash" else first end else case type when "TrueClass" "true" when "FalseClass" "false" when "NilClass" "nil" else type end end end def type_list_to_rbs(type_list, param_name = nil) types = Array.wrap(type_list).map! { |type| type_to_rbs(type) }.uniq.compact if types.count("true").positive? && types.count("false").positive? types -= ["true", "false"] types << "bool" end if types.count("nil").positive? && types.uniq.count == 2 types -= ["nil"] types << "#{types.shift}?" end # TODO: if number of unique types is greater than (?) then the parameter is probably of type Object list = types.join(" | ") if types.none? "untyped" elsif types.one? list elsif types.uniq.count <= 3 "(#{list})" else type_name = [target.qualified_name, name, param_name].compact.map { |t| t.gsub("::", "__") }.join("_") custom_types << [type_name, list] type_name end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/concerns/method_finders.rb
app/models/concerns/method_finders.rb
# frozen_string_literal: true module MethodFinders def methods class_methods.sort_by(&:name) + instance_methods.sort_by(&:name) end def find_method(name) find_class_method(name) || find_instance_method(name) end def find_method!(name) find_method(name) || raise(GemConstantNotFoundError, "Couldn't find method '#{name}' on #{object_name} #{name}") end def find_class_method(name) class_methods.find { |class_method| class_method.name == name } end def find_instance_method(name) instance_methods.find { |instance_method| instance_method.name == name } end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/models/types/sample.rb
app/models/types/sample.rb
# frozen_string_literal: true class Types::Sample < ApplicationRecord validates :gem_name, :gem_version, :method_name, :location, :type_fusion_version, :application_name, :source_ip, presence: true # TODO: there are methods which don't have params. # Currently `[]` is considerd invalid since [].blank? returns true # # validates :parameters, presence: true # TODO: there are methods without return values # # validates :return_value, presence: true end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/mailers/application_mailer.rb
app/mailers/application_mailer.rb
# frozen_string_literal: true class ApplicationMailer < ActionMailer::Base default from: "from@example.com" layout "mailer" end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/channels/application_cable/channel.rb
app/channels/application_cable/channel.rb
# frozen_string_literal: true module ApplicationCable class Channel < ActionCable::Channel::Base end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/app/channels/application_cable/connection.rb
app/channels/application_cable/connection.rb
# frozen_string_literal: true module ApplicationCable class Connection < ActionCable::Connection::Base end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/seeds.rb
db/seeds.rb
# frozen_string_literal: true # This file should ensure the existence of records required to run the application in every environment (production, # development, test). The code here should be idempotent so that it can be executed at any point in every environment. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # # Example: # # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/schema.rb
db/schema.rb
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schema when running `bin/rails # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[7.1].define(version: 2023_12_12_112541) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "types_samples", force: :cascade do |t| t.string "gem_name" t.string "gem_version" t.string "receiver" t.string "method_name" t.string "location" t.string "type_fusion_version" t.string "application_name" t.string "source_ip" t.jsonb "parameters" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.jsonb "return_value" end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/migrate/20231212112539_add_service_name_to_active_storage_blobs.active_storage.rb
db/migrate/20231212112539_add_service_name_to_active_storage_blobs.active_storage.rb
# frozen_string_literal: true # This migration comes from active_storage (originally 20190112182829) class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] def up return unless table_exists?(:active_storage_blobs) return if column_exists?(:active_storage_blobs, :service_name) add_column :active_storage_blobs, :service_name, :string if (configured_service = ActiveStorage::Blob.service.name) ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) # rubocop:disable Rails/SkipsModelValidations end change_column :active_storage_blobs, :service_name, :string, null: false end def down return unless table_exists?(:active_storage_blobs) remove_column :active_storage_blobs, :service_name end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/migrate/20230825163543_change_types_sample_return_value_type.rb
db/migrate/20230825163543_change_types_sample_return_value_type.rb
# frozen_string_literal: true class ChangeTypesSampleReturnValueType < ActiveRecord::Migration[7.0] def change reversible do |direction| direction.up do change_column :types_samples, :return_value, :jsonb, using: "to_json(return_value)" end direction.down do change_column :types_samples, :return_value, :string, using: %(to_jsonb(return_value)->>0) end end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/migrate/20231212112540_create_active_storage_variant_records.active_storage.rb
db/migrate/20231212112540_create_active_storage_variant_records.active_storage.rb
# frozen_string_literal: true # This migration comes from active_storage (originally 20191206030411) class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] def change return unless table_exists?(:active_storage_blobs) # Use Active Record's configured type for primary key create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t| t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type t.string :variation_digest, null: false t.index [:blob_id, :variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true t.foreign_key :active_storage_blobs, column: :blob_id end end private def primary_key_type config = Rails.configuration.generators config.options[config.orm][:primary_key_type] || :primary_key end def blobs_primary_key_type pkey_name = connection.primary_key(:active_storage_blobs) pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } pkey_column.bigint? ? :bigint : pkey_column.type end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/migrate/20230813213022_create_types_samples.rb
db/migrate/20230813213022_create_types_samples.rb
# frozen_string_literal: true class CreateTypesSamples < ActiveRecord::Migration[7.0] def change create_table :types_samples do |t| t.string :gem_name t.string :gem_version t.string :receiver t.string :method_name t.string :location t.string :type_fusion_version t.string :application_name t.string :source_ip t.jsonb :parameters t.timestamps end end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/migrate/20231212112541_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb
db/migrate/20231212112541_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb
# frozen_string_literal: true # This migration comes from active_storage (originally 20211119233751) class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0] def change return unless table_exists?(:active_storage_blobs) change_column_null(:active_storage_blobs, :checksum, true) end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/db/migrate/20230815223413_add_return_value_to_types_samples.rb
db/migrate/20230815223413_add_return_value_to_types_samples.rb
# frozen_string_literal: true class AddReturnValueToTypesSamples < ActiveRecord::Migration[7.0] def change add_column :types_samples, :return_value, :string end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/test/application_system_test_case.rb
test/application_system_test_case.rb
# frozen_string_literal: true require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/test/test_helper.rb
test/test_helper.rb
# frozen_string_literal: true ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" require "rails/test_help" FactoryBot.find_definitions module ActiveSupport class TestCase # Run tests in parallel with specified workers parallelize(workers: :number_of_processors) # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # Add more helper methods to be used by all tests here... end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false
marcoroth/gem.sh
https://github.com/marcoroth/gem.sh/blob/8a4a44bdd857ea79114017608d73c5cd03c21dba/test/factories/types/sample.rb
test/factories/types/sample.rb
# frozen_string_literal: true FactoryBot.define do factory :type_sample, class: Types::Sample do gem_name { "railties" } gem_version { "7.0.6" } receiver { "Rails" } method_name { "env" } parameters { [] } return_value { "String" } location { "/test/file.rb:123" } application_name { "gem.sh" } source_ip { "127.0.0.1" } type_fusion_version { TypeFusion::VERSION } end end
ruby
MIT
8a4a44bdd857ea79114017608d73c5cd03c21dba
2026-01-04T17:48:24.521520Z
false