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 | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/menu.rb | Ruby | mit | 19 | master | 2,166 | # frozen_string_literal: true
require 'gosu'
require_relative 'menu_item'
module SpaceInvaders
class Menu
def initialize(window, size)
@window = window
@items = []
@font_size = size
@items_with_coordinates = {}
end
def add_item(text, callback:)
@items << MenuItem.new(
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/new_game.rb | Ruby | mit | 19 | master | 1,200 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/menu_scene_component'
require_relative '../base/text_field'
require_relative 'menu'
require_relative '../db/operations'
module SpaceInvaders
class NewGame < MenuSceneComponent
attr_reader :need_start
def initialize(window, size)
s... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/scrollable_menu.rb | Ruby | mit | 19 | master | 2,279 | # frozen_string_literal: true
require_relative 'menu'
module SpaceInvaders
class ScrollableMenu < Menu
SCROLL_Y_OFFSET_BASE = 30
attr_reader :drawing_items
def draw(start_x, start_y)
calc_items_coordinates(start_x, scroll_y(start_y))
draw_visible_items
draw_scrollable_items
end
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/menu_entrance_text.rb | Ruby | mit | 19 | master | 1,436 | # frozen_string_literal: true
require_relative '../base/settings'
require_relative '../output/printable_text'
require_relative '../base/image_object'
module SpaceInvaders
class MenuEntranceText
include Settings
attr_reader :last_y
def initialize(options)
@x = options.fetch(:x)
@y = options... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/load_game.rb | Ruby | mit | 19 | master | 938 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/menu_scene_component'
require_relative '../db/operations'
require_relative 'scrollable_menu'
module SpaceInvaders
class LoadGame < MenuSceneComponent
attr_reader :loaded
def initialize(window, font_size)
super
@games = DBOp... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/aliens_scoreboard.rb | Ruby | mit | 19 | master | 2,029 | # frozen_string_literal: true
require 'gosu'
require_relative '../output/printable_text'
require_relative '../base/timer'
require_relative '../base/menu_scene_component'
module SpaceInvaders
class AliensScoreboard < MenuSceneComponent
ALIENS_TABLE_OFFSET_X = 65
def initialize(window, font_size)
super... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/menu_item.rb | Ruby | mit | 19 | master | 940 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/settings'
module SpaceInvaders
class MenuItem
ACTIVE_COLOR = Gosu::Color.argb(0xff_de2f2f)
DEFAULT_COLOR = Gosu::Color::WHITE
attr_reader :needs_redraw, :text, :active, :x, :y
alias needs_redraw? needs_redraw
def initialize... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/leaderboard.rb | Ruby | mit | 19 | master | 910 | # frozen_string_literal: true
require 'gosu'
require_relative '../db/operations'
require_relative '../base/menu_scene_component'
module SpaceInvaders
class Leaderboard < MenuSceneComponent
def initialize(window, font_size)
super
@leaders = DBOperations.find_max_scores(5)
end
def visible?
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/menu/continue_game.rb | Ruby | mit | 19 | master | 261 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/menu_scene_component'
require_relative '../db/operations'
module SpaceInvaders
class ContinueGame < MenuSceneComponent
def visible?
DBOperations.current_user
end
end
end |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/effects/explosion.rb | Ruby | mit | 19 | master | 742 | # frozen_string_literal: true
require_relative '../base/settings'
require_relative '../base/timer'
module SpaceInvaders
class Explosion
FRAME_DELAY_MSEC = 10
SPRITE = Settings::EFFECTS_DIR / 'explosion.png'
EXPLOSION_SIZE = 128
def initialize(coord_x, coord_y)
@tile_num = 0
@x = coord_x... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/scores/score.rb | Ruby | mit | 19 | master | 737 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/settings'
require_relative '../db/operations'
module SpaceInvaders
class Score
def initialize(options)
@x = options[:x] || 0
@y = options[:y] || 0
@font_size = 25
@score_obj = Gosu::Font.new(
options[:window],... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/scores/player_score.rb | Ruby | mit | 19 | master | 491 | # frozen_string_literal: true
require_relative 'score'
require_relative '../base/settings'
module SpaceInvaders
class PlayerScore < Score
def initialize(options)
super
@score_text = 'SCORE'
@score = 0
end
def draw(current_user)
@score_obj.draw_text("User: #{current_user}", @x, @... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/scores/hi_score.rb | Ruby | mit | 19 | master | 444 | # frozen_string_literal: true
require_relative 'score'
require_relative '../db/operations'
module SpaceInvaders
class HiScore < Score
attr_reader :hi_score
alias current hi_score
def initialize(options)
super
@score_text = 'RECORD'
end
def draw(current_user)
@hi_score ||= DBO... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/text_caret.rb | Ruby | mit | 19 | master | 781 | # frozen_string_literal: true
require_relative 'timer'
module SpaceInvaders
class TextCaret
CARET_COLOR = 0xffffffff
CARET_DELAY_MSEC = 500
VERTICAL_OFFSET = 3
def initialize(window)
@window = window
@visible = true
end
def draw(options)
if Timer.overtime?(CARET_DELAY_MSE... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/image_object.rb | Ruby | mit | 19 | master | 454 | # frozen_string_literal: true
require 'gosu'
module SpaceInvaders
class ImageObject
attr_reader :x, :y, :w, :h
def initialize(coord_x, coord_y, image_path)
@x = coord_x
@y = coord_y
@figure = Gosu::Image.new(image_path.to_s)
@w = @figure.width
@h = @figure.height
end
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/text_field.rb | Ruby | mit | 19 | master | 915 | # frozen_string_literal: true
require 'gosu'
require_relative 'settings'
require_relative 'text_caret'
module SpaceInvaders
class TextField < Gosu::TextInput
include Settings
attr_accessor :restrict
def initialize(window, font)
super()
@window = window
@font = font
@printed = f... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/settings.rb | Ruby | mit | 19 | master | 2,547 | # frozen_string_literal: true
require 'pathname'
require 'gosu'
module SpaceInvaders
module Settings
WIDTH = 800
HEIGHT = 600
CAPTION = 'Space Invaders'
SPACESHIP_SPEED = 3
SPACESHIP_LIFES = 3
BULLET_SPEED = 5
BULLET_DIRECTION_UP = -1
BULLET_DIRECTION_DOWN = 1
ALIENS_ROWS = 5
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/menu_scene_component.rb | Ruby | mit | 19 | master | 443 | # frozen_string_literal: true
require 'gosu'
require_relative 'settings'
module SpaceInvaders
class MenuSceneComponent
include Settings
def initialize(window, font_size)
@window = window
@font_size = font_size
@font = Gosu::Font.new(@window, FONT, @font_size)
@was_draw = false
e... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/game_scene.rb | Ruby | mit | 19 | master | 587 | # frozen_string_literal: true
require_relative 'settings'
require_relative 'image_object'
module SpaceInvaders
class GameScene
def initialize(width:, height:, window:)
@width = width
@height = height
@window = window
@bg = ImageObject.new(0, 0, Settings::IMAGES_PATH / 'space.png')
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/helpers.rb | Ruby | mit | 19 | master | 349 | # frozen_string_literal: true
require 'gosu'
require_relative 'settings'
module SpaceInvaders
module Helpers
def horizontal_center(obj)
Settings::WIDTH / 2 - obj.w / 2
end
def last_column_x(collection)
collection.max_by(&:x).x
end
def first_column_x(collection)
collection.min... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/base/timer.rb | Ruby | mit | 19 | master | 299 | # frozen_string_literal: true
require 'gosu'
module SpaceInvaders
class Timer
def self.overtime?(duration, freeze: nil)
@timestamp ||= Gosu.milliseconds
result = Gosu.milliseconds - @timestamp > duration
@timestamp = nil if result && !freeze
result
end
end
end |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/ground.rb | Ruby | mit | 19 | master | 350 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/settings'
module SpaceInvaders
class Ground
HEIGHT = 5
attr_reader :x, :y
def initialize(coord_x, coord_y)
@x = coord_x
@y = coord_y
end
def draw
Gosu.draw_rect(@x, @y, Settings::WIDTH, HEIGHT, Settings::B... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/mistery_alien.rb | Ruby | mit | 19 | master | 1,227 | # frozen_string_literal: true
require 'gosu'
require_relative '../../base/settings'
require_relative '../../base/timer'
module SpaceInvaders
class MisteryAlien < Alien
include Settings
MOVING_REDRAW_MSEC = 30
MISTERY_SOUND = SOUNDS_PATH / 'mistery.wav'
INITIAL_MOVE_DIRECTION = :right
MISTERY_IN... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/bullet.rb | Ruby | mit | 19 | master | 1,078 | # frozen_string_literal: true
require_relative '../../base/settings'
require_relative '../../base/image_object'
module SpaceInvaders
class Bullet < ImageObject
attr_accessor :target
include Settings
def initialize(options)
super options[:x], options[:y], options[:image_path]
@target = opti... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/gun.rb | Ruby | mit | 19 | master | 1,506 | # frozen_string_literal: true
require 'gosu'
require_relative 'bullet'
require_relative '../../base/image_object'
module SpaceInvaders
class Gun < ImageObject
def initialize(options)
@ammo = []
@reload_time_msec = 100
@prev_shoot_timestamp = Gosu.milliseconds
@shot_sound = Gosu::Sample.n... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/ship.rb | Ruby | mit | 19 | master | 2,370 | # frozen_string_literal: true
require 'gosu'
require_relative '../../base/settings'
require_relative '../../base/image_object'
require_relative '../../effects/explosion'
module SpaceInvaders
class Ship < ImageObject
include Settings
SHIP_IMAGE_PATH = IMAGES_PATH / 'ship.png'
HIT_SOUND = SOUNDS_PATH / '... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/animated_alien.rb | Ruby | mit | 19 | master | 872 | # frozen_string_literal: true
require 'gosu'
require_relative '../../base/settings'
require_relative 'alien'
module SpaceInvaders
class AnimatedAlien < Alien
attr_writer :gun
def initialize(coord_x, coord_y, alien_path)
super coord_x, coord_y, alien_path
@type = Settings::TILEABLE_ALIENS_PATH_... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/lifes.rb | Ruby | mit | 19 | master | 448 | # frozen_string_literal: true
require_relative '../../base/settings'
require_relative '../../base/image_object'
module SpaceInvaders
class Lifes < ImageObject
def initialize(coord_x, coord_y)
super coord_x, coord_y, Settings::IMAGES_PATH / 'heart.png'
end
def draw(amount)
coord_x = @x
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/alien.rb | Ruby | mit | 19 | master | 918 | # frozen_string_literal: true
require 'gosu'
require_relative '../../base/settings'
require_relative '../../base/image_object'
module SpaceInvaders
class Alien < ImageObject
HIT_ALIEN_SOUND = Settings::SOUNDS_PATH / 'alien_destroys.wav'
attr_reader :type
def initialize(coord_x, coord_y, alien_path)
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/game_objects/image_objects/ammo.rb | Ruby | mit | 19 | master | 1,573 | # frozen_string_literal: true
require 'gosu'
require_relative 'bullet'
require_relative '../../base/settings'
require_relative '../../base/image_object'
module SpaceInvaders
class Ammo < ImageObject
def initialize(options)
@bullets = []
@reload_time_msec = 100
@prev_shoot_timestamp = Gosu.mill... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/db/operations.rb | Ruby | mit | 19 | master | 1,351 | # frozen_string_literal: true
require_relative 'setup'
module SpaceInvaders
class DBOperations
class Errors
class OperationFailure < Mongo::Error::OperationFailure; end
end
class << self
include DB
def insert(data)
SCORES_COLLECTION.insert_one(data)
rescue Mongo::Error:... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/db/setup.rb | Ruby | mit | 19 | master | 330 | # frozen_string_literal: true
require 'mongo'
module SpaceInvaders
module DB
CONNECTION = Mongo::Client.new(
["#{ENV['MONGO_HOST']}:#{ENV['MONGO_PORT']}"],
database: ENV['MONGO_DB']
)
SCORES_COLLECTION = CONNECTION[:scores]
SCORES_COLLECTION.indexes.create_one({ user: 1 }, unique: true)
... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/scenes/game_over_scene.rb | Ruby | mit | 19 | master | 1,328 | # frozen_string_literal: true
require 'gosu'
require_relative '../output/printable_text'
require_relative '../base/settings'
require_relative '../base/timer'
require_relative '../base/game_scene'
module SpaceInvaders
class GameOverScene < GameScene
LABEL_DRAW_DELAY = 150
def initialize(width:, height:, win... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/scenes/main_scene.rb | Ruby | mit | 19 | master | 3,624 | # frozen_string_literal: true
require 'gosu'
require_relative '../db/operations'
require_relative '../base/game_scene'
require_relative '../base/timer'
require_relative '../base/settings'
require_relative '../aliens'
require_relative '../scores/player_score'
require_relative '../scores/hi_score'
require_relative '../g... |
github | fargelus/space-invaders | https://github.com/fargelus/space-invaders | lib/space_invaders/scenes/menu_scene.rb | Ruby | mit | 19 | master | 4,284 | # frozen_string_literal: true
require 'gosu'
require_relative '../base/settings'
require_relative '../base/timer'
require_relative '../menu/menu_entrance_text'
require_relative '../menu/menu'
require_relative '../menu/aliens_scoreboard'
require_relative '../menu/new_game'
require_relative '../menu/leaderboard'
require... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | Gemfile | Ruby | mit | 19 | master | 216 | # frozen_string_literal: true
source 'https://rubygems.org'
# Specify your gem's dependencies in jb.gemspec
gemspec
# For benchmarking
gem 'action_args'
gem 'benchmark-ips'
gem 'jb'
gem 'jbuilder'
gem 'rubocop' |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | simple_json.gemspec | Ruby | mit | 19 | master | 1,293 | # frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'simple_json/version'
Gem::Specification.new do |spec|
spec.name = 'simple_json'
spec.version = SimpleJson::VERSION
spec.authors = ['Jingyuan Zhao']
spec.em... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/test_helper.rb | Ruby | mit | 19 | master | 284 | # frozen_string_literal: true
ENV['RAILS_ENV'] ||= 'test'
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require File.expand_path('../test/dummy_app/config/environment.rb', __dir__)
Bundler.require
require 'action_args'
require 'debug'
require 'test/unit/rails/test_help' |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/bin/bench.rb | Ruby | mit | 19 | master | 2,049 | # frozen_string_literal: true
require 'action_dispatch/testing/integration'
require 'benchmark/ips'
require 'json'
SCENARIOS = [
{
label: 'jb',
path: '/benchmarks/jb.json',
decoder: ->(body) { JSON.parse(body) }
},
{
label: 'jbuilder',
path: '/benchmarks/jbuilder.json',
decoder: ->(body)... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/application.rb | Ruby | mit | 19 | master | 586 | # frozen_string_literal: true
require_relative 'boot'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_mailer/railtie'
require 'rails/test_unit/railtie'
Bundler.require(*Rails.groups)
require 'simple_json'
module Dummy
class Application < Rails::Application
# Settings in confi... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/routes.rb | Ruby | mit | 19 | master | 1,026 | # frozen_string_literal: true
Rails.application.routes.draw do
resources :posts, only: :show do
collection do
get :hello
end
end
namespace :simple_json_migration do
resources :posts, only: :show
resources :posts_with_wrong_template, only: :show
resources :posts_without_partial, only: :s... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/puma.rb | Ruby | mit | 19 | master | 2,027 | # frozen_string_literal: true
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minim... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/environments/production.rb | Ruby | mit | 19 | master | 3,136 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, a... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/environments/development.rb | Ruby | mit | 19 | master | 1,371 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/environments/test.rb | Ruby | mit | 19 | master | 1,556 | # frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "s... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/initializers/new_framework_defaults.rb | Ruby | mit | 19 | master | 387 | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.0 upgrade.
#
# Read the Rails 5.0 release notes for more info on each option.
# Configure SSL options to enable HSTS with subdomains. Previous versions had false.
Rai... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/config/initializers/simple_json/json.rb | Ruby | mit | 19 | master | 275 | # frozen_string_literal: true
require 'oj'
module SimpleJson
module Json
class Oj
def self.encode(json)
::Oj.dump(json, mode: :rails)
end
def self.decode(json_string)
::Oj.load(json_string, mode: :rails)
end
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/views/posts/show.simple_json.rb | Ruby | mit | 19 | master | 201 | # frozen_string_literal: true
{
title: @post.title,
user: partial!('users/_user', user: @post.user),
comments: @post.comments.map { |comment| partial!('comments/_comment', comment: comment) }
} |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/views/posts_with_cache/show.simple_json.rb | Ruby | mit | 19 | master | 246 | # frozen_string_literal: true
cache!(['posts', @post.id]) do
{
title: @post.title,
user: partial!('users/_user', user: @post.user),
comments: @post.comments.map { |comment| partial!('comments/_comment', comment: comment) }
}
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/views/benchmarks/_comment_simple_json.simple_json.rb | Ruby | mit | 19 | master | 1,625 | # frozen_string_literal: true
->(comment:, position:) {
length = comment.body.length
likes = comment.id * 3
dislikes = comment.id % 4
rating = (likes.to_f / (dislikes.zero? ? 1 : dislikes)).round(2)
{
id: comment.id,
body: comment.body,
metrics: {
length: length,
readability: (length... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/views/benchmarks/simple_json_oj.simple_json.rb | Ruby | mit | 19 | master | 585 | # frozen_string_literal: true
lengths = @comments.map { |comment| comment.body.length }
avg_length = lengths.empty? ? 0.0 : (lengths.sum.to_f / lengths.size).round(2)
{
meta: {
total_comments: @comments.size,
longest_comment_length: lengths.max || 0,
average_comment_length: avg_length,
tags: %w[benc... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/views/simple_json_migration/posts_with_wrong_template/show.simple_json.rb | Ruby | mit | 19 | master | 208 | # frozen_string_literal: true
{
title: "~#{@post.title}~",
user: partial!('users/_user', user: @post.user),
comments: @post.comments.map { |comment| partial!('comments/_comment', comment: comment) }
} |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/views/simple_json_migration/posts_without_partial/show.simple_json.rb | Ruby | mit | 19 | master | 265 | # frozen_string_literal: true
{
title: @post.title,
user: partial!('users/_user', user: @post.user),
comments: @post.comments.map do |comment|
partial!('simple_json_migration/posts_without_partial/_comment', comment: comment)
end
} |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/controllers/benchmarks_controller.rb | Ruby | mit | 19 | master | 544 | # frozen_string_literal: true
class BenchmarksController < ApplicationController
before_action :prepare_comments
def self.comments
@comments ||= 1.upto(1000).map { |i| Comment.new(i, nil, "comment #{i}") }
end
def jb
end
def jbuilder
end
def simple_json_oj
SimpleJson.json_module = SimpleJso... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/controllers/api/posts_controller.rb | Ruby | mit | 19 | master | 337 | # frozen_string_literal: true
if Rails::VERSION::MAJOR >= 5
module Api
class PostsController < ActionController::API
include SimpleJson::SimpleJsonRenderable
def show(id)
@post = Post.find id
end
def renamed_show(id)
@post = Post.find id
render :show
end
... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/controllers/simple_json_migration/posts_without_template_controller.rb | Ruby | mit | 19 | master | 219 | # frozen_string_literal: true
module SimpleJsonMigration
class PostsWithoutTemplateController < ApplicationController
include SimpleJson::Migratable
def show(id)
@post = Post.find id
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/controllers/simple_json_migration/posts_controller.rb | Ruby | mit | 19 | master | 204 | # frozen_string_literal: true
module SimpleJsonMigration
class PostsController < ApplicationController
include SimpleJson::Migratable
def show(id)
@post = Post.find id
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/controllers/simple_json_migration/posts_with_wrong_template_controller.rb | Ruby | mit | 19 | master | 221 | # frozen_string_literal: true
module SimpleJsonMigration
class PostsWithWrongTemplateController < ApplicationController
include SimpleJson::Migratable
def show(id)
@post = Post.find id
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/controllers/simple_json_migration/posts_without_partial_controller.rb | Ruby | mit | 19 | master | 218 | # frozen_string_literal: true
module SimpleJsonMigration
class PostsWithoutPartialController < ApplicationController
include SimpleJson::Migratable
def show(id)
@post = Post.find id
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/models/comment.rb | Ruby | mit | 19 | master | 301 | # frozen_string_literal: true
Comment = Struct.new :id, :post, :body do
post = Post.find 1
@all = [new(1, post, 'comment 1'), new(2, post, 'comment 2'), new(3, post, 'comment 3')]
class << self
attr_reader :all
def find(id)
@all.detect { |c| c.id == id.to_i }
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/models/user.rb | Ruby | mit | 19 | master | 207 | # frozen_string_literal: true
User = Struct.new :id, :name do
@all = [new(1, 'user 1')]
class << self
attr_reader :all
def find(id)
@all.detect { |u| u.id == id.to_i }
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/models/post.rb | Ruby | mit | 19 | master | 334 | # frozen_string_literal: true
Post = Struct.new :id, :user, :title do
user = User.find 1
@all = [new(1, user, 'post 1'), new(2, user, 'post 2')]
class << self
attr_reader :all
def find(id)
@all.detect { |p| p.id == id.to_i }
end
end
def comments
Comment.all.select { |c| c.post == sel... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/dummy_app/app/simple_jsons/posts_with_multiple_view_paths/show.simple_json.rb | Ruby | mit | 19 | master | 223 | # frozen_string_literal: true
{
title: @post.title,
user: partial!('users/_user', user: @post.user),
comments: @post.comments.map { |comment| partial!('posts_with_multiple_view_paths/_comment', comment: comment) }
} |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/unit/simple_json_template_test.rb | Ruby | mit | 19 | master | 6,134 | # frozen_string_literal: true
require 'test_helper'
class SimpleJsonTemplateTest < Test::Unit::TestCase
# -> { body } form
test 'converts simple lambda with braces' do
source = '-> { "hello" }'
result = call_method(source, :foo)
assert_equal 'def foo; "hello" ;end', result
end
# ->(params) { bod... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/html_test.rb | Ruby | mit | 19 | master | 248 | # frozen_string_literal: true
require 'test_helper'
class SimpleJsonTest < ActionDispatch::IntegrationTest
test 'bypass simple_json when HTML requested' do
get '/posts/1.html'
assert_includes response.body, "HTML for post 1"
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/json_module_test.rb | Ruby | mit | 19 | master | 706 | # frozen_string_literal: true
require 'test_helper'
class JsonModuleTest < ActionDispatch::IntegrationTest
test 'The template correctly renders a JSON' do
SimpleJson.json_module = ActiveSupport::JSON
get '/posts/1.json'
json = if response.respond_to?(:parsed_body)
response.parsed_body
... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/migration_test.rb | Ruby | mit | 19 | master | 1,817 | # frozen_string_literal: true
require 'test_helper'
class MigrationTest < ActionDispatch::IntegrationTest
test 'The template correctly renders a JSON' do
get '/simple_json_migration/posts/1.json'
json = if response.respond_to?(:parsed_body)
response.parsed_body
else
JSO... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/action_controller_api_test.rb | Ruby | mit | 19 | master | 529 | # frozen_string_literal: true
require 'test_helper'
if Rails::VERSION::MAJOR >= 5
class ActionControllerAPITest < ActionDispatch::IntegrationTest
test 'The template correctly renders a JSON' do
get '/api/posts/1.json'
json = response.parsed_body
assert_equal json, { 'title' => 'post 1' }
... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/multiple_view_paths_test.rb | Ruby | mit | 19 | master | 1,537 | # frozen_string_literal: true
require 'test_helper'
class MultipleViewPathsTest < ActionDispatch::IntegrationTest
test 'The template correctly renders a JSON' do
SimpleJson.template_paths = [
'app/views',
'app/simple_jsons'
]
get '/posts_with_multiple_view_paths/1.json'
json = if respon... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/cache_test.rb | Ruby | mit | 19 | master | 1,840 | # frozen_string_literal: true
require 'test_helper'
class SimpleJsonTest < ActionDispatch::IntegrationTest
test 'The response will be cached' do
Rails.cache.clear
get '/posts_with_cache/1.json'
cache = Rails.cache.read([SimpleJson.cache_key_prefix, 'posts', 1])
assert_equal cache, {
title: '... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | test/features/simple_json_test.rb | Ruby | mit | 19 | master | 1,687 | # frozen_string_literal: true
require 'test_helper'
class SimpleJsonTest < ActionDispatch::IntegrationTest
test 'The template correctly renders a JSON' do
get '/posts/1.json'
json = if response.respond_to?(:parsed_body)
response.parsed_body
else
JSON.parse response.body... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/simple_json.rb | Ruby | mit | 19 | master | 1,261 | # frozen_string_literal: true
require 'simple_json/version'
require 'simple_json/simple_json_renderable'
require 'simple_json/simple_json_renderer'
require 'simple_json/simple_json_template'
require 'simple_json/migratable'
require 'simple_json/simple_json_renderer_for_migration'
module SimpleJson
@config = {
... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/simple_json/simple_json_template.rb | Ruby | mit | 19 | master | 1,224 | # frozen_string_literal: true
module SimpleJson
class SimpleJsonTemplate
def initialize(path)
@path = path
@source = File.read(path)
end
def define_to_class(klass, method_name)
method_string = to_method_string(method_name)
klass.class_eval(method_string, @path)
method_name... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/simple_json/simple_json_renderer_for_migration.rb | Ruby | mit | 19 | master | 1,063 | # frozen_string_literal: true
module SimpleJson
class SimpleJsonRendererForMigration < SimpleJsonRenderer
@templates_loaded = false
def partial!(template_name, **params)
if renderer(template_name)
render(template_name, **params)
else
warn_template_not_exist(template_name)
... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/simple_json/migratable.rb | Ruby | mit | 19 | master | 1,708 | # frozen_string_literal: true
module SimpleJson
# The module for migration from jbuilder to simple json.
# Using this will render view twice, and may cause http response headers change.
#
# DO NOT INCLUDE THIS IN PRODUCTION!
#
# class XXXController < ActionController::Base
# include SimpleJson::Sim... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/simple_json/simple_json_renderable.rb | Ruby | mit | 19 | master | 2,545 | # frozen_string_literal: true
module SimpleJson
# The module for overriding rendering with SimpleJson
#
# class XXXController < ActionController::Base
# include SimpleJson::SimpleJsonRenderable
#
# ...
# end
module SimpleJsonRenderable
extend ActiveSupport::Concern
# monkey-patch f... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/simple_json/simple_json_renderer.rb | Ruby | mit | 19 | master | 3,683 | # frozen_string_literal: true
module SimpleJson
class SimpleJsonRenderer
class TemplateNotFound < RuntimeError; end
attr_reader :controller
@templates_loaded = false
class << self
def templates_loaded?
@templates_loaded
end
def load_all_templates!
@renderers = {}... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/generators/rails/scaffold_controller_generator.rb | Ruby | mit | 19 | master | 290 | # frozen_string_literal: true
require 'rails/generators'
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
module Rails
module Generators
class ScaffoldControllerGenerator
hook_for :simple_json, type: :boolean, default: true
end
end
end |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/generators/rails/simple_json_generator.rb | Ruby | mit | 19 | master | 1,011 | # frozen_string_literal: true
require 'rails/generators/named_base'
require 'rails/generators/resource_helpers'
module Rails
module Generators
class SimpleJsonGenerator < NamedBase # :nodoc:
include Rails::Generators::ResourceHelpers
source_root File.expand_path('../templates', __FILE__)
arg... |
github | aktsk/simple_json | https://github.com/aktsk/simple_json | lib/generators/rails/templates/index.simple_json.rb | Ruby | mit | 19 | master | 264 | @<%= plural_table_name %>.map do |<%= singular_table_name %>|
{
<% attributes_names.each do |attr| -%>
<%= attr %>: <%= singular_table_name %>.<%= attr %>,
<% end -%>
url: <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
}
end |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | sidekiq-belt.gemspec | Ruby | mit | 19 | main | 1,593 | # frozen_string_literal: true
require_relative "lib/sidekiq/belt/version"
Gem::Specification.new do |spec|
spec.name = "sidekiq-belt"
spec.version = Sidekiq::Belt::VERSION
spec.authors = ["Danilo Jeremias da Silva"]
spec.email = ["daniloj.dasilva@gmail.com"]
spec.summary = "This Ruby gem enhances the capab... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | Gemfile | Ruby | mit | 19 | main | 306 | # frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in sidekiq-belt.gemspec
gemspec
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.21"
gem "rubocop-rake"
gem "rubocop-rspec"
group :development, :test do
gem "byebug"
gem "simplecov"
end |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/spec_helper.rb | Ruby | mit | 19 | main | 509 | # frozen_string_literal: true
require "simplecov"
SimpleCov.start :test_frameworks do
# enable_coverage :branch
# minimum_coverage line: 100, branch: 85
end
require "sidekiq/belt"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path ... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt_spec.rb | Ruby | mit | 19 | main | 1,870 | # frozen_string_literal: true
RSpec.describe Sidekiq::Belt do
it "has a version number" do
expect(Sidekiq::Belt::VERSION).not_to be_nil
end
describe ".use!" do
before do
allow(Sidekiq::Belt::Community::Files).to receive(:use!).and_return(true)
allow(Sidekiq::Belt::Pro::Files).to receive(:use... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/web_action_helper_spec.rb | Ruby | mit | 19 | main | 1,480 | # frozen_string_literal: false
RSpec.describe(Sidekiq::WebActionHelper) do
describe "ERB" do
let(:dummy_web_action) do
Class.new do
def env
{ "PATH_INFO" => "/" }
end
def render(_engine, content, _options = {})
content
end
end
end
before d... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/web_router_helper_spec.rb | Ruby | mit | 19 | main | 665 | # frozen_string_literal: true
RSpec.describe(Sidekiq::WebRouterHelper) do
describe ".render" do
let(:dummy_web_router) do
Class.new
end
let(:instance_web_router) do
dummy_web_router.new
end
it "replaces the page content with the block content" do
dummy_web_router.prepend(descr... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt/ent/periodic_pause_spec.rb | Ruby | mit | 19 | main | 761 | # frozen_string_literal: false
require "sidekiq"
require "sidekiq/web"
RSpec.describe(Sidekiq::Belt::Ent::PeriodicPause) do
describe ".use!" do
before do
stub_const("Sidekiq::Periodic", Module.new)
allow(described_class).to receive(:require).and_return(true)
allow(Sidekiq::Web.configure).to r... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt/ent/periodic_run_spec.rb | Ruby | mit | 19 | main | 2,144 | # frozen_string_literal: true
require "sidekiq"
require "sidekiq/web"
RSpec.describe(Sidekiq::Belt::Ent::PeriodicRun) do
describe ".run" do
let(:options) { { "args" => ["def"] }.to_json }
let(:dummy_job_class) do
Class.new do
include Sidekiq::Worker
end
end
let(:loop_class) do
... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt/ent/files_spec.rb | Ruby | mit | 19 | main | 2,122 | # frozen_string_literal: true
require "sidekiq"
RSpec.describe(Sidekiq::Belt::Ent::Files) do
describe ".use!" do
before do
allow(Sidekiq::Belt::Ent::PeriodicPause).to receive(:use!).and_return(true)
allow(Sidekiq::Belt::Ent::PeriodicRun).to receive(:use!).and_return(true)
allow(Sidekiq::Belt::... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt/ent/periodic_sort_spec.rb | Ruby | mit | 19 | main | 1,742 | # frozen_string_literal: true
require "sidekiq"
require "sidekiq/web"
RSpec.describe(Sidekiq::Belt::Ent::PeriodicSort) do
describe ".each" do
let(:dummy_class) do
Class.new do
def initialize(lids)
@lids = lids
end
end
end
let(:jobs) do
[
Sidekiq::Peri... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt/community/run_job_spec.rb | Ruby | mit | 19 | main | 2,852 | # frozen_string_literal: true
require "sidekiq"
require "sidekiq/web"
RSpec.describe(Sidekiq::Belt::Community::RunJob) do
describe ".use!" do
before do
allow(Sidekiq::Web.configure).to receive(:register).and_call_original
end
it "injects the code" do
described_class.use!
expect(Sidek... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | spec/sidekiq/belt/pro/files_spec.rb | Ruby | mit | 19 | main | 578 | # frozen_string_literal: true
require "sidekiq"
RSpec.describe(Sidekiq::Belt::Pro::Files) do
describe ".use!" do
context "when Sidekiq is not Pro" do
before do
allow(Sidekiq).to receive(:pro?).and_return(false)
end
it "returns nil" do
expect(described_class.use!([:all])).to be... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/web_router_helper.rb | Ruby | mit | 19 | main | 471 | # frozen_string_literal: true
require "sidekiq/web/helpers"
require "sidekiq/web/router"
require_relative "web_action_helper"
module Sidekiq
module WebRouterHelper
def replace_content(path, &block)
Sidekiq::Config::DEFAULTS[:replace_views] ||= {}
Sidekiq::Config::DEFAULTS[:replace_views][path.to_s] ... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/belt.rb | Ruby | mit | 19 | main | 891 | # frozen_string_literal: true
require "sidekiq"
require_relative "belt/version"
require "sidekiq/web"
require_relative "web_action_helper"
require_relative "web_router_helper"
require_relative("belt/community/files")
require_relative("belt/ent/files")
require_relative("belt/pro/files")
module Sidekiq
module Belt
... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/web_action_helper.rb | Ruby | mit | 19 | main | 1,378 | # frozen_string_literal: true
require "sidekiq/web/helpers"
require "sidekiq/web/action"
module Sidekiq
module WebActionHelper
class ERB < ::ERB
def initialize(content)
replace_views = Sidekiq::Config::DEFAULTS[:replace_views] || {}
replace_views.each do |key, content_blocks|
ro... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/belt/community/force_kill.rb | Ruby | mit | 19 | main | 1,498 | # frozen_string_literal: true
require "sidekiq/web"
require "sidekiq/web/helpers"
module Sidekiq
module Belt
module Community
module ForceKill
def kill!
signal("KILL")
end
module SidekiqForceKill
def self.registered(app)
app.replace_content("/busy")... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/belt/community/run_job.rb | Ruby | mit | 19 | main | 2,202 | # frozen_string_literal: true
require "sidekiq/web"
require "sidekiq/web/helpers"
module Sidekiq
module Belt
module Community
module RunJob
def self.list_grouped_jobs
jobs = {}
Sidekiq::Belt.config.run_jobs.each_with_index do |job, i|
job.transform_keys(&:to_sym)
... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/belt/community/files.rb | Ruby | mit | 19 | main | 672 | # frozen_string_literal: true
require "sidekiq"
require_relative "run_job"
require_relative "top_label"
require_relative "force_kill"
module Sidekiq
module Belt
module Community
module Files
def self.use!(options = [:all])
Sidekiq::Belt::Community::RunJob.use! if should_use?(:run_job, o... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/belt/community/top_label.rb | Ruby | mit | 19 | main | 1,766 | # frozen_string_literal: true
require "sidekiq/web"
require "sidekiq/web/helpers"
module Sidekiq
module Belt
module Community
class TopLabel
def self.use!
Sidekiq::WebActionHelper.change_layout do |content|
Sidekiq::Belt::Community::TopLabel.new(content).apply
end
... |
github | dannnylo/sidekiq-belt | https://github.com/dannnylo/sidekiq-belt | lib/sidekiq/belt/ent/files.rb | Ruby | mit | 19 | main | 725 | # frozen_string_literal: true
require "sidekiq"
require_relative "periodic_pause"
require_relative "periodic_run"
require_relative "periodic_sort"
module Sidekiq
module Belt
module Ent
module Files
def self.use!(options = [:all])
return unless Sidekiq.ent?
Sidekiq::Belt::Ent:... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.