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 | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/load.rb | Ruby | mit | 187 | master | 1,208 | require "rghost/ps_object"
module RGhost::Load
# Loads library
def self.library(name, type = :ps)
# PsObject.new File.open(File.dirname(__FILE__)+File::SEPARATOR+type.to_s+File::SEPARATOR+name.to_s+"."+type.to_s).readlines.join("")
RGhost::PsObject.new("(#{name}.#{type}) runlibfile\n")
end
def self.rg... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/text.rb | Ruby | mit | 187 | master | 1,379 | require "rghost/ps_object"
require "rghost/units"
require "rghost/font"
require "rghost/ruby_to_ps"
# Wraps the text so as the it fits on the page(:area_x). Wrapping happens at whitespace characters without hyphenation.
# Additionally you can make use of predefined tag and the special tag <br/> to break row. You can di... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/border.rb | Ruby | mit | 187 | master | 2,140 | # Border object render a border around of vector shapes. Its sketch can be a combination of color, dashes, line joins and line caps.
# Usually its use inside of object facades, such as, Document, CallbackFacade and PsFacade as parameter :border, for example:
# d=Document.new
# d.horizontal_line :middle, :border => { ... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/textarea.rb | Ruby | mit | 187 | master | 2,465 | require "rghost/ps_object"
require "rghost/units"
require "rghost/font"
require "rghost/ruby_to_ps"
require "rghost/parse_text"
# TextArea wraps the text so as the it fits in a box of a given width. Wrapping happens at whitespace characters without hyphenation.
# Additionally you can make use of predefined tag and the ... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/shape_content.rb | Ruby | mit | 187 | master | 526 | # Responsible for fill shapes
class RGhost::ShapeContent < RGhost::PsObject
DEFAULT_OPTIONS = {
fill: true, color: "#F0FFFF"
}
# You can use parameter :color(facade for Color.create) or disable using :fill => false
def initialize(options = {})
super("") {}
@options = DEFAULT_OPTIONS.dup.merge(optio... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/horizontal_line.rb | Ruby | mit | 187 | master | 1,267 | require "rghost/ps_object"
require "rghost/units"
# Creates horizontal line on the current row.
class RGhost::HorizontalLine < RGhost::PsObject
DEFAULT_OPTIONS = {start_in: :limit_left, size: :area_x,
border: RGhost::Border::DEFAULT_OPTIONS}
# Examples
#
# Drawing line on middle
#
# do... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/static_document_callback.rb | Ruby | mit | 187 | master | 374 | require "rghost/ps_object"
require "rghost/function"
class RGhost::StaticDocumentCallback < RGhost::Function # :nodoc:
ACCEPT = [:before_document_create,
:first_page,
:last_page,
:after_document_create]
def initialize(name, &block)
raise NameError.new("#{name} no accept in #{self.class}") unless A... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/cursor.rb | Ruby | mit | 187 | master | 3,767 | require "rghost/point"
require "rghost/ps_object"
require "rghost/point_with_command"
# It resposible to cursor manipulate. Use it to position objects on the page.
class RGhost::Cursor < RGhost::PsObject
# The class method goto positioned the cursor based on page row number. Example:
# d=Document.new
# d.goto_r... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/image.rb | Ruby | mit | 187 | master | 688 | require "rghost/ps_object"
# Super class of GIF and JPEG.
class RGhost::Image < RGhost::PsObject
DEFAULT_OPTIONS = {x: :limit_left, y: 1, zoom: 100, rotate: 0}
def initialize(image_path, options = {})
super("")
@options = DEFAULT_OPTIONS.dup.merge(options)
@file = image_path
end
# Facade method fo... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/callback.rb | Ruby | mit | 187 | master | 1,865 | require "rghost/ps_object"
require "rghost/ruby_to_ps"
# Callbacks are custom code blocks defined inside of Document.
# All callbacks received implicitly a instance of PsFacade can be creates any PsObject.
# The callbacks's execution depend of the algorithims predefined in Postscript core library.
# There are two kind... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/document_callback_facade.rb | Ruby | mit | 187 | master | 2,022 | # This module is included inside of Document class. It will creates methods to easy the use.
#===Callback execution order
# Example for a document with 4 pages, looking at the picture you can see the order in which the callbacks are executed
#
# link:images/pages_rghost.png
module RGhost::DocumentCallbackFacade
# Ex... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/rectangle_link.rb | Ruby | mit | 187 | master | 2,010 | # Creates one rectangle or one shape with rounded corners.
#===Options
#
# * <tt>:x and :y</tt> - Coordinates to position.
# * <tt>:corners</tt> - Value for rounded corners. Use 0 to straight angle.
# * <tt>:width and :height</tt> - Size of frame
# * <tt>:content</tt> - facade to ShapeContent with same parameters.
# * ... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/frame.rb | Ruby | mit | 187 | master | 3,398 | # Creates one rectangle or one shape with rounded corners.
#===Options
#
# * <tt>:x and :y</tt> - Coordinates to position.
# * <tt>:corners</tt> - Value for rounded corners. Use 0 to straight angle.
# * <tt>:width and :height</tt> - Size of frame
# * <tt>:content</tt> - facade to ShapeContent with same parameters.
# * ... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/vertical_line.rb | Ruby | mit | 187 | master | 1,162 | require "rghost/ps_object"
require "rghost/units"
require "rghost/load"
# Creates vertical line starting from current row.
class RGhost::VerticalLine < RGhost::PsObject
DEFAULT_OPTIONS = {
start_in: :limit_left, size: :area_y,
border: RGhost::Border::DEFAULT_OPTIONS
}
# Draws a vertical line where :start... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/callback_facade.rb | Ruby | mit | 187 | master | 3,565 | module RGhost::Grid
# The callbacks for the grid are defined here. Let's see them in action.
# ===Grid::CallbackFacade examples
# grid=Grid::Matrix.new :column_padding => 1
# grid.column :title => "Id", :width => 1
# grid.column :title => "Name", :width => 3, :align => :center
# grid.column :title => "D... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/static_callback.rb | Ruby | mit | 187 | master | 319 | require "rghost/ps_object"
require "rghost/function"
class RGhost::Grid::StaticCallback < RGhost::Function
ACCEPT = [:before_table_create, :after_table_create]
def initialize(name, &block)
raise NameError.new("#{name} no accept in #{self.class}") unless ACCEPT.include? name
super(name, &block)
end
end |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/grid.rb | Ruby | mit | 187 | master | 382 | module RGhost::Grid
require "rghost/grid/header"
require "rghost/grid/callback_facade"
require "rghost/grid/style/style"
require "rghost/grid/base_grid"
require "rghost/grid/rails_grid"
require "rghost/grid/matrix"
require "rghost/grid/csv_grid"
require "rghost/grid/dynamic_callback"
require "rghost/g... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/field_format.rb | Ruby | mit | 187 | master | 719 | $LOAD_PATH << File.dirname(__FILE__) + File::SEPARATOR + "../"
require "rghost/ps_object"
require "rghost/ruby_to_ps"
module RGhost::Grid
module FieldFormat
extend RGhost::RubyToPs
# Format Time/Date to %d/%m/%Y
def self.eurodate(value)
string(value.strftime("%d/%m/%Y"))
end
# Cut all bl... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/rails_grid.rb | Ruby | mit | 187 | master | 2,405 | require "rghost/ps_object"
#
# Grid::Rails mapps grid columns to ActiveRecord attributes. For
# example, let's take a Calls class to represent telephone calls.
#
# ===Example
# rails_grid=Grid::Rails.new(:align => :center, :width => 3)
#
# Mapping, first the attribute name then the already known optionsName
# rails_... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/dynamic_callback.rb | Ruby | mit | 187 | master | 400 | require "rghost/callback"
# Dynamic Callbacks
class RGhost::Grid::DynamicCallback < RGhost::Callback
ACCEPT = [:before_row, :after_row, :even_row,
:odd_row, :before_column, :after_column, :even_column, :odd_column]
def initialize(name, options = {}, &block)
raise NameError.new("#{name} no accept in #{self.... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/header.rb | Ruby | mit | 187 | master | 2,774 | $LOAD_PATH << File.dirname(__FILE__) + File::SEPARATOR + "../"
require "rghost/ps_object"
require "rghost/ruby_to_ps"
require "rghost/variable"
require "rghost/units"
require "rghost/function"
require "rghost/callback"
# Grid's Header.
# You can get a header instance using:
# grid=Grid::Rails.new
# grid.header
#
# Y... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/base_grid.rb | Ruby | mit | 187 | master | 6,452 | # RGhost::Grid::Base is a helper object to create a tabular
# representations, composed of rows, columns and a title. This
# prototype used to join the common attributes for data grids. To use
# a Grid you must first setup the columns, then load the data.
#
# Example:
# grid=Grid::Matrix.new
# grid.column :title => ... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/csv_grid.rb | Ruby | mit | 187 | master | 1,391 | # Grid::CSV allows you to import data from a csv file.
# ===Example
#
# grid=Grid::CSV.new :width => 2
# grid.column :title => "User", :align => :right
# grid.column :title => "Password", :format => lambda{|v| (v.to_s == "x") ? "Yes" : "No"}
# grid.column :title => "UID", :width => 1
# grid.column :title => "GID"... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/style/bottom_lines.rb | Ruby | mit | 187 | master | 382 | class RGhost::Grid::Style::BottomLines
def set_style(grid)
size = grid.header.size
grid.before_row do |b|
b.horizontal_line(:bottom, size: grid.width)
end
grid.header.before_create do |h|
h.line_width(0)
h.horizontal_line(:bottom, size: grid.width)
h.use_tag :bold
end
... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/style/old_forms.rb | Ruby | mit | 187 | master | 398 | class RGhost::Grid::Style::OldForms
def set_style(grid)
size = grid.header.size
grid.odd_row do |o|
o.background_row(size: size)
end
grid.header.before_create do |h|
h.line_width(0)
h.background_row(size: size, color: RGhost::ShapeContent::DEFAULT_OPTIONS[:color])
h.use_tag :b... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | lib/rghost/grid/style/border_lines.rb | Ruby | mit | 187 | master | 738 | class RGhost::Grid::Style::BorderLines
def set_style(grid)
grid.before_row do |b|
b.horizontal_line(:top, size: grid.width)
b.horizontal_line(:bottom, size: grid.width)
end
grid.before_column only: 0 do |b|
b.vertical_line_row
end
grid.after_column do |c|
c.vertical_line_... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/color_spec.rb | Ruby | mit | 187 | master | 5,902 | # frozen_string_literal: true
RSpec.describe RGhost::Color do
context "color factory" do
# String HTML color converter
# Color.create '#FFAA33'
# As Symbol will be find in RGhost::Constants::Colors::RGB
# Color.create :red
# As Array with 3 elements
# Color.create [0.5, 0.3, 0.5]
# Hash w... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/cursor_spec.rb | Ruby | mit | 187 | master | 1,684 | # frozen_string_literal: true
RSpec.describe RGhost::Cursor do
it "should go to a row" do
expect(RGhost::Cursor.goto_row(10).ps.strip).to eq("10 goto_row default_point")
expect(RGhost::Cursor.goto_row(20).ps.strip).to eq("20 goto_row default_point")
end
it "should jump rows" do
expect(RGhost::Curs... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/border_spec.rb | Ruby | mit | 187 | master | 1,587 | # frozen_string_literal: true
RSpec.describe RGhost::Border do
it "should to use default options when user doesn't use any" do
ps_string = RGhost::Border.new.ps.to_s
options = RGhost::Border::DEFAULT_OPTIONS
color = RGhost::Color.create(options[:color])
line_width = RGhost::LineWidth.new(options[:wi... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/convert_spec.rb | Ruby | mit | 187 | master | 1,553 | require "fileutils"
RSpec.describe RGhost::Convert do
before :all do
@a_pdf = RGhost.asser_path("doc.pdf")
@multi_page = RGhost.asser_path("doc2.pdf")
end
it "should convert a pdf to jpeg" do
resp = RGhost::Convert.new(@a_pdf).to :jpeg, filename: RGhost.using_temp_dir("a_file.jpg")
expect(File.e... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/spec_helper.rb | Ruby | mit | 187 | master | 1,105 | # frozen_string_literal: true
require "pry-byebug"
require "tmpdir"
require File.expand_path("../lib/rghost", __dir__)
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/callback_spec.rb | Ruby | mit | 187 | master | 1,505 | # frozen_string_literal: true
RSpec.describe RGhost::Callback do
it "should create a callback block" do
b = RGhost::Callback.new "a_test_callback" do
end
expect(b.ps.strip).to eq(%(/a_test_callback 3 dict def a_test_callback begin \n/proc { } bind def \n/except [] def \n/only [] def \nend))
end
... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/matrix_spec.rb | Ruby | mit | 187 | master | 481 | require "./lib/rghost"
# describe RGhost::Grid::Base do
# it "should generate for ruby 1.9" do
vals = [
["col1", "col2"], ["anothercol", "anothercol2"]
]
doc = RGhost::Document.new
doc.matrix_grid(align: :center, width: 8) do |grid|
grid.style :bottom_lines
grid.column title: "First column", width: 3.5
grid.... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/dash_spec.rb | Ruby | mit | 187 | master | 662 | # frozen_string_literal: true
RSpec.describe RGhost::Dash do
it "should set dash values" do
options = RGhost::Dash::DEFAULT_OPTIONS
dash = RGhost::Dash.new
expect(dash.ps.strip).to eq("[#{options[:style].join(" ")}] #{options[:offset]} setdash")
end
it "should set create a dash with options" do
... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/rghost_config_spec.rb | Ruby | mit | 187 | master | 730 | # frozen_string_literal: true
RSpec.describe RGhost::Config do
subject(:config) { described_class }
let(:fake_which) { class_double("RGhost::Which", call: :ok) }
let(:options) { {} }
it "sets GS[:path] when executable is found" do
allow(fake_which).to receive(:call).with("gs") { "/some/path/to/gs" }
... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/circle_spec.rb | Ruby | mit | 187 | master | 2,115 | # frozen_string_literal: true
RSpec.describe RGhost::Circle do
it "should use default options when user doesn't use any" do
ps_string = RGhost::Circle.new.ps.to_s
options = RGhost::Circle::DEFAULT_OPTIONS
border = RGhost::Border.new
shape = RGhost::ShapeContent.new
x, y = RGhost::Units.parse(opt... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/document_spec.rb | Ruby | mit | 187 | master | 2,609 | # frozen_string_literal: true
RSpec.describe RGhost::Document do
it "should to use default options when user doesn't use any" do
doc = RGhost::Document.new
r = doc.render :pdf, filename: RGhost.using_temp_dir("testdoc.pdf")
expect(File.exist?(r.output)).to be true
end
it "should create a new documen... |
github | shairontoledo/rghost | https://github.com/shairontoledo/rghost | spec/rghost/which_spec.rb | Ruby | mit | 187 | master | 1,869 | # frozen_string_literal: true
RSpec.describe RGhost::Which do
subject(:which) { described_class.new(env: fake_env) }
let(:fake_env) { {"PATH" => path.join(File::PATH_SEPARATOR)} }
let(:path) { ["/tmp/fake_dir"] }
let(:project_root_dir) { Pathname(__dir__).join("../..") }
let(:fixture_path) { project_root_dir... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | Rakefile | Ruby | apache-2.0 | 187 | the-future | 249 | # Add your own tasks in files placed in lib/tasks ending in .rake, for example
# lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | Gemfile | Ruby | apache-2.0 | 187 | the-future | 5,414 | # frozen_string_literal: true
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
source 'https://rubygems.org'
# Core Stuff
gem 'i18n', '1.8.11'
gem 'puma'
gem 'rails', '6.1.7.6'
# Database Stuff
gem 'activerecord-import' # Run bulk imports quicker
gem 'attr_encrypted' # encrypt linked_profile tokens
ge... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | Guardfile | Ruby | apache-2.0 | 187 | the-future | 1,363 | require 'active_support/inflector'
guard :rspec, cmd: 'bin/rspec -f doc' do
# spec/*_helper.rb -> all specs
watch(%r{spec/.*_helper.rb}) { 'spec' }
# spec/support/*.rb -> all specs
watch(%r{spec/support/.*.rb}) { 'spec' }
# app/**/(application|base)_*.rb--> all re... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/mutators/account_mutator.rb | Ruby | apache-2.0 | 187 | the-future | 1,139 | class AccountMutator
# Create an account for a user
#
# @param [String] email The email address of the user to register
# @param [String] password The password to set for the user
# @param [String] name The name of the user
# @param [Hash,nil] external_identity An external account to associate with the user... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/serializers/category_recommendation_serializer.rb | Ruby | apache-2.0 | 187 | the-future | 2,033 | class CategoryRecommendationSerializer < JSONAPI::ResourceSerializer
def self_link(source, relationship)
return {} if source.class.name == 'CategoryRecommendationResource'
link_builder.relationships_self_link(source, relationship)
end
def related_link(source, relationship)
return {} if source.class.n... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/library_stat_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 976 | # Hooks onto LibraryEntry and manages updating the stats
class LibraryStatCallbacks < Callbacks
# @param klass [Class] the class to hook the callbacks for
def self.hook(klass)
klass.after_update(self)
klass.after_create(self)
klass.after_destroy(self)
end
def after_update
perform_for :update
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/embed_link_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 972 | # frozen_string_literal: true
class EmbedLinkCallbacks < Callbacks
# @param klass [Class] the class to hook the callbacks for
def self.hook(klass)
klass.after_validation(self)
end
# Update the embed if the URL is present or if the content changed
def after_validation
record.public_send("#{to}=", emb... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/library_event_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 240 | class LibraryEventCallbacks < Callbacks
# @param klass [Class] the class to hook the callbacks for
def self.hook(klass)
klass.after_update(self)
end
def after_update
LibraryEventService.new(record).create_events!
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/media_total_length_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 855 | # Hooks onto Episode and maintains the total_length sum on the Media
class MediaTotalLengthCallbacks < Callbacks
# @param klass [Class] the class to hook the callbacks for
def self.hook(klass)
klass.after_create(self)
klass.after_destroy(self)
klass.after_update(self)
end
def after_create
media... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/instanced_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 1,433 | # Encapsulates a set of life-cycle callbacks on a class
class InstancedCallbacks
attr_reader :record
# @param record [ActiveRecord::Base] the record on which the callbacks are being run
# @param options [Hash] a hash of options to this
def initialize(record, options = {})
@record = record
@_options = o... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 1,007 | # Encapsulates a set of life-cycle callbacks on a class
class Callbacks
attr_reader :record
# @param record [ActiveRecord::Base] the record on which the callbacks are being run
def initialize(record)
@record = record
end
# @return [Hash] the options set for this callback group
def options
{}
end... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/library_time_spent_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 525 | # Hooks onto LibraryEntry and manages updating the time_spent column as the progress/reconsume_count
# change over time.
class LibraryTimeSpentCallbacks < Callbacks
# @param klass [Class] the class to hook the callbacks for
def self.hook(klass)
klass.before_save(self)
end
def before_save
return unless ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/callbacks/wordfilter_callbacks.rb | Ruby | apache-2.0 | 187 | the-future | 1,232 | # frozen_string_literal: true
class WordfilterCallbacks < InstancedCallbacks
# @param klass [Class] the class to hook the callbacks for
# @param location [Symbol] the wordfilter location name
# @param content_field [Symbol] the field on this class which stores the content
def self.hook(klass, location, content... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/cover_image_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 1,674 | require 'image_processing/vips'
require 'image_processing/mini_magick'
class CoverImageUploader < Shrine
include ImageUploader
include PublicUploader
DERIVATIVES = {
magick: {
tiny: ->(magick) {
magick.resize_to_fill(840, 200).convert(:gif).call
},
tiny_webp: ->(magick) {
m... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/portrait_image_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 775 | require 'image_processing/vips'
class PortraitImageUploader < Shrine
include ImageUploader
include PublicUploader
DERIVATIVES = {
tiny: ->(vips) {
vips.resize_to_fill(100, 120).convert(:jpeg).saver(quality: 90, strip: true).call
},
small: ->(vips) {
vips.resize_to_fill(200, 240).convert(... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/unit_thumbnail_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 774 | require 'image_processing/vips'
class UnitThumbnailUploader < Shrine
include ImageUploader
include PublicUploader
DERIVATIVES = {
tiny: ->(vips) {
vips.resize_to_fill(160, 90).convert(:jpeg).saver(quality: 95, strip: true).call
},
small: ->(vips) {
vips.resize_to_fill(320, 180).convert(:... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/poster_image_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 773 | require 'image_processing/vips'
class PosterImageUploader < Shrine
include ImageUploader
include PublicUploader
DERIVATIVES = {
tiny: ->(vips) {
vips.resize_to_fill(110, 156).convert(:jpeg).saver(quality: 90, strip: true).call
},
small: ->(vips) {
vips.resize_to_fill(284, 402).convert(:j... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/avatar_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 1,973 | require 'image_processing/vips'
require 'image_processing/mini_magick'
class AvatarUploader < Shrine
include ImageUploader
include PublicUploader
DERIVATIVES = {
magick: {
tiny: ->(magick) {
magick.resize_to_fill(40, 40).convert(:gif).call
},
tiny_webp: ->(magick) {
magick.... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/concerns/image_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 286 | module ImageUploader
extend ActiveSupport::Concern
include BlurhashUploader
included do
plugin :validation_helpers
plugin :store_dimensions
self::Attacher.validate do
validate_mime_type %w[image/jpg image/jpeg image/png image/webp image/gif]
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/uploaders/concerns/blurhash_uploader.rb | Ruby | apache-2.0 | 187 | the-future | 684 | # frozen_string_literal: true
module BlurhashUploader
extend ActiveSupport::Concern
included do
plugin :blurhash,
resize: 50,
components: ->(width, height) {
ratio = width.to_f / height
# Achieves the following
# - "component area" <= 15
# - maintains aspect ratio
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_report_policy.rb | Ruby | apache-2.0 | 187 | the-future | 308 | class GroupReportPolicy < ApplicationPolicy
include GroupPermissionsHelpers
def create?
member.present?
end
def update?
is_owner? || has_group_permission?(:content)
end
def destroy?
false
end
class Scope < Scope
def resolve
scope.visible_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_ticket_policy.rb | Ruby | apache-2.0 | 187 | the-future | 300 | class GroupTicketPolicy < ApplicationPolicy
include GroupPermissionsHelpers
def create?
member?
end
def update?
is_owner? || has_group_permission?(:tickets)
end
def destroy?
false
end
class Scope < Scope
def resolve
scope.visible_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/report_policy.rb | Ruby | apache-2.0 | 187 | the-future | 493 | class ReportPolicy < ApplicationPolicy
administrated_by :community_mod
def create?
return false unless user
return false if user.has_role?(:banned)
is_owner?
end
def update?
return false unless user
return false if user.has_role?(:banned)
is_owner? || can_administrate?
end
def des... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/user_ip_address_policy.rb | Ruby | apache-2.0 | 187 | the-future | 313 | # frozen_string_literal: true
class UserIPAddressPolicy < ApplicationPolicy
administrated_by :community_mod
def update?
false
end
alias_method :create?, :update?
alias_method :destroy?, :update?
class Scope < Scope
def resolve
can_administrate? ? scope : scope.none
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/ama_policy.rb | Ruby | apache-2.0 | 187 | the-future | 254 | class AMAPolicy < ApplicationPolicy
administrated_by :community_mod
def update?
record.author == user || can_administrate?
end
def destroy?
record.author == user || can_administrate?
end
def create?
can_administrate?
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/anime_policy.rb | Ruby | apache-2.0 | 187 | the-future | 599 | # frozen_string_literal: true
class AnimePolicy < ApplicationPolicy
administrated_by :database_mod
class Scope < Scope
def resolve
if user && !user.sfw_filter?
scope
else
scope.sfw
end
end
end
class AlgoliaScope < AlgoliaScope
def resolve
if user && !user.s... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/video_policy.rb | Ruby | apache-2.0 | 187 | the-future | 226 | class VideoPolicy < ApplicationPolicy
class Scope < Scope
def resolve
region = Thread.current[:region]
return scope unless region.present? && region != 'XX'
scope.available_in(region)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_neighbor_policy.rb | Ruby | apache-2.0 | 187 | the-future | 245 | class GroupNeighborPolicy < ApplicationPolicy
include GroupPermissionsHelpers
def create?
has_group_permission? :community
end
alias_method :destroy?, :create?
def update?
false
end
def group
record.source
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/community_recommendation_request_policy.rb | Ruby | apache-2.0 | 187 | the-future | 259 | class CommunityRecommendationRequestPolicy < ApplicationPolicy
administrated_by :community_mod
def update?
is_owner? || can_administrate?
end
def create?
record.user == user
end
def destroy?
is_owner? || can_administrate?
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/post_like_policy.rb | Ruby | apache-2.0 | 187 | the-future | 603 | class PostLikePolicy < ApplicationPolicy
include GroupPermissionsHelpers
def update?
false
end
def create?
return false unless user
return false if user.unregistered?
return false if user&.blocked?(record.post.user)
return false if user&.has_role?(:banned)
if group
return false i... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/one_signal_player_policy.rb | Ruby | apache-2.0 | 187 | the-future | 244 | class OneSignalPlayerPolicy < ApplicationPolicy
alias_method :create?, :is_owner?
alias_method :update?, :is_owner?
alias_method :destroy?, :is_owner?
class Scope < Scope
def resolve
scope.where(user: user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/post_policy.rb | Ruby | apache-2.0 | 187 | the-future | 1,569 | # frozen_string_literal: true
class PostPolicy < ApplicationPolicy
administrated_by :community_mod
include GroupPermissionsHelpers
def update?
return false unless user
return false if user.has_role?(:banned)
return true if can_administrate?
return false if record.locked?
return true if group... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_ban_policy.rb | Ruby | apache-2.0 | 187 | the-future | 353 | class GroupBanPolicy < ApplicationPolicy
include GroupPermissionsHelpers
def create?
has_group_permission?(:members)
end
alias_method :destroy?, :create?
def update?
false
end
def editable_attributes(all)
all - %i[notes_formatted]
end
class Scope < Scope
def resolve
scope.vis... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/user_policy.rb | Ruby | apache-2.0 | 187 | the-future | 1,452 | # frozen_string_literal: true
class UserPolicy < ApplicationPolicy
administrated_by :community_mod
def create?
true
end
def update?
user == record || can_administrate?
end
alias_method :destroy?, :update?
def editable_attributes(all)
if has_scope?(:email_password_reset, accept_all: false)
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_action_log_policy.rb | Ruby | apache-2.0 | 187 | the-future | 233 | class GroupActionLogPolicy < ApplicationPolicy
def update?
false
end
alias_method :create?, :update?
alias_method :destroy?, :update?
class Scope < Scope
def resolve
scope.visible_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_permission_policy.rb | Ruby | apache-2.0 | 187 | the-future | 257 | class GroupPermissionPolicy < ApplicationPolicy
include GroupPermissionsHelpers
def update?
false
end
def create?
has_group_permission? :leaders
end
alias_method :destroy?, :create?
def group
record.group_member.group
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/linked_account_policy.rb | Ruby | apache-2.0 | 187 | the-future | 242 | class LinkedAccountPolicy < ApplicationPolicy
alias_method :create?, :is_owner?
alias_method :update?, :is_owner?
alias_method :destroy?, :is_owner?
class Scope < Scope
def resolve
scope.where(user: user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/review_like_policy.rb | Ruby | apache-2.0 | 187 | the-future | 378 | class ReviewLikePolicy < ApplicationPolicy
def update?
false
end
def create?
return false unless user
return false if user.unregistered?
return false if user.blocked?(record.review.user)
record.user == user
end
alias_method :destroy?, :create?
class Scope < Scope
def resolve
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/library_entry_policy.rb | Ruby | apache-2.0 | 187 | the-future | 241 | class LibraryEntryPolicy < ApplicationPolicy
alias_method :update?, :is_owner?
alias_method :create?, :is_owner?
alias_method :destroy?, :is_owner?
class Scope < Scope
def resolve
scope.visible_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/application_policy.rb | Ruby | apache-2.0 | 187 | the-future | 5,985 | # frozen_string_literal: true
# Base class for all policies. Provides a bunch of useful shortcuts for checks
# that we use frequently, such as checking for admin-ness, lewd goggles, or
# token scopes.
#
# Because of overlap between Pundit, Doorkeeper, and Rolify terminology,
# there are three different meanings of "s... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/leader_chat_message_policy.rb | Ruby | apache-2.0 | 187 | the-future | 286 | class LeaderChatMessagePolicy < ApplicationPolicy
include GroupPermissionsHelpers
def update?
leader? && is_owner?
end
alias_method :create?, :update?
alias_method :destroy?, :update?
class Scope < Scope
def resolve
scope.visible_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/media_reaction_vote_policy.rb | Ruby | apache-2.0 | 187 | the-future | 228 | class MediaReactionVotePolicy < ApplicationPolicy
def create?
return false unless user
return false if user.has_role?(:banned)
is_owner?
end
alias_method :destroy?, :create?
def update?
false
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/list_import_policy.rb | Ruby | apache-2.0 | 187 | the-future | 287 | class ListImportPolicy < ApplicationPolicy
administrated_by :admin
def create?
record.user == user || can_administrate?
end
def update?
false
end
alias_method :destroy, :update?
class Scope < Scope
def resolve
scope.where(user: user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_invite_policy.rb | Ruby | apache-2.0 | 187 | the-future | 334 | class GroupInvitePolicy < ApplicationPolicy
include GroupPermissionsHelpers
def create?
has_group_permission? :members
end
def update?
has_group_permission? :members
end
def destroy?
has_group_permission? :members
end
class Scope < Scope
def resolve
scope.visible_for(user)
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/manga_policy.rb | Ruby | apache-2.0 | 187 | the-future | 437 | # frozen_string_literal: true
class MangaPolicy < ApplicationPolicy
administrated_by :database_mod
class Scope < Scope
def resolve
if user && !user.sfw_filter?
scope
else
scope.sfw
end
end
end
class TypesensualScope < TypesensualScope
def resolve
if user &&... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_policy.rb | Ruby | apache-2.0 | 187 | the-future | 1,658 | # frozen_string_literal: true
class GroupPolicy < ApplicationPolicy
administrated_by :community_mod
include GroupPermissionsHelpers
def create?
user ? true : false
end
def update?
has_group_permission? :community
end
def destroy?
has_group_permission? :owner
end
def editable_attribute... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/review_policy.rb | Ruby | apache-2.0 | 187 | the-future | 392 | class ReviewPolicy < ApplicationPolicy
administrated_by :community_mod
def create?
user.registered? && is_owner?
end
def update?
is_owner? || can_administrate?
end
alias_method :destroy?, :update?
def editable_attributes(all)
all - [:content_formatted]
end
class Scope < Scope
def ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/comment_policy.rb | Ruby | apache-2.0 | 187 | the-future | 1,723 | # frozen_string_literal: true
class CommentPolicy < ApplicationPolicy
administrated_by :community_mod
include GroupPermissionsHelpers
def update?
return false unless user
return false if user.has_role?(:banned)
return true if can_administrate?
# admins are allowed to update comments on locked po... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_member_policy.rb | Ruby | apache-2.0 | 187 | the-future | 855 | class GroupMemberPolicy < ApplicationPolicy
include GroupPermissionsHelpers
def update?
required_permission = record.pleb? ? :members : :leaders
is_owner? || has_group_permission?(required_permission)
end
alias_method :destroy?, :update?
def create?
return false unless is_owner?
return false... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/wiki_submission_policy.rb | Ruby | apache-2.0 | 187 | the-future | 212 | class WikiSubmissionPolicy < ApplicationPolicy
administrated_by :community_mod
alias_method :create_draft?, :is_owner?
alias_method :update_draft?, :is_owner?
alias_method :submit_draft?, :is_owner?
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/media_reaction_policy.rb | Ruby | apache-2.0 | 187 | the-future | 1,114 | # frozen_string_literal: true
class MediaReactionPolicy < ApplicationPolicy
administrated_by :community_mod
def create?
return false unless user
return false if user.has_role?(:banned)
record.user == user
end
alias_method :update?, :create?
def like?
return false unless user
return fals... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/comment_like_policy.rb | Ruby | apache-2.0 | 187 | the-future | 675 | class CommentLikePolicy < ApplicationPolicy
include GroupPermissionsHelpers
def update?
false
end
def create?
return false unless user
return false if user.unregistered?
return false if user.blocked?(record.comment.user)
return false if user.blocked?(record.comment.post.user)
return fa... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_member_note_policy.rb | Ruby | apache-2.0 | 187 | the-future | 378 | class GroupMemberNotePolicy < ApplicationPolicy
include GroupPermissionsHelpers
def update?
is_owner? && has_group_permission?(:members)
end
alias_method :destroy?, :create?
alias_method :create?, :update?
def editable_attributes(all)
all - %i[content_formatted]
end
class Scope < Scope
de... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/follow_policy.rb | Ruby | apache-2.0 | 187 | the-future | 598 | # frozen_string_literal: true
class FollowPolicy < ApplicationPolicy
def create?
is_owner? && !user.has_role?(:banned)
end
alias_method :update?, :create?
alias_method :destroy?, :create?
def visible_attributes(all)
is_owner? ? all : all - %i[hidden]
end
alias_method :editable_attributes, :visib... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/group_ticket_message_policy.rb | Ruby | apache-2.0 | 187 | the-future | 265 | class GroupTicketMessagePolicy < ApplicationPolicy
def create?
policy_for(record.ticket).update?
end
alias_method :update?, :create?
alias_method :destroy?, :create?
class Scope < Scope
def resolve
scope.visible_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/block_policy.rb | Ruby | apache-2.0 | 187 | the-future | 353 | class BlockPolicy < ApplicationPolicy
administrated_by :community_mod
def create?
return false if record == Block
record.user == user
end
def destroy?
record.try(:user) == user || can_administrate?
end
class Scope < Scope
def resolve
return scope if can_administrate?
scope.whe... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/repost_policy.rb | Ruby | apache-2.0 | 187 | the-future | 200 | class RepostPolicy < ApplicationPolicy
administrated_by :community_mod
def create?
is_owner?
end
def update?
false
end
def destroy?
is_owner? || can_administrate?
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/upload_policy.rb | Ruby | apache-2.0 | 187 | the-future | 307 | class UploadPolicy < ApplicationPolicy
administrated_by :community_mod
def show?
true
end
def create?
user ? true : false
end
def update?
is_owner?
end
def destroy?
is_owner? || can_administrate?
end
class Scope < Scope
def resolve
scope
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/policies/concerns/group_permissions_helpers.rb | Ruby | apache-2.0 | 187 | the-future | 1,308 | module GroupPermissionsHelpers
extend ActiveSupport::Concern
private
# The Group of the current record. Returns nil if the record isn't a record
def group
return if record.respond_to?(:where)
record.group
end
# The GroupMember object for the current user
#
# @return [GroupMember, nil] the me... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/controllers/group_invites_controller.rb | Ruby | apache-2.0 | 187 | the-future | 870 | class GroupInvitesController < ApplicationController
include CustomControllerHelpers
before_action :authenticate!, only: %i[accept decline]
before_action :acceptable?, only: %i[accept decline revoke]
def accept
invite.accept!
render json: {}, status: 201
end
def decline
invite.decline!
re... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/controllers/follows_controller.rb | Ruby | apache-2.0 | 187 | the-future | 522 | class FollowsController < ApplicationController
def import_from_facebook
facebook = Authorization::Assertion::Facebook.new(params[:assertion])
render json: serialize_follows(facebook.auto_follows)
end
def serialize_follows(follows)
serializer.serialize_to_hash(wrap_in_resources(follows))
end
def... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/controllers/admin_controller.rb | Ruby | apache-2.0 | 187 | the-future | 678 | class AdminController < ActionController::Base
before_action :redirect_to_session
include Pundit::Authorization
protect_from_forgery with: :null_session
rescue_from ActionController::InvalidAuthenticityToken do
render plain: 'Token expired/invalid', status: 403
end
rescue_from Pundit::NotAuthorizedErr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.