repo_name stringlengths 6 97 | path stringlengths 3 341 | text stringlengths 8 1.02M |
|---|---|---|
HTW-Webtech/ai-webtech-admin-app | app/models/aris_service.rb | <gh_stars>0
class ArisService
def self.publish(app)
return true if Rails.env.development?
bookkeeper.add(app.permalink, app_opts(app))
write_semaphore(app)
end
def self.write_semaphore(app)
IO.binwrite(app.semaphore_file_path, "Time: #{Time.now.to_s}")
end
def self.app_opts(app)
opts = {... |
HTW-Webtech/ai-webtech-admin-app | db/migrate/20160622152300_migrate_review_date_markers.rb | class MigrateReviewDateMarkers < ActiveRecord::Migration
def up
ReviewDate.find_each do |review_date|
review_date.user_id or next
user = User.find(review_date.user_id)
user.update reviewed_at: review_date.reviewed_at
end
end
def down
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/controllers/concerns/app_fetching.rb | module AppFetching
def fetch_app(permalink_or_id)
App.for_permalink_or_id(permalink_or_id).tap do |app|
if app.user != current_user && !current_user.admin?
redirect_to current_user
end
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/models/user.rb | <filename>app/models/user.rb<gh_stars>0
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :timeoutable and :omniauthable
# :rememberable manages generating and clearing tokens from a cookie
devise :database_authenticatable, :registerable,
:recoverable,... |
HTW-Webtech/ai-webtech-admin-app | spec/features/attending_codereviews_spec.rb | # Admin creates N codereviews. N is determined by
#
# 17.30-19 Uhr
# 19.15-20.45 Uhr => 60 / 10 = 6 * 4 = 24
#
# A user needs to select a pratice group
# Once she has selected the group the admin can create a review date
# The admin creates a group for the review
# The admin adds the users (at least 3) to the review gr... |
HTW-Webtech/ai-webtech-admin-app | db/migrate/20160511172322_add_review_user_to_review_date.rb | <gh_stars>0
class AddReviewUserToReviewDate < ActiveRecord::Migration
def change
add_column :review_dates, :user_id, :integer
end
end
|
HTW-Webtech/ai-webtech-admin-app | db/migrate/20150918081948_add_admin_user.rb | <filename>db/migrate/20150918081948_add_admin_user.rb
class AddAdminUser < ActiveRecord::Migration
def up
User.create!({
email: cc(:admin).email,
name: cc(:admin).name,
ssh_key: cc(:admin).pub_ssh_key,
password: ENV.fetch('<PASSWO... |
HTW-Webtech/ai-webtech-admin-app | spec/factories/user_factory.rb | <reponame>HTW-Webtech/ai-webtech-admin-app
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "<EMAIL>" }
name '<NAME>'
ssh_key 'AASAD…'
password '<PASSWORD>'
end
end
|
HTW-Webtech/ai-webtech-admin-app | config/routes.rb | <gh_stars>0
Rails.application.routes.draw do
if Object.const_defined?(:RailsAdmin)
mount RailsAdmin::Engine => '/admin/rails_admin', as: 'rails_admin'
end
devise_for :users, controllers: {
sessions: 'users/sessions'
}
root 'home#index'
resources :users, only: [:show, :edit, :update] do
resou... |
HTW-Webtech/ai-webtech-admin-app | db/migrate/20160403170714_add_timestamps_to_users_table.rb | <filename>db/migrate/20160403170714_add_timestamps_to_users_table.rb<gh_stars>0
class AddTimestampsToUsersTable < ActiveRecord::Migration
def up
add_timestamps :users
end
def down
remove_timestamps :users
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/exercise_points_controller.rb | <gh_stars>0
module Admin
class ExercisePointsController < BaseController
def create
App.find_each do |app|
ExercisePointMaster.new(current_course).evaluate_app!(app)
end
redirect_to root_path, notice: "Updated exercise points for #{App.count} apps."
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | db/migrate/20151123164107_ensure_unique_app_names.rb | class EnsureUniqueAppNames < ActiveRecord::Migration
def change
add_index :apps, :name, unique: true
end
end
|
HTW-Webtech/ai-webtech-admin-app | db/migrate/20151126061226_be_more_liberal_about_null_values.rb | <filename>db/migrate/20151126061226_be_more_liberal_about_null_values.rb<gh_stars>0
class BeMoreLiberalAboutNullValues < ActiveRecord::Migration
def up
change_column :apps, :ssh_key, :string, null: true
change_column :apps, :pg_host, :string, null: true
change_column :apps, :pg_database, :string, null: tr... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/statistics_controller.rb | module Admin
class StatisticsController < BaseController
def show
@google_chart_data = Statistics::OverallPoints.new(current_course.students).google_chart_data
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/fixtures_controller.rb | <reponame>HTW-Webtech/ai-webtech-admin-app
module Admin
class FixturesController < BaseController
def create
id = User.count+1
user = User.create({
email: "#{<EMAIL>",
name: "#{id}-alice-or-bob",
ssh_key: "ssh-rsa …",
password: '<PASSWORD>',
password_confirmatio... |
HTW-Webtech/ai-webtech-admin-app | app/models/jenkins_service.rb | <filename>app/models/jenkins_service.rb
class JenkinsService
def self.publish(app_or_apps)
apps = Array(app_or_apps)
jobs = load_jobs
jobs = add_or_update(jobs, apps)
store_jobs(jobs)
end
def self.load_jobs
jobs_yml = read_jenkins_jobs_yaml
jobs = if jobs_yml.present?
YAML.load(jobs... |
HTW-Webtech/ai-webtech-admin-app | app/models/review_points.rb | class ReviewPoints
attr_accessor :course, :points
def initialize(course = Courses.current)
@course = course || Courses.current
@points = @course.review_points
end
def for_app(app)
for_exercise_id(app.exercise_id)
end
def for_exercise_id(exercise_id)
points.fetch(exercise_id, (0..0))
end... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/users_controller.rb | <reponame>HTW-Webtech/ai-webtech-admin-app
module Admin
class UsersController < BaseController
def block
user = User.find(params[:user_id])
if user.block!
redirect_to user, notice: 'User has been successfully blocked.'
else
redirect_to user, alert: 'Could not block user!'
e... |
HTW-Webtech/ai-webtech-admin-app | app/models/review_group.rb | <reponame>HTW-Webtech/ai-webtech-admin-app
class ReviewGroup < ActiveRecord::Base
has_many :users
has_many :review_dates
def self.without_date_for_exercise(exercise_id)
groups_with_date_ids = includes(:review_dates).where(review_dates: { exercise_id: exercise_id }).pluck(:id)
where.not(id: groups_with_da... |
HTW-Webtech/ai-webtech-admin-app | app/models/courses.rb | <gh_stars>0
require 'courses/base'
module Courses
module_function
def current
Summer2016
end
def self.all
Base.descendants
end
def self.find(name)
course = all.detect { |klass| klass.name.demodulize.downcase == name.downcase }
course || current
end
end
|
HTW-Webtech/ai-webtech-admin-app | spec/models/user/appraisal_spec.rb | <gh_stars>0
require 'rails_helper'
describe User::Appraisal do
let(:course) { double('Course', total_points: 100) }
let(:user) { double('User') }
subject { described_class.new(user, course: course) }
describe '#percentage' do
it 'for a user with 0 total_points it equals 0' do
allow(user).to receiv... |
HTW-Webtech/ai-webtech-admin-app | spec/features/registration_and_login_spec.rb | <gh_stars>0
require 'rails_helper'
feature 'User registration and authentication' do
scenario 'allows user to register an account' do
visit '/'
click_on 'Registrieren'
fill_in 'Email', with: '<EMAIL>'
fill_in 'user_password', with: '<PASSWORD>'
fill_in 'user_pa... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/app_exercise_points_controller.rb | module Admin
class AppExercisePointsController < BaseController
def update
app = App.for_permalink_or_id(params[:app_id])
app.update exercise_points: params[:points]
redirect_to :back, notice: "App #{app.display_name} hat nun #{app.exercise_points} Punkte"
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/models/email/code_review_confirmation_mailer.rb | module Email
class CodeReviewConfirmationMailer
attr_accessor :review_date
def initialize(review_date)
@review_date = review_date
end
def subject
"#{review_date.review_points} Punkt(e) für Code Review zur Aufgabe #{review_date.exercise_id}"
end
def body
"Zu deinem CodeRevi... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/feedbacks_controller.rb | <filename>app/controllers/feedbacks_controller.rb
class FeedbacksController < ApplicationController
before_action :find_app_and_feedback, only: [:show, :edit, :update]
def show
end
def edit
end
def new
@feedback = Feedback.new(feedback_params)
end
def create
@feedback = Feedback.new(feedback... |
HTW-Webtech/ai-webtech-admin-app | app/models/group.rb | class Group < ActiveRecord::Base
has_and_belongs_to_many :users, join_table: :groups_users
def self.current_course
where(name: Courses.current.display_name).first_or_create!
end
def display_name
"#{name} (#{users.count})"
end
end
|
HTW-Webtech/ai-webtech-admin-app | db/migrate/20151111192749_drop_failures_count_on_results.rb | <filename>db/migrate/20151111192749_drop_failures_count_on_results.rb
class DropFailuresCountOnResults < ActiveRecord::Migration
def up
remove_column :exercise_results, :failures_count
end
def down
add_column :exercise_results, :failures_count, :integer, null: false, default: -1
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/helpers/application_helper.rb | <gh_stars>0
module ApplicationHelper
def announcements
@announcements ||= []
end
def current_url(query:)
uri = URI.parse(request.url)
uri.query = query if query
uri.to_s
end
def active_link_to_li(*args)
additional = { wrap_tag: :li, active: :exclusive }
opts = if args.last.is_a?(Hash... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/app_reviews_controller.rb | module Admin
class AppReviewsController < BaseController
include AppFetching
def show
@app = fetch_app(params[:app_id])
end
def confirm
@app = fetch_app(params[:app_id])
@app.update!(reviewed_at: Time.current, review_points: params[:points])
redirect_to admin_app_review_path(... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/apiv1/pings_controller.rb | require 'json'
module Apiv1
class PingsController < BaseController
def ping
render json: JSON.generate({ result: 'pong' })
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/exceptions_controller.rb | module Admin
class ExceptionsController < BaseController
def create
raise StandardError, "Bla"
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/models/exercise_point_master.rb | class ExercisePointMaster
attr_accessor :course, :exercises, :messages
def initialize(course = Courses.current)
@course = course || Courses.current
@exercises = @course.exercises
@messages = []
end
def evaluate!(exercise_result)
if reached_deadline? exercise_result
messages << "Deadli... |
HTW-Webtech/ai-webtech-admin-app | app/controllers/apps_controller.rb | <filename>app/controllers/apps_controller.rb<gh_stars>0
class AppsController < ::BaseController
include AppFetching
before_action :limit_apps_per_user, only: [:new, :create]
def index
redirect_to current_user
end
def show
@announcements = Announcement.all
@app = fetch_app(params[:id])
end
d... |
HTW-Webtech/ai-webtech-admin-app | app/models/review_date.rb | class ReviewDate < ActiveRecord::Base
has_many :users, through: :review_group
belongs_to :user
belongs_to :review_group
validates_inclusion_of :exercise_id, in: Courses.current.exercise_names.keys
def self.upcoming_for_user(user)
where('begins_at > ?', [Time.now]).where(review_group_id: user.review_grou... |
HTW-Webtech/ai-webtech-admin-app | db/migrate/20160420111116_add_winter_group2015.rb | class AddWinterGroup2015 < ActiveRecord::Migration
def up
ws2015 = Group.create(name: 'WS2015')
User.where('created_at > ?', [8.weeks.ago]).each do |user|
ws2015.users << user
end
end
def down
Group.where(name: 'WS2015').delete_all
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/controllers/admin/exercises_controller.rb | module Admin
class ExercisesController < BaseController
def show
@exercise_ids = ExercisePointMaster.new(current_course).exercise_ids
@apps = current_course.students.includes(:apps).map(&:apps).flatten
end
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/models/statistics/overall_points.rb | # Overall points
# students.each do |student|
# student["user"] => User(email: …),
# student["total_points"] => 6
# end
module Statistics
class OverallPoints
attr_accessor :students
def initialize(students = User.without_admin)
@students = students
end
def google_chart_data
formatted... |
HTW-Webtech/ai-webtech-admin-app | app/models/feedback.rb | <filename>app/models/feedback.rb
require 'kramdown'
class Feedback < ActiveRecord::Base
belongs_to :app
belongs_to :user
def body_as_html
Kramdown::Document.new(body).to_html.html_safe
end
end
|
HTW-Webtech/ai-webtech-admin-app | app/models/courses/summer2016.rb | <filename>app/models/courses/summer2016.rb
module Courses
class Summer2016 < Base
def self.exercises
{
1 => [ 0, Date.new(2016, 12, 12) ],
2 => [ 2, Date.new(2016, 5, 6) ],
3 => [ 2, Date.new(2016, 5, 11) ],
4 => [ 2, Date.new(2016, 5, 16) ],
5 => [ 4, Date.new(2016,... |
csxiaodiao/hecms | app/models/hecms/tag_relation.rb | <filename>app/models/hecms/tag_relation.rb
# frozen_string_literal: true
module Hecms
class TagRelation < ApplicationRecord
belongs_to :record, polymorphic: true, touch: true
belongs_to :tag, counter_cache: :articles_count
end
end
|
csxiaodiao/hecms | app/controllers/hecms/categories_controller.rb | # frozen_string_literal: true
require_dependency 'hecms/base_controller'
module Hecms
class CategoriesController < BaseController
before_action :find_category, only: %i[destroy edit update]
def index
@categories = Category.roots.page(params[:page])
end
def new
@category = Category.new
... |
csxiaodiao/hecms | app/jobs/hecms/application_job.rb | <reponame>csxiaodiao/hecms
module Hecms
class ApplicationJob < ActiveJob::Base
end
end
|
csxiaodiao/hecms | app/models/hecms/article.rb | <filename>app/models/hecms/article.rb
# frozen_string_literal: true
module Hecms
class Article < ApplicationRecord
include SoftDelete
extend Enumerize
has_one_attached :image
acts_as_tenant(:user)
has_many :category_relations, as: :record, inverse_of: :record
has_many :categories, through:... |
csxiaodiao/hecms | app/controllers/hecms/base_controller.rb | # frozen_string_literal: true
require_dependency 'hecms/application_controller'
module Hecms
class BaseController < ApplicationController
layout 'layouts/hecms/application'
before_action :authenticate_user!
set_current_tenant_through_filter
before_action :set_tenant
def set_tenant
set_cu... |
csxiaodiao/hecms | db/migrate/seeds.rb | # frozen_string_literal: true
# Hecms::Category.create(name: 'cate name', slug: 'cate_name')
puts 123
|
csxiaodiao/hecms | app/models/hecms/picture.rb | # frozen_string_literal: true
module Hecms
class Picture < ApplicationRecord
has_one_attached :image
end
end
|
csxiaodiao/hecms | app/models/concerns/keyword_like_helper.rb | <gh_stars>0
# frozen_string_literal: true
module KeywordLikeHelper
# example
# Add `scope_keyword_like users: [:username, :email], user_auth_tokens: [:value]' to model/user.rb
# explain: users is current table name, :username, :email is current table field.
# users_auth_tokens tables need joined to current ta... |
csxiaodiao/hecms | app/controllers/hecms/auth/sessions_controller.rb | <gh_stars>0
# frozen_string_literal: true
module Hecms
class Auth::SessionsController < Devise::SessionsController
layout 'layouts/hecms/simple'
private
def after_sign_in_path_for(_resource)
root_path
end
def after_sign_out_path_for(_scope)
new_user_session_path
end
end
end
|
csxiaodiao/hecms | app/views/hecms/articles/search.json.jbuilder | # frozen_string_literal: true
json.articles do
json.array! @articles do |x|
json.id x.id
json.title x.title
json.category_names x.category_names
json.tag_names x.tag_names
json.content strip_tags(x.content_html.to_s)
end
end
json.meta do
json.total_pages @articles.total_pages
json.total_cou... |
csxiaodiao/hecms | test/dummy/config/routes.rb | Rails.application.routes.draw do
mount Hecms::Engine => "/hecms"
end
|
csxiaodiao/hecms | db/migrate/20210420072903_create_hecms_category_relations.rb | # frozen_string_literal: true
class CreateHecmsCategoryRelations < ActiveRecord::Migration[6.1]
def change
create_table :hecms_category_relations do |t|
t.references :category, null: false, comment: '栏目'
t.references :record, null: false, polymorphic: true, index: false
t.timestamps
end
... |
csxiaodiao/hecms | app/controllers/hecms/uploads_controller.rb | <reponame>csxiaodiao/hecms<filename>app/controllers/hecms/uploads_controller.rb
# frozen_string_literal: true
require_dependency 'hecms/base_controller'
module Hecms
class UploadsController < BaseController
def create
picture = Picture.new(image: params[:upload])
if picture.save
render(json:... |
csxiaodiao/hecms | lib/tasks/hecms_tasks.rake | <reponame>csxiaodiao/hecms
# desc "Explaining what the task does"
# task :hecms do
# # Task goes here
# end
|
csxiaodiao/hecms | hecms.gemspec | <reponame>csxiaodiao/hecms
# frozen_string_literal: true
require_relative 'lib/hecms/version'
Gem::Specification.new do |spec|
spec.name = 'hecms'
spec.version = Hecms::VERSION
spec.authors = ['csxiaodiao']
spec.email = ['<EMAIL>']
spec.homepage = 'http://xiaodiao.me'
spec.summary ... |
csxiaodiao/hecms | app/helpers/hecms/tags_helper.rb | module Hecms
module TagsHelper
end
end
|
csxiaodiao/hecms | app/models/concerns/i18n_display_helper.rb | <filename>app/models/concerns/i18n_display_helper.rb<gh_stars>0
# frozen_string_literal: true
module I18nDisplayHelper
extend ActiveSupport::Concern
def display_created_at
I18n.l(created_at, format: :long) if created_at.present?
end
def display_md_created_at
I18n.l(created_at, format: :md) if create... |
csxiaodiao/hecms | app/controllers/hecms/application_controller.rb | <filename>app/controllers/hecms/application_controller.rb
# frozen_string_literal: true
module Hecms
class ApplicationController < ActionController::Base
end
end
|
csxiaodiao/hecms | app/models/concerns/article_achortext.rb | <filename>app/models/concerns/article_achortext.rb<gh_stars>0
# frozen_string_literal: true
module ArticleAchortext
extend ActiveSupport::Concern
included do
has_many :anchor_text_relations
has_many :anchor_texts, through: :anchor_text_relations
accepts_nested_attributes_for :anchor_text_relations, rej... |
csxiaodiao/hecms | lib/hecms.rb | <gh_stars>0
# frozen_string_literal: true
# require 'active_storage/engine'
require 'hecms/version'
require 'hecms/engine'
require 'awesome_nested_set'
require 'ransack'
require 'friendly_id'
require 'kaminari'
require 'devise'
require 'jquery-rails'
require 'sass-rails'
require 'fomantic-ui-sass'
require 'acts_as_ten... |
csxiaodiao/hecms | db/migrate/20210413015526_create_hecms_categories.rb | <reponame>csxiaodiao/hecms<filename>db/migrate/20210413015526_create_hecms_categories.rb<gh_stars>0
# frozen_string_literal: true
class CreateHecmsCategories < ActiveRecord::Migration[6.1]
def change
create_table :hecms_categories do |t|
t.string :name, null: false, comment: '栏目名'
t.string :seo_title... |
csxiaodiao/hecms | app/models/concerns/ads_wordsable.rb | <reponame>csxiaodiao/hecms
# frozen_string_literal: true
module AdsWordsable
extend ActiveSupport::Concern
class_methods do
def ads_words
YAML.load(File.read(Rails.root.join("lib/ads_words/ads_words.yml")))["ads_words"]
end
end
end
|
csxiaodiao/hecms | test/dummy/db/schema.rb | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
csxiaodiao/hecms | db/migrate/20210420072005_create_hecms_tag_relations.rb | # frozen_string_literal: true
class CreateHecmsTagRelations < ActiveRecord::Migration[6.1]
def change
create_table :hecms_tag_relations do |t|
t.references :tag, null: false, comment: '标签'
t.references :record, null: false, polymorphic: true, index: false
t.timestamps
end
add_index :hec... |
csxiaodiao/hecms | config/routes.rb | <reponame>csxiaodiao/hecms
# frozen_string_literal: true
Hecms::Engine.routes.draw do
devise_for :users, path: 'auth/users', class_name: 'Hecms::User', module: :devise, controllers: {
sessions: 'hecms/auth/sessions',
passwords: '<PASSWORD>'
}
root to: 'categories#index'
resources :categories
resour... |
csxiaodiao/hecms | app/helpers/hecms/application_helper.rb | # frozen_string_literal: true
module Hecms
module ApplicationHelper
def controller_path_action_name
"#{controller.controller_path.gsub('/', '__')}__#{controller.action_name}"
end
def html_body_classes
"#{controller_path_action_name} #{@body_classes&.join(' ')}"
end
def site_logo_url... |
csxiaodiao/hecms | db/migrate/20210420072101_create_hecms_pictures.rb | <gh_stars>0
# frozen_string_literal: true
class CreateHecmsPictures < ActiveRecord::Migration[6.1]
def change
create_table :hecms_pictures, &:timestamps
end
end
|
csxiaodiao/hecms | lib/hecms/engine.rb | <reponame>csxiaodiao/hecms<filename>lib/hecms/engine.rb
# frozen_string_literal: true
module Hecms
class Engine < ::Rails::Engine
isolate_namespace Hecms
config.before_initialize do
config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
# config.i18n.available_locales << 'zh-CN'
... |
csxiaodiao/hecms | db/migrate/20210420070722_create_hecms_articles.rb | # frozen_string_literal: true
class CreateHecmsArticles < ActiveRecord::Migration[6.1]
def change
create_table :hecms_articles do |t|
t.references :user_id, null: false, comment: 'user'
t.string(:title, null: false, comment: '标题')
t.string(:seo_title, comment: 'SEO标题')
t.string(:keywords,... |
csxiaodiao/hecms | app/models/hecms/tag.rb | # frozen_string_literal: true
module Hecms
class Tag < ApplicationRecord
extend FriendlyId
has_many :tag_relations
has_many :articles, through: :tag_relations, source: :record, source_type: 'Article'
accepts_nested_attributes_for :tag_relations, reject_if: :all_blank, allow_destroy: true
frien... |
csxiaodiao/hecms | app/controllers/hecms/tags_controller.rb | <filename>app/controllers/hecms/tags_controller.rb<gh_stars>0
# frozen_string_literal: true
require_dependency 'hecms/base_controller'
module Hecms
class TagsController < BaseController
before_action :find_tag, only: %i[destroy edit update]
def index
@tags = Tag.keyword_like(params[:keyword]).order(i... |
csxiaodiao/hecms | app/helpers/hecms/categories_helper.rb | module Hecms
module CategoriesHelper
end
end
|
csxiaodiao/hecms | app/helpers/hecms/articles_helper.rb | <gh_stars>0
module Hecms
module ArticlesHelper
end
end
|
csxiaodiao/hecms | app/models/hecms/category_relation.rb | <reponame>csxiaodiao/hecms<filename>app/models/hecms/category_relation.rb
# frozen_string_literal: true
module Hecms
class CategoryRelation < ApplicationRecord
belongs_to :record, polymorphic: true, touch: true
belongs_to :category
end
end
|
csxiaodiao/hecms | app/models/hecms/category.rb | # frozen_string_literal: true
module Hecms
class Category < ApplicationRecord
acts_as_nested_set
include SoftDelete
extend FriendlyId
has_many :category_relations, dependent: :destroy
has_many :articles, through: :category_relations, source: :record, source_type: 'Article'
has_many :tags, th... |
csxiaodiao/hecms | app/controllers/hecms/articles_controller.rb | <reponame>csxiaodiao/hecms
# frozen_string_literal: true
require_dependency 'hecms/base_controller'
module Hecms
class ArticlesController < BaseController
before_action :find_article, only: %i[edit update show destroy]
def index
@articles = Article.keyword_like(params[:keyword]).includes(:tags, :cate... |
csxiaodiao/hecms | db/migrate/20210420071829_create_hecms_tags.rb | <reponame>csxiaodiao/hecms
# frozen_string_literal: true
class CreateHecmsTags < ActiveRecord::Migration[6.1]
def change
create_table :hecms_tags do |t|
t.string :name, comment: '标签名'
t.string :seo_title, comment: 'SEO标题'
t.string :keywords, comment: '关键词'
t.text :description, comment: '简... |
HuaxinTang/grpc | src/objective-c/BoringSSL-GRPC.podspec |
# This file has been automatically generated from a template file.
# Please make modifications to
# `templates/src/objective-c/BoringSSL-GRPC.podspec.template` instead. This
# file can be regenerated from the template by running
# `tools/buildgen/generate_projects.sh`.
# BoringSSL CocoaPods podspec
# Copyright 2015... |
jmhnilbog/dcc_tabbed_sheet | lib/dcc_tabbed_sheet/helpers.rb | <gh_stars>0
module DccTabbedSheet
module Helpers
def version
# Sheet version, not DCC_Tabbed_Sheet version
DccTabbedSheet::SHEET_VERSION
end
end
end
|
jmhnilbog/dcc_tabbed_sheet | lib/dcc_tabbed_sheet.rb | require "dcc_tabbed_sheet/compiler"
require "dcc_tabbed_sheet/version"
module DccTabbedSheet
class Error < StandardError; end
end
|
mitre-cyber-academy/2012-web-e | turtles/cookbooks/challenge/aux/myapp.rb | require 'sinatra'
require 'tempfile'
class String
def ^( other )
b1 = self.unpack("U*")
b2 = other.unpack("U*")
longest = [b1.length,b2.length].max
b1 = [0]*(longest-b1.length) + b1
b2 = [0]*(longest-b2.length) + b2
b1.zip(b2).map{ |a,b| a^b }.pack("U*")
end
end
class Application < Sinatr... |
mitre-cyber-academy/2012-web-e | turtles/cookbooks/challenge/recipes/default.rb | <filename>turtles/cookbooks/challenge/recipes/default.rb
bash "initd" do
user "root"
code <<-EOH
# move initd
mv /home/ubuntu/chef-solo/cookbooks/challenge/aux/init_d_script /etc/init.d/challenge
chmod 755 /etc/init.d/challenge
# register it with boot sequence
update-rc.d challenge defaults 98 02
... |
Tryweirder/Docker-Provider | source/plugins/ruby/filter_telegraf2mdm.rb | # Copyright (c) Microsoft Corporation. All rights reserved.
# frozen_string_literal: true
module Fluent
require "logger"
require "yajl/json_gem"
require_relative "oms_common"
require_relative "kubelet_utils"
require_relative "MdmMetricsGenerator"
require_relative "constants"
class Telegraf2MdmFilter <... |
Tryweirder/Docker-Provider | source/plugins/ruby/filter_cadvisor2mdm.rb | <reponame>Tryweirder/Docker-Provider<filename>source/plugins/ruby/filter_cadvisor2mdm.rb
# Copyright (c) Microsoft Corporation. All rights reserved.
# frozen_string_literal: true
module Fluent
require "logger"
require "yajl/json_gem"
require_relative "oms_common"
require_relative "CustomMetricsUtils"
requi... |
remi/rackbox | examples/.shared_specs/blackbox/helpful_matchers_spec.rb | <gh_stars>1-10
require File.dirname(__FILE__) + '/../spec_helper'
describe 'Helpful Matchers' do
it 'response.should be_success' do
request('/').should be_success
end
it 'response.should be_redirect' do
request('/redirect?to=http://www.google.com').should be_redirect
end
it 'response.should redire... |
remi/rackbox | lib/rackbox/rack/content_length_fix.rb | <reponame>remi/rackbox
# An evil fix
#
# The actual fix
# has been pulled upstream into Rack
# but hasn't made it into the Rack gem yet, so we need this fix until the new gem is released
#
class Rack::MockRequest
class << self
alias env_for_without_content_length_fix env_for
def env_for_with_content_length_... |
remi/rackbox | lib/rackbox/app.rb | class RackBox
# represents a rack appliction
#
# gives us some helpers on a rack app
# like the ability to use the #request
# method on it easily
#
class App
attr_accessor :rack_app, :mock_request
def initialize rack_app
@rack_app = rack_app
reset_request
end
def reset_req... |
remi/rackbox | examples/sinatra/config.ru | <filename>examples/sinatra/config.ru
require 'rubygems'
require 'sinatra'
set :run, false
set :environment, :production
require 'sinatra_app'
use Rack::Session::Cookie
run Sinatra::Application
|
remi/rackbox | examples/.shared_specs/blackbox/sticky_sessions_spec.rb | <reponame>remi/rackbox
require File.dirname(__FILE__) + '/../spec_helper'
describe 'Sticky Sessions' do
it 'should work with sessions' do
request('/print-session').body.should == ''
request('/print-session', :params => { :session_variable => 'chunky bacon!' }).body.should == 'chunky bacon!'
request('/pr... |
remi/rackbox | examples/rails/app/controllers/welcome_controller.rb | class WelcomeController < ApplicationController
def index
render :text => "You said #{ params[:say] || 'nothing' }"
end
def print_method
render :text => request.method
end
def print_session
session[:session_variable] = params[:session_variable] if params[:session_variable]
render :text => s... |
remi/rackbox | lib/rackbox/rack/extensions_for_rspec.rb | <reponame>remi/rackbox
# some more Rack extensions to help when testing
class Rack::MockResponse
# TODO checkout Rack::Response::Helpers which implements many of these!
# these methods help with RSpec specs so we can ask things like:
#
# request('/').should be_successful
# request('/').should be_redirec... |
remi/rackbox | spec/basic_auth_spec.rb | require File.dirname(__FILE__) + '/spec_helper'
describe RackBox, 'basic auth' do
it 'should be able to add HTTP BASIC AUTH to a request' do
app = lambda {|env| [200, {}, "i require http basic auth"] }
app = Rack::Auth::Basic.new(app){|u,p| u == 'remi' && p == 'testing' }
RackBox.request( app, '/' ).s... |
remi/rackbox | spec/spec_helper.rb | require File.dirname(__FILE__) + '/../lib/rackbox'
|
remi/rackbox | spec/custom_request_header_specs.rb | require File.dirname(__FILE__) + '/spec_helper'
describe RackBox, 'custom request headers' do
before do
@rack_app = lambda {|env| [ 200, { }, env.inspect ] }
end
it "#request should take any non-special options and assume they're request headers" do
RackBox.request(@rack_app, '/').body.should_not inclu... |
remi/rackbox | examples/sinatra/sinatra_app.rb | <reponame>remi/rackbox
get '/' do
"You said #{ params[:say] || 'nothing' }"
end
post '/' do
"You said #{ params[:say] || 'nothing' }"
end
# can i roll these into 1?
get '/print-method' do
request.request_method.downcase
end
put '/print-method' do
request.request_method.downcase
end
post '/print-method' do
re... |
remi/rackbox | lib/rackbox/test.rb | # this should get you up and running for using RackBox with test/unit
|
remi/rackbox | lib/rackbox.rb | $:.unshift File.dirname(__FILE__)
require 'rubygems'
require 'rack'
require 'rails-rack-adapter' # update this so it's only loaded when/if needed
require 'rackbox/rack/content_length_fix'
require 'rackbox/rack/sticky_sessions'
require 'rackbox/rack/extensions_for_rspec'
require 'rackbox/rackbox'
require 'rackbox/app... |
remi/rackbox | lib/rackbox/matchers.rb | class RackBox
# Custom RSpec matchers
module Matchers
def self.included base
# this should really just be matcher(:foo){ ... }
# but there's a bit of other meta logic to deal with here
Object.send :remove_const, :RedirectTo if defined? RedirectTo
undef redirect_to if defined? re... |
remi/rackbox | lib/rackbox/rack/sticky_sessions.rb | <reponame>remi/rackbox<gh_stars>1-10
#
# little extension to Rack::MockRequest to track cookies
#
class Rack::MockRequest
# cookies is a hash of persistent cookies (by domain)
# that let you test cookies for your app
#
# cookies = {
# 'example.org' => {
# 'cookie-name' => 'cookie-value',
# ... |
remi/rackbox | lib/rackbox/spec.rb | <reponame>remi/rackbox<filename>lib/rackbox/spec.rb
# this should get you up and running for using RackBox with RSpec
require File.dirname(__FILE__) + '/../rackbox'
spec_configuration = nil
spec_configuration = Spec::Example if defined? Spec::Example
spec_configuration = Spec::Runner if defined? Spec::Runner
spec_con... |
remi/rackbox | examples/rack/config.ru | use Rack::Session::Cookie
run lambda { |env|
request = Rack::Request.new env
response = Rack::Response.new
params = request.params
session = env['rack.session']
response.body = case request.path_info
when '/'
"You said #{ params['say'] || 'nothing' }"
when '/print-method'
request.request_me... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.