source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/022_add_spatial_bbox_geom_column_to_mapscans.rb
Ruby
mit
45
master
311
class AddSpatialBboxGeomColumnToMapscans < ActiveRecord::Migration def self.up add_column :mapscans, :bbox_geom, :st_polygon, :srid => 4326 add_index :mapscans, :bbox_geom, :using => :gist end def self.down remove_column :mapscans, :bbox_geom remove_index :mapscans, :bbox_geom end end
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/021_add_map_type_to_mapscan.rb
Ruby
mit
45
master
390
class AddMapTypeToMapscan < ActiveRecord::Migration def self.up add_column :mapscans, :map_type, :integer # 0 = index , 1 = map 2 = not a map (see Mapscan model) # is_map # Map.where('map = true').update_all(:map => true) #not map # Map.where('map_type = 2').update_all(:map => false) ...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/028_add_fields_for_placing_steps_to_map.rb
Ruby
mit
45
master
749
class AddFieldsForPlacingStepsToMap < ActiveRecord::Migration def self.up add_column :mapscans, :rough_lat, :decimal, :precision => 15, :scale => 10 add_column :mapscans, :rough_lon, :decimal, :precision => 15, :scale => 10 add_column :mapscans, :rough_centroid, :st_point, :srid => 4326 add_index :m...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/014_create_layers.rb
Ruby
mit
45
master
772
class CreateLayers < ActiveRecord::Migration def self.up create_table "layers" do |t| t.string :name t.text :description t.string :catnyp t.string :uuid t.string :parent_uuid t.boolean :is_visible, :default => true t.datetime :depicts_year t.datetime :c...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/030_add_gcp_touched_at_and_last_rectified_to_map.rb
Ruby
mit
45
master
308
class AddGcpTouchedAtAndLastRectifiedToMap < ActiveRecord::Migration def self.up add_column :mapscans, :rectified_at, :datetime add_column :mapscans, :gcp_touched_at, :datetime end def self.down remove_column :mapscans, :rectified_at remove_column :mapscans, :gcp_touched_at end end
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/20150531170559_create_versions.rb
Ruby
mit
45
master
457
class CreateVersions < ActiveRecord::Migration def change create_table :versions do |t| t.string :item_type, :null => false t.integer :item_id, :null => false t.string :event, :null => false t.string :whodunnit t.text :object t.datetime :created_at ...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/026_create_comments.rb
Ruby
mit
45
master
470
class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.string :title, :limit => 50, :default => "" t.text :comment, :default => "" t.references :commentable, :polymorphic => true t.references :user t.timestamps end add_index :comments, :...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/023_create_oauth_tables.rb
Ruby
mit
45
master
1,126
class CreateOauthTables < ActiveRecord::Migration def self.up create_table :client_applications do |t| t.string :name t.string :url t.string :support_url t.string :callback_url t.string :key, :limit => 20 t.string :secret, :limit => 40 t.integer :user_id t.timestam...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/20150624151012_create_flags.rb
Ruby
mit
45
master
394
class CreateFlags < ActiveRecord::Migration def change create_table :flags do |t| t.integer :flaggable_id t.string :flaggable_type t.string :reason t.text :message t.integer :reporter_id t.integer :closer_id t.timestamp :closed_at t.timestamp...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/017_add_map_boolean_to_mapscan.rb
Ruby
mit
45
master
229
class AddMapBooleanToMapscan < ActiveRecord::Migration def self.up add_column :mapscans, :map, :boolean, :default => true #Map.update_all(:map => true) end def self.down remove_column :mapscans, :map end end
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/018_add_bbox_to_layer.rb
Ruby
mit
45
master
299
class AddBboxToLayer < ActiveRecord::Migration def self.up add_column :layers, :bbox, :string Layer.reset_column_information #now update bbox info Layer.all.each do |l| l.set_bounds l.save! end end def self.down remove_column :layers, :bbox end end
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/006_add_nypl_metadata_fields.rb
Ruby
mit
45
master
485
class AddNyplMetadataFields < ActiveRecord::Migration def self.up add_column :mapscans, :nypl_digital_id, :string add_column :mapscans, :catnyp, :string add_column :mapscans, :uuid, :string add_column :mapscans, :parent_uuid, :string end def self.down remove_column :...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/20150521142529_create_imports.rb
Ruby
mit
45
master
361
class CreateImports < ActiveRecord::Migration def change create_table :imports do |t| t.integer :user_id t.integer :status t.integer :import_type t.string :uuid t.string :since_date t.string :until_date t.string :log_filename t.timestamps null: false t...
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/20150531170600_add_transaction_id_column_to_versions.rb
Ruby
mit
45
master
298
class AddTransactionIdColumnToVersions < ActiveRecord::Migration def self.up add_column :versions, :transaction_id, :integer add_index :versions, [:transaction_id] end def self.down remove_index :versions, [:transaction_id] remove_column :versions, :transaction_id end end
github
nypl-spacetime/nypl-warper
https://github.com/nypl-spacetime/nypl-warper
db/migrate/015_create_user_maps.rb
Ruby
mit
45
master
422
class CreateUserMaps < ActiveRecord::Migration def self.up create_table :my_maps do |t| t.integer :mapscan_id t.integer :user_id t.timestamps end add_index :my_maps, [:mapscan_id, :user_id], :unique =>true add_index :my_maps, :mapscan_id end def self.down remove_index :my_m...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
Gemfile
Ruby
mit
45
main
1,120
# frozen_string_literal: true source "https://rubygems.org" ruby "3.4.4" gem "rails", "~> 8.1.2", ">= 8.1.2.1" gem "bootsnap", require: false gem "csv" gem "daemons" gem "devise", "~> 5.0" gem "faker", "~> 3.8.0" gem "font-awesome-rails" gem "image_processing", "~> 1.14" gem "importmap-rails" gem "jbuilder" gem "lu...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/admin_helper.rb
Ruby
mit
45
main
8,527
# frozen_string_literal: true # rubocop:disable Metrics/ModuleLength module AdminHelper # Renders a table for index pages with sortable columns # @param collection [ActiveRecord::Relation] The records to display # @param columns [Array<Hash>] Column definitions with :attribute, :label, :sortable keys # @param ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components_helper.rb
Ruby
mit
45
main
892
# frozen_string_literal: true require "tailwind_merge" module ComponentsHelper def tw(*classes) TailwindMerge::Merger.new.merge(classes.join(" ")) end PRIMARY_CLASSES = " bg-primary text-primary-foreground hover:bg-primary/80 " SECONDARY_CLASSES = " bg-secondary text-secondary-foreground hover:bg-seconda...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/application_helper.rb
Ruby
mit
45
main
1,294
# frozen_string_literal: true module ApplicationHelper def ticker_stocks Stock.active.order(:ticker) end def format_money(cents) format("$%.2f", cents / 100.0) end def safe_url(url) uri = URI.parse(url) %w[http https].include?(uri.scheme) ? url : nil rescue URI::InvalidURIError nil ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components/checkbox_helper.rb
Ruby
mit
45
main
223
# frozen_string_literal: true module Components module CheckboxHelper def render_checkbox(label:, name:, **options) render "components/ui/checkbox", name: name, label: label, options: options end end end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components/button_helper.rb
Ruby
mit
45
main
1,654
# frozen_string_literal: true module Components module ButtonHelper def render_button(label = "", text: nil, variant: :default, as: :button, href: nil, data: {}, **options, &block) base_classes = base_class_styling variant_classes = case variant.to_sym when :default ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components/forms_helper.rb
Ruby
mit
45
main
295
# frozen_string_literal: true module Components module FormsHelper def render_form_with(**, &) form_with(**, builder: Shadcn::FormBuilder, &) end def render_form_for(obj, **opts, &) form_for(obj, **opts, builder: Shadcn::FormBuilder, html: opts, &) end end end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components/textarea_helper.rb
Ruby
mit
45
main
486
# frozen_string_literal: true module Components module TextareaHelper def render_textarea(name:, label: false, id: nil, value: nil, **options) options.reverse_merge!( rows: 3, required: false, disabled: false, readonly: false, class: "", label: false, placeholder: "Type here..." ) ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components/input_helper.rb
Ruby
mit
45
main
1,889
# frozen_string_literal: true module Components module InputHelper def render_input(name:, label: false, id: nil, type: :text, value: nil, **options) options[:class] = border_styling(options[:class]) options[:class] << case options[:variant] when :borderless ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/components/label_helper.rb
Ruby
mit
45
main
214
# frozen_string_literal: true module Components module LabelHelper def render_label(name:, label:, **options) render "components/ui/label", name: name, label: label, options: options end end end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/helpers/admin/form_helper.rb
Ruby
mit
45
main
1,290
# frozen_string_literal: true module Admin module FormHelper # Creates a form using the Admin::FormBuilder # Usage: admin_form_for @resource do |f| # f.text_field :name # f.email_field :email # f.submit_button # end def admin_form_for(record, options = {}...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/components/shadcn/form_builder.rb
Ruby
mit
45
main
1,792
# frozen_string_literal: true module Shadcn class FormBuilder < ActionView::Helpers::FormBuilder def label(method, options = {}) error_class = @object.errors[method].any? ? "error" : "" options[:class] = @template.tw("#{options[:class]} #{error_class}") @template.render_label(name: "#{object_na...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/jobs/stock_attribute_update_job.rb
Ruby
mit
45
main
285
# frozen_string_literal: true class StockAttributeUpdateJob < ApplicationJob queue_as :default def perform Stock.find_each do |stock| Rails.logger.info "Processing stock attribute update for #{stock.ticker}" StockAttributeUpdate.execute(stock) end end end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/jobs/monthly_portfolio_snapshot_job.rb
Ruby
mit
45
main
1,164
# frozen_string_literal: true class MonthlyPortfolioSnapshotJob < ApplicationJob queue_as :default def perform(target_date = Date.current, batch_size = 1000) Rails.logger.info "[RECURRING JOB] MonthlyPortfolioSnapshotJob starting at #{Time.current} (#{Time.zone})" Rails.logger.info "[RECURRING JOB] Curren...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/jobs/stock_prices_update_job.rb
Ruby
mit
45
main
3,045
# frozen_string_literal: true class StockPricesUpdateJob < ApplicationJob queue_as :default retry_on StandardError, wait: :exponentially_longer, attempts: 3 def perform(...) Rails.logger.info "Starting stock prices update job at #{Time.current}" @api_client = AlphaVantageApiClient.new stock_count ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/jobs/order_execution_job.rb
Ruby
mit
45
main
1,862
# frozen_string_literal: true class OrderExecutionJob < ApplicationJob queue_as :default retry_on StandardError, wait: :exponentially_longer, attempts: 3 def perform Rails.logger.info "[RECURRING JOB] OrderExecutionJob starting at #{Time.current} (#{Time.zone})" Rails.logger.info "[RECURRING JOB] Curre...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/portfolio.rb
Ruby
mit
45
main
2,312
# frozen_string_literal: true class Portfolio < ApplicationRecord include ::UrlHelpers belongs_to :user validate :user_must_be_student delegate :username, :student?, :school_name, :trading_enabled?, to: :user has_many :portfolio_transactions, dependent: :destroy has_many :portfolio_stocks, dependent: :d...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/classroom_enrollment.rb
Ruby
mit
45
main
2,558
# frozen_string_literal: true # Represents a student's enrollment in a classroom, supporting multiple # enrollments over time with historical tracking. # # A student can have multiple enrollment records for the same classroom # (e.g., enrolled in Fall 2023, then again in Spring 2024), and can be # enrolled in multiple...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/classroom.rb
Ruby
mit
45
main
4,057
# frozen_string_literal: true class Classroom < ApplicationRecord MIN_GRADE = 5 MAX_GRADE = 8 GRADE_RANGE = (MIN_GRADE..MAX_GRADE).to_a.freeze belongs_to :school_year has_one :school, through: :school_year has_one :year, through: :school_year delegate :name, to: :school, prefix: :school delegate :nam...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/teacher.rb
Ruby
mit
45
main
414
# frozen_string_literal: true class Teacher < User attr_accessor :school_id has_many :teacher_classrooms, dependent: :destroy has_many :classrooms, through: :teacher_classrooms before_validation :sync_username_from_email def display_name name.presence || email&.split("@")&.first || "Teacher" end ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/portfolio_position.rb
Ruby
mit
45
main
1,626
# frozen_string_literal: true class PortfolioPosition attr_reader :stock, :shares, :portfolio, :change_amount, :total_return_amount delegate :current_price, :price_cents, :ticker, to: :stock, prefix: :stock def initialize(stock:, shares:, portfolio: nil, financial_data: {}) @stock = stock @shares = sha...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/portfolio_transaction.rb
Ruby
mit
45
main
940
# frozen_string_literal: true class PortfolioTransaction < ApplicationRecord TRANSACTION_FEE_CENTS = 1_00 # deposit/witdrawal is for cash transactions ie grades and attendance # credit/debit is for stock transactions ie buy/sell stocks enum :transaction_type, { deposit: 0, withdrawal: 1, credit: 2, debit: 3, f...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/grade.rb
Ruby
mit
45
main
307
# frozen_string_literal: true class Grade < ApplicationRecord has_many :classroom_grades, dependent: :restrict_with_error has_many :classrooms, through: :classroom_grades validates :name, presence: true, uniqueness: { case_sensitive: false } validates :level, presence: true, uniqueness: true end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/portfolio_snapshot.rb
Ruby
mit
45
main
333
# frozen_string_literal: true class PortfolioSnapshot < ApplicationRecord belongs_to :portfolio validates :date, presence: true validates :worth_cents, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :portfolio_id, uniqueness: { scope: :date } def current_worth worth_cents / 100...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/quarter.rb
Ruby
mit
45
main
1,350
# frozen_string_literal: true class Quarter < ApplicationRecord belongs_to :school_year validates :number, presence: true, inclusion: { in: 1..4 }, uniqueness: { scope: :school_year_id } scope :ordered, -> { order(:number) } def next return first_quarter_of_next_year ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/stock.rb
Ruby
mit
45
main
1,018
# frozen_string_literal: true class Stock < ApplicationRecord has_many :portfolio_stocks, dependent: :restrict_with_error has_many :orders, dependent: :restrict_with_error validates :ticker, presence: true validates( :company_website, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/announcement.rb
Ruby
mit
45
main
793
# frozen_string_literal: true class Announcement < ApplicationRecord has_rich_text :content validates :title, presence: true, length: { maximum: 255 } validates :content, presence: true before_save :unfeature_other_announcements, if: :will_save_change_to_featured? scope :latest, -> { order(created_at: :de...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/grade_entry.rb
Ruby
mit
45
main
1,678
# frozen_string_literal: true class GradeEntry < ApplicationRecord belongs_to :grade_book belongs_to :user delegate :username, to: :user EARNINGS_PER_DAY_ATTENDANCE = 20 EARNINGS_FOR_A_GRADE = 3_00 EARNINGS_FOR_B_GRADE = 2_00 EARNINGS_FOR_IMPROVED_GRADE = 2_00 EARNINGS_FOR_PERFECT_ATTENDANCE = 1_00 ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/grade_book.rb
Ruby
mit
45
main
260
# frozen_string_literal: true class GradeBook < ApplicationRecord belongs_to :quarter belongs_to :classroom has_many :grade_entries, dependent: :destroy enum :status, { draft: "draft", verified: "verified", completed: "completed" } end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/order.rb
Ruby
mit
45
main
6,938
# frozen_string_literal: true class Order < ApplicationRecord include ApplicationHelper belongs_to :user belongs_to :stock belongs_to :portfolio_stock, optional: true belongs_to :portfolio_transaction, optional: true enum :status, { pending: 0, completed: 1, canceled: 2 }, default: :pending enum :actio...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/school_year.rb
Ruby
mit
45
main
367
# frozen_string_literal: true class SchoolYear < ApplicationRecord belongs_to :school belongs_to :year has_many :classrooms, dependent: :restrict_with_error has_many :quarters, dependent: :restrict_with_error delegate :name, to: :school, prefix: :school delegate :name, to: :year, prefix: :year def name...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/earnings_summary.rb
Ruby
mit
45
main
769
# frozen_string_literal: true class EarningsSummary attr_reader :portfolio def initialize(portfolio) @portfolio = portfolio end def attendance_earnings_cents sum_by_reason(:attendance_earnings) end def reading_earnings_cents sum_by_reason(:reading_earnings) end def math_earnings_cents ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/year.rb
Ruby
mit
45
main
1,082
# frozen_string_literal: true class Year < ApplicationRecord has_many :school_years, dependent: :destroy has_many :schools, through: :school_years has_many :classrooms, through: :school_years validates :name, presence: true, uniqueness: true scope :ordered_by_start_year, -> { order(Arel.sql("CAST(SUBSTRING...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/user.rb
Ruby
mit
45
main
2,069
# frozen_string_literal: true class User < ApplicationRecord include Discard::Model def destroy(*) soft_delete_guard discard end def destroy!(*) soft_delete_guard discard end def really_destroy! ActiveRecord::Base.instance_method(:destroy).bind(self).call end belongs_to :classro...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/teacher_classroom.rb
Ruby
mit
45
main
210
# frozen_string_literal: true class TeacherClassroom < ApplicationRecord belongs_to :teacher, class_name: "Teacher" belongs_to :classroom validates :teacher_id, uniqueness: { scope: :classroom_id } end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/school.rb
Ruby
mit
45
main
203
# frozen_string_literal: true class School < ApplicationRecord has_many :school_years, dependent: :restrict_with_error has_many :years, through: :school_years validates :name, presence: true end
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/models/student.rb
Ruby
mit
45
main
2,627
# frozen_string_literal: true class Student < User has_many :classroom_enrollments, dependent: :destroy has_many :classrooms, through: :classroom_enrollments # Ensure students have nil email by default (not empty string) after_initialize :set_default_email, if: :new_record? after_create :ensure_portfolio ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/bulk_student_import_service.rb
Ruby
mit
45
main
844
# frozen_string_literal: true class BulkStudentImportService ResultWithLineNumber = Struct.new(:result, :line_number) do delegate_missing_to :result end def self.import_from_csv(csv_file_path) results = [] CSV.foreach(csv_file_path, headers: true).with_index(2) do |row, csv_line_number| class...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/memorable_password_generator.rb
Ruby
mit
45
main
439
# frozen_string_literal: true # TODO: more robust solution later. class MemorablePasswordGenerator RANGE = (1..99) class << self def generate password = Faker::Superhero.name + rand(RANGE).to_s + Faker::Superhero.name normalize password end private def normalize(password) inval...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/transaction_fee_processor.rb
Ruby
mit
45
main
636
# frozen_string_literal: true class TransactionFeeProcessor def initialize(orders) @orders = orders @users = Set.new end def self.execute(...) new(...).execute end def execute ActiveRecord::Base.transaction do @orders.each do |order| add_transaction_fee order end end...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/import_student_service.rb
Ruby
mit
45
main
1,832
# frozen_string_literal: true class ImportStudentService Result = Struct.new(:success?, :student, :error_message, :action) do def created? action == :created end def skipped? action == :skipped end def failed? action == :failed end end def self.call(username:, classro...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/stock_attribute_update.rb
Ruby
mit
45
main
1,959
# frozen_string_literal: true require "net/http" require "json" class StockAttributeUpdate def initialize(stock) @stock = stock end def self.execute(stock) new(stock).execute end def execute return if stock.ticker.blank? log_start_update data = fetch_api_data return unless valid_...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/school_year_creation_service.rb
Ruby
mit
45
main
452
# frozen_string_literal: true class SchoolYearCreationService def initialize(school:, year:) @school = school @year = year end def call ActiveRecord::Base.transaction do school_year = SchoolYear.create!(school: @school, year: @year) (1..4).each do |quarter_number| Quarter.create!...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/alpha_vantage_api_client.rb
Ruby
mit
45
main
1,566
# frozen_string_literal: true require "net/http" require "json" class AlphaVantageApiClient class ApiError < StandardError; end class InvalidResponseError < ApiError; end def initialize @api_key = ENV.fetch("ALPHA_VANTAGE_API_KEY", nil) end def fetch_quote(symbol) return nil unless api_key_present...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/execute_order.rb
Ruby
mit
45
main
1,833
# frozen_string_literal: true class ExecuteOrder delegate :portfolio, :shares, :stock, to: :order, private: true delegate :price_cents, to: :stock, prefix: true, private: true def initialize(order) @order = order end def self.execute(...) new(...).execute end def execute return unless orde...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/services/distribute_earnings.rb
Ruby
mit
45
main
1,905
# frozen_string_literal: true class DistributeEarnings def initialize(grade_book) @grade_book = grade_book @previous_entries = find_previous_entries end def self.execute(...) new(...).execute end def execute return unless @grade_book.verified? ActiveRecord::Base.transaction do di...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/facades/classroom_facade.rb
Ruby
mit
45
main
1,190
# frozen_string_literal: true # Facade for classroom presentation logic class ClassroomFacade attr_reader :classroom def initialize(classroom) @classroom = classroom end # Get all students for this classroom (both via enrollments and legacy classroom_id) # # @return [ActiveRecord::Relation<Student>] ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/presenters/attendance_entry_presenter.rb
Ruby
mit
45
main
652
# frozen_string_literal: true class AttendanceEntryPresenter < BasePresenter def self.for_student(student) GradeEntry.where(user: student) .joins(grade_book: { quarter: { school_year: :year } }) .includes(grade_book: { quarter: { school_year: :year } }) .order("years.name ASC, quarters.number A...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/presenters/base_presenter.rb
Ruby
mit
45
main
405
# frozen_string_literal: true class BasePresenter attr_reader :object def initialize(object) @object = object end def method_missing(method_name, *, &) if object.respond_to?(method_name) object.public_send(method_name, *, &) else super end end def respond_to_missing?(method_n...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/portfolios_controller.rb
Ruby
mit
45
main
367
# frozen_string_literal: true class PortfoliosController < ApplicationController before_action :set_portfolio before_action :authenticate_user! def show authorize @portfolio @stocks = @portfolio.stocks @earnings_summary = EarningsSummary.new(@portfolio) end private def set_portfolio @por...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/stocks_controller.rb
Ruby
mit
45
main
526
# frozen_string_literal: true class StocksController < ApplicationController before_action :set_stock, only: %i[show] before_action :authenticate_user! before_action :set_portfolio def index @stocks = policy_scope(Stock).includes(portfolio_stocks: :portfolio) @portfolio = current_user.portfolio if cur...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/students_controller.rb
Ruby
mit
45
main
2,223
# frozen_string_literal: true class StudentsController < ApplicationController before_action :authenticate_user! before_action :ensure_teacher_or_admin before_action :set_classroom before_action :set_student, except: %i[new create] def new @student = Student.new(classroom: @classroom) end def edit;...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/schools_controller.rb
Ruby
mit
45
main
1,845
# frozen_string_literal: true class SchoolsController < ApplicationController before_action :set_school, only: %i[show edit update destroy] before_action :authenticate_user! # GET /schools or /schools.json def index @schools = School.all end # GET /schools/1 or /schools/1.json def show; end # GE...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/classroom_enrollments_controller.rb
Ruby
mit
45
main
1,718
# frozen_string_literal: true # Manages student enrollments in classrooms class ClassroomEnrollmentsController < ApplicationController before_action :authenticate_user! before_action :ensure_teacher_or_admin before_action :set_classroom before_action :set_enrollment, only: %i[destroy unenroll] # POST /class...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/grade_books_controller.rb
Ruby
mit
45
main
1,647
# frozen_string_literal: true # app/controllers/grade_books_controller.rb class GradeBooksController < ApplicationController before_action :set_classroom_and_grade_book before_action :authorize_grade_book def show; end def update GradeEntry.transaction do grade_entry_params.each do |id, attrs| ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/classrooms_controller.rb
Ruby
mit
45
main
3,333
# frozen_string_literal: true class ClassroomsController < ApplicationController before_action :set_classroom, only: %i[show edit update toggle_trading] before_action :authorize_classroom, except: %i[edit update toggle_trading] before_action :authorize_classroom_instance, only: %i[edit update toggle_trading] b...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/application_controller.rb
Ruby
mit
45
main
1,153
# frozen_string_literal: true class ApplicationController < ActionController::Base include Pundit::Authorization before_action :authenticate_user! before_action :configure_permitted_parameters, if: :devise_controller? before_action :set_navbar_stocks protected def ensure_teacher_or_admin authorize :...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/orders_controller.rb
Ruby
mit
45
main
2,972
# frozen_string_literal: true class OrdersController < ApplicationController before_action :set_order, only: %i[edit update cancel] before_action :set_stock, only: %i[new] before_action :set_shared_owned, only: %i[new edit] before_action :authenticate_user! def index @orders = policy_scope(Order) @o...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/announcements_controller.rb
Ruby
mit
45
main
356
# frozen_string_literal: true class AnnouncementsController < ApplicationController before_action :set_announcement, only: %i[show] def show; end private def set_announcement @announcement = Announcement.find(params.expect(:id)) rescue ActiveRecord::RecordNotFound redirect_to root_path, alert: t("...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/classrooms_controller.rb
Ruby
mit
45
main
2,209
# frozen_string_literal: true module Admin class ClassroomsController < BaseController before_action :set_classroom, only: %i[show edit update toggle_archive] def index @classrooms = apply_sorting(Classroom.all, default: "name") @breadcrumbs = [ { label: "Classrooms" } ] end ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/schools_controller.rb
Ruby
mit
45
main
2,422
# frozen_string_literal: true module Admin class SchoolsController < BaseController before_action :set_school, only: %i[show edit update destroy] def index sort_column = params[:sort].presence || "name" sort_direction = params[:direction] == "desc" ? :desc : :asc @schools = School.reorder...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/portfolio_transactions_controller.rb
Ruby
mit
45
main
2,825
# frozen_string_literal: true module Admin class PortfolioTransactionsController < BaseController before_action :set_portfolio_transaction, only: %i[show edit update destroy] def show # TODO: FIX # authorize @portfolio_transaction @breadcrumbs = [ { label: "Portfolio Transaction #...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/school_years_controller.rb
Ruby
mit
45
main
3,087
# frozen_string_literal: true module Admin class SchoolYearsController < BaseController before_action :set_school_year, only: %i[show edit update destroy] def index @school_years = apply_sorting(SchoolYear.includes(:school, :year), default: "id") @breadcrumbs = [ { label: "School Years"...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/base_controller.rb
Ruby
mit
45
main
890
# frozen_string_literal: true # Base controller for in-house admin. # All Admin controllers inherit from this controller. module Admin class BaseController < ApplicationController layout "admin" before_action :authenticate_admin private def authenticate_admin redirect_to root_path, alert: t(...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/students_controller.rb
Ruby
mit
45
main
7,134
# frozen_string_literal: true module Admin # rubocop:disable Metrics/ClassLength class StudentsController < BaseController include SoftDeletableFiltering before_action :set_student, only: %i[show edit update destroy add_transaction] before_action :set_discarded_student, only: %i[restore] def inde...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/announcements_controller.rb
Ruby
mit
45
main
2,237
# frozen_string_literal: true module Admin class AnnouncementsController < BaseController before_action :set_announcement, only: %i[show edit update destroy] def index sort_column = params[:sort].presence || "created_at" sort_direction = params[:direction] == "desc" ? :desc : :asc @announ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/stocks_controller.rb
Ruby
mit
45
main
2,531
# frozen_string_literal: true module Admin class StocksController < BaseController before_action :set_stock, only: %i[show edit update destroy] def index @stocks = apply_sorting(Stock.all, default: "ticker") @breadcrumbs = [ { label: "Stocks" } ] end def show @bread...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/teachers_controller.rb
Ruby
mit
45
main
3,452
# frozen_string_literal: true module Admin class TeachersController < BaseController include SoftDeletableFiltering before_action :set_teacher, only: %i[show edit update destroy] before_action :require_deactivated, only: %i[destroy] def index @teachers = apply_sorting(scoped_by_discard_status...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/component_demo_controller.rb
Ruby
mit
45
main
2,316
# frozen_string_literal: true module Admin class ComponentDemoController < BaseController # rubocop:disable Metrics/MethodLength def index # Demo data for table component - apply sorting before limit @users = User.all # Apply sorting if params present if params[:sort].present? ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/users_controller.rb
Ruby
mit
45
main
1,831
# frozen_string_literal: true module Admin class UsersController < BaseController before_action :set_user, only: %i[show edit update destroy] def index @users = apply_sorting(User.all, default: "username") @breadcrumbs = [ { label: "Users" } ] end def show @breadcru...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/teachers/deactivations_controller.rb
Ruby
mit
45
main
452
# frozen_string_literal: true module Admin module Teachers class DeactivationsController < BaseController before_action :set_teacher def create username = @teacher.username @teacher.discard redirect_back_or_to admin_teachers_path, notice: t(".notice", username: username) ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/admin/teachers/reactivations_controller.rb
Ruby
mit
45
main
469
# frozen_string_literal: true module Admin module Teachers class ReactivationsController < BaseController before_action :set_teacher def create username = @teacher.username @teacher.undiscard redirect_back_or_to admin_teachers_path, notice: t(".notice", username: username) ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/controllers/concerns/soft_deletable_filtering.rb
Ruby
mit
45
main
768
# frozen_string_literal: true module SoftDeletableFiltering extend ActiveSupport::Concern private # Scopes a resource class based on discard status query parameters # # @param resource_class [ActiveRecord::Base] The model class to scope # @return [ActiveRecord::Relation] Scoped collection based on params...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/policies/application_policy.rb
Ruby
mit
45
main
846
# frozen_string_literal: true class ApplicationPolicy attr_reader :user, :record def initialize(user, record) @user = user @record = record end def index? false end def show? false end def create? false end def new? create? end def update? false end def ed...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/policies/stock_policy.rb
Ruby
mit
45
main
1,191
# frozen_string_literal: true class StockPolicy < ApplicationPolicy # Show trading-related links (buy/sell/trade) when the user is a student # and has a portfolio (safeguard for nil portfolio) and the stock is not archived # (or if archived, user is holding it) and trading is enabled for their classroom. def s...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/policies/classroom_policy.rb
Ruby
mit
45
main
904
# frozen_string_literal: true class ClassroomPolicy < ApplicationPolicy def index? user&.teacher_or_admin? end def show? user&.teacher_or_admin? end def new? user.admin? end def edit? user.admin? end def create? user.admin? end def update? user.admin? end def tog...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/policies/grade_book_policy.rb
Ruby
mit
45
main
369
# frozen_string_literal: true class GradeBookPolicy < ApplicationPolicy def update? user_is_teacher_of_classroom? || user.admin? end def show? user_is_teacher_of_classroom? || user.admin? end def finalize? user.admin? end private def user_is_teacher_of_classroom? user.teacher? && re...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/policies/order_policy.rb
Ruby
mit
45
main
594
# frozen_string_literal: true class OrderPolicy < ApplicationPolicy def index? user.present? end def create? user.portfolio == record.portfolio end def update? user.portfolio == record.portfolio end def cancel? user.portfolio == record.portfolio end class Scope < ApplicationPolicy...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/policies/portfolio_policy.rb
Ruby
mit
45
main
370
# frozen_string_literal: true class PortfolioPolicy < ApplicationPolicy def show? return false if user.blank? return true if user.admin? return true if record.user_id == user.id user.teacher? && teacher_access? end private def teacher_access? teacher_ids = record.user&.classroom&.teacher...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
app/form_builders/admin/form_builder.rb
Ruby
mit
45
main
15,544
# frozen_string_literal: true module Admin # rubocop:disable Metrics/ClassLength class FormBuilder < ActionView::Helpers::FormBuilder # Tailwind CSS classes for form elements INPUT_CLASSES = "block w-full rounded-md border-0 py-2 px-3 text-gray-900 ring-1 ring-inset ring-gray-300 " \ "p...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
test/test_helper.rb
Ruby
mit
45
main
1,677
# frozen_string_literal: true if ENV["COVERAGE"] == "true" require "simplecov" SimpleCov.start "rails" do add_filter "/test/" add_group "Dashboards", "app/dashboards" add_group "Services", "app/services" add_group "Policies", "app/policies" end end ENV["RAILS_ENV"] ||= "test" require_relative ...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
test/application_system_test_case.rb
Ruby
mit
45
main
776
# frozen_string_literal: true require "test_helper" class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include Devise::Test::IntegrationHelpers # You can run the system test in an actual browser for visually validate the system test. # eg. TEST_DRIVER=chrome rails test test/system/student_trading...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
test/services/memorable_password_generator_test.rb
Ruby
mit
45
main
375
# frozen_string_literal: true require "test_helper" class MemorablePasswordGeneratorTest < ActiveSupport::TestCase test "generate returns a password" do password = MemorablePasswordGenerator.generate assert password.length.positive? assert password.match(/^\w+[0-9]+\w+$/), "Password should be in the fo...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
test/services/transaction_fee_processor_test.rb
Ruby
mit
45
main
1,417
# frozen_string_literal: true require "test_helper" class TransactionFeeProcessorTest < ActiveSupport::TestCase test "it applies 1 fee per student for multiple orders" do user_with_multiple_orders = create(:student) user_with_multiple_orders.portfolio.portfolio_transactions.create!(amount_cents: 100_00, tra...
github
rubyforgood/stocks-in-the-future
https://github.com/rubyforgood/stocks-in-the-future
test/services/import_student_service_test.rb
Ruby
mit
45
main
2,974
# frozen_string_literal: true require "test_helper" class ImportStudentServiceTest < ActiveSupport::TestCase def setup @classroom = create(:classroom) end test "call creates student successfully" do assert_difference("Student.count", 1) do result = ImportStudentService.call( username: "st...