repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/controllers/chaskiq/manage/templates_controller_spec.rb | spec/controllers/chaskiq/manage/templates_controller_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Manage::TemplatesController, type: :controller do
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/controllers/chaskiq/manage/metrics_controller_spec.rb | spec/controllers/chaskiq/manage/metrics_controller_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Manage::MetricsController, type: :controller do
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/attachment_spec.rb | spec/models/chaskiq/attachment_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Attachment, type: :model do
it{ should belong_to :campaign }
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/campaign_spec.rb | spec/models/chaskiq/campaign_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Campaign, type: :model do
include ActiveJob::TestHelper
it{ should have_many :attachments }
it{ should have_many :metrics }
#it{ should have_one :campaign_template }
#it{ should have_one(:template).through(:campaign_template) }
it{ should belong_to :list }
it{ should have_many(:subscribers).through(:list) }
it{ should belong_to :template }
let(:html_content){
"<p>hola {{name}} {{email}}</p> <a href='http://google.com'>google</a>"
}
let(:template){ FactoryGirl.create(:chaskiq_template, body: html_content ) }
let(:list){ FactoryGirl.create(:chaskiq_list) }
let(:subscriber){
#list.create_subscriber(subscriber)
list.create_subscriber FactoryGirl.attributes_for(:chaskiq_subscriber)
}
let(:subscription){
subscriber.subscriptions.first
}
let(:campaign){ FactoryGirl.create(:chaskiq_campaign, template: template) }
let(:premailer_template){"<p>{{name}} {{last_name}} {{email}} {{campaign_url}} {{campaign_subscribe}} {{campaign_unsubscribe}}this is the template</p>"}
describe "creation" do
it "will create a pending campaign by default" do
@c = FactoryGirl.create(:chaskiq_campaign)
expect(@c).to_not be_sent
allow_any_instance_of(Chaskiq::Campaign).to receive(:premailer).and_return(premailer_template)
end
end
context "template step" do
it "will copy template" do
campaign.template = template
campaign.save
expect(campaign.html_content).to be == template.body
end
it "will copy template on creation" do
expect(campaign.html_content).to be == template.body
end
end
context "send newsletter" do
before do
10.times do
list.create_subscriber FactoryGirl.attributes_for(:chaskiq_subscriber)
end
@c = FactoryGirl.create(:chaskiq_campaign, template: template, list: list)
allow(@c).to receive(:premailer).and_return("<p>hi</p>")
allow_any_instance_of(Chaskiq::Campaign).to receive(:apply_premailer).and_return(true)
end
it "will prepare mail to" do
expect(@c.prepare_mail_to(subscription)).to be_an_instance_of(ActionMailer::MessageDelivery)
end
it "will prepare mail to can send inline" do
reset_email
@c.prepare_mail_to(subscription).deliver_now
expect(ActionMailer::Base.deliveries.size).to be 1
end
it "will send newsletter jobs for each subscriber" do
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 0
Chaskiq::MailSenderJob.perform_now(@c)
#expect(@c.metrics.deliveries.size).to be == 10
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 10
end
it "will send newsletter jobs for each subscriber" do
@c.subscriptions.first.unsubscribe!
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 0
Chaskiq::MailSenderJob.perform_now(@c)
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 9
end
it "will send newsletter for dispatch" do
@c.subscriptions.first.unsubscribe!
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 0
@c.send_newsletter
expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq 1
end
end
context "template compilation" do
it "will render subscriber attributes" do
campaign.template = template
campaign.save
expect(campaign.html_content).to be == template.body
allow_any_instance_of(Chaskiq::Campaign).to receive(:premailer).and_return("{{name}}")
expect(campaign.mustache_template_for(subscriber)).to include(subscriber.name)
end
it "will render subscriber and compile links with host ?r=link" do
campaign.template = template
campaign.save
allow_any_instance_of(Chaskiq::Campaign).to receive(:premailer).and_return("<a href='http://google.com'>google</a>")
expect(campaign.compiled_template_for(subscriber)).to include("?r=http://google.com")
expect(campaign.compiled_template_for(subscriber)).to include(campaign.host)
end
end
context "clone campaign" do
it "should clone record" do
c = campaign.clone_newsletter
c.save
expect(c.id).to_not be == campaign.id
expect(c.template).to be == campaign.template
expect(c.list).to be == campaign.list
expect(c.subscribers).to be == campaign.subscribers
end
it "rename" do
c = campaign.clone_newsletter
c.save
expect(c.name).to_not be == campaign.name
expect(c.name).to include("copy")
end
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/subscription_spec.rb | spec/models/chaskiq/subscription_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Subscription, type: :model do
it{ should belong_to :list }
it{ should belong_to :subscriber }
it{ should have_many :campaigns }
let(:template){ FactoryGirl.create(:chaskiq_template) }
let(:list){ FactoryGirl.create(:chaskiq_list) }
let(:subscriber){
list.create_subscriber FactoryGirl.attributes_for(:chaskiq_subscriber)
}
let(:campaign){ FactoryGirl.create(:chaskiq_campaign, template: template, list: list) }
it "will set passive state" do
subscriber
expect(campaign.subscriptions.passive.size).to be == 1
end
it "will notify susbscrition" do
sub = list.subscriptions.first
#expect(sub).to receive(:notify_subscription).once
list.subscribe(subscriber)
expect(list.subscriptions.subscribed.map(&:subscriber)).to include subscriber
end
it "will notify un susbscrition" do
#expect(subscriber).to receive(:notify_unsubscription).once
list.unsubscribe(subscriber)
expect(list.subscriptions.unsubscribed.map(&:subscriber)).to include subscriber
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/subscriber_spec.rb | spec/models/chaskiq/subscriber_spec.rb | require 'rails_helper'
require 'urlcrypt'
module Chaskiq
RSpec.describe Subscriber, type: :model do
it{ should have_many :subscriptions }
it{ should have_many(:lists).through(:subscriptions) }
it{ should have_many :metrics }
it{ should have_many(:campaigns).through(:lists) }
describe "states" do
let(:subscriber){ FactoryGirl.create(:chaskiq_subscriber)}
it "will set passive state" do
#expect(subscriber).to be_passive
end
it "will notify susbscrition" do
#expect(subscriber).to receive(:notify_subscription).once
#subscriber.suscribe
#expect(subscriber).to be_subscribed
end
it "will notify un susbscrition" do
#expect(subscriber).to receive(:notify_unsubscription).once
#subscriber.unsuscribe
#expect(subscriber).to be_unsubscribed
end
it "encode decode email" do
expect(subscriber.email).to_not be == subscriber.encoded_id
expect(URLcrypt.encode(subscriber.email)).to be == subscriber.encoded_id
end
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/list_spec.rb | spec/models/chaskiq/list_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe List, type: :model do
it{ should have_many :subscribers }
it{ should have_many :campaigns }
describe "creation" do
let(:list){FactoryGirl.create(:chaskiq_list)}
it "will create a list" do
Chaskiq::Subscriber.delete_all
data = list.import_csv("spec/fixtures/csv_example.csv")
expect(list.subscribers.size).to be 3
end
it "will not save repeated data" do
Chaskiq::Subscriber.delete_all
list.import_csv("spec/fixtures/csv_example.csv")
list.import_csv("spec/fixtures/csv_example.csv")
expect(list.subscribers.size).to be 3
end
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/metric_spec.rb | spec/models/chaskiq/metric_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Metric, type: :model do
it{should belong_to :trackable}
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/setting_spec.rb | spec/models/chaskiq/setting_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Setting, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/models/chaskiq/template_spec.rb | spec/models/chaskiq/template_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Template, type: :model do
it{ should have_many(:campaigns) }
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/app/helpers/application_helper.rb | spec/dummy/app/helpers/application_helper.rb | module ApplicationHelper
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/app/controllers/application_controller.rb | spec/dummy/app/controllers/application_controller.rb | class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/db/schema.rb | spec/dummy/db/schema.rb | # encoding: UTF-8
# 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.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150418050262) do
create_table "chaskiq_attachments", force: :cascade do |t|
t.string "image", limit: 255
t.string "content_type", limit: 255
t.integer "size", limit: 4
t.string "name", limit: 255
t.integer "campaign_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "chaskiq_attachments", ["campaign_id"], name: "index_chaskiq_attachments_on_campaign_id", using: :btree
create_table "chaskiq_campaigns", force: :cascade do |t|
t.string "subject", limit: 255
t.string "from_name", limit: 255
t.string "from_email", limit: 255
t.string "reply_email", limit: 255
t.text "plain_content", limit: 65535
t.text "html_content", limit: 65535
t.text "premailer", limit: 65535
t.text "description", limit: 65535
t.string "logo", limit: 255
t.string "name", limit: 255
t.string "query_string", limit: 255
t.datetime "scheduled_at"
t.string "timezone", limit: 255
t.string "state", limit: 255
t.integer "recipients_count", limit: 4
t.boolean "sent", limit: 1
t.integer "opens_count", limit: 4
t.integer "clicks_count", limit: 4
t.integer "parent_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "list_id", limit: 4
t.integer "template_id", limit: 4
t.text "css", limit: 65535
end
add_index "chaskiq_campaigns", ["list_id"], name: "index_chaskiq_campaigns_on_list_id", using: :btree
add_index "chaskiq_campaigns", ["parent_id"], name: "index_chaskiq_campaigns_on_parent_id", using: :btree
add_index "chaskiq_campaigns", ["template_id"], name: "index_chaskiq_campaigns_on_template_id", using: :btree
create_table "chaskiq_lists", force: :cascade do |t|
t.string "name", limit: 255
t.string "state", limit: 255
t.integer "unsubscribe_count", limit: 4
t.integer "bounced", limit: 4
t.integer "active_count", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "chaskiq_metrics", force: :cascade do |t|
t.integer "trackable_id", limit: 4, null: false
t.string "trackable_type", limit: 255, null: false
t.integer "campaign_id", limit: 4
t.string "action", limit: 255
t.string "host", limit: 255
t.string "data", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "chaskiq_metrics", ["campaign_id"], name: "index_chaskiq_metrics_on_campaign_id", using: :btree
add_index "chaskiq_metrics", ["trackable_type", "trackable_id"], name: "index_chaskiq_metrics_on_trackable_type_and_trackable_id", using: :btree
create_table "chaskiq_settings", force: :cascade do |t|
t.text "config", limit: 65535
t.integer "campaign_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "chaskiq_settings", ["campaign_id"], name: "index_chaskiq_settings_on_campaign_id", using: :btree
create_table "chaskiq_subscribers", force: :cascade do |t|
t.string "name", limit: 255
t.string "email", limit: 255
t.string "state", limit: 255
t.string "last_name", limit: 255
t.integer "list_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "chaskiq_subscribers", ["list_id"], name: "index_chaskiq_subscribers_on_list_id", using: :btree
create_table "chaskiq_subscriptions", force: :cascade do |t|
t.string "state", limit: 255
t.integer "campaign_id", limit: 4
t.integer "subscriber_id", limit: 4
t.integer "list_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "chaskiq_subscriptions", ["campaign_id"], name: "index_chaskiq_subscriptions_on_campaign_id", using: :btree
add_index "chaskiq_subscriptions", ["list_id"], name: "index_chaskiq_subscriptions_on_list_id", using: :btree
add_index "chaskiq_subscriptions", ["subscriber_id"], name: "index_chaskiq_subscriptions_on_subscriber_id", using: :btree
create_table "chaskiq_templates", force: :cascade do |t|
t.string "name", limit: 255
t.text "body", limit: 65535
t.text "html_content", limit: 65535
t.string "screenshot", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "css", limit: 65535
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/application.rb | spec/dummy/config/application.rb | require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
require "chaskiq"
module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.active_job.queue_adapter = :sidekiq
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/environment.rb | spec/dummy/config/environment.rb | # Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/routes.rb | spec/dummy/config/routes.rb | Rails.application.routes.draw do
mount Chaskiq::Engine => '/'
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/boot.rb | spec/dummy/config/boot.rb | # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/rainbows.rb | spec/dummy/config/rainbows.rb | worker_processes 3
timeout 30
preload_app true
Rainbows! do
use :EventMachine
end
before_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
end | ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/filter_parameter_logging.rb | spec/dummy/config/initializers/filter_parameter_logging.rb | # Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/session_store.rb | spec/dummy/config/initializers/session_store.rb | # Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_dummy_session'
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/wrap_parameters.rb | spec/dummy/config/initializers/wrap_parameters.rb | # Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/chaskiq.rb | spec/dummy/config/initializers/chaskiq.rb | require "chaskiq"
Chaskiq::Config.setup do |config|
#config.authentication_method = :authenticate_user!
config.ses_access_key = ENV['FOG_ACCESS_KEY_ID']
config.ses_access_secret_key = ENV['FOG_SECRET_ACCESS_KEY']
config.s3_bucket = ENV['FOG_BUCKET']
config.chaskiq_secret_key = "chaskiq123"
end | ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/inflections.rb | spec/dummy/config/initializers/inflections.rb | # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/cookies_serializer.rb | spec/dummy/config/initializers/cookies_serializer.rb | # Be sure to restart your server when you modify this file.
Rails.application.config.action_dispatch.cookies_serializer = :json
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/assets.rb | spec/dummy/config/initializers/assets.rb | # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js )
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/backtrace_silencers.rb | spec/dummy/config/initializers/backtrace_silencers.rb | # Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/initializers/mime_types.rb | spec/dummy/config/initializers/mime_types.rb | # Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/environments/test.rb | spec/dummy/config/environments/test.rb | 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 "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static file server for tests with Cache-Control for performance.
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Randomize the order test cases are executed.
config.active_support.test_order = :random
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
Rails.application.routes.default_url_options = {host: 'http://localhost:3000'}
config.action_controller.default_url_options = {host: 'http://localhost:3000'}
config.action_mailer.default_url_options = {host: 'http://localhost:3000'}
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/environments/development.rb | spec/dummy/config/environments/development.rb | 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't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
config.allow_concurrency = true
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
Rails.application.routes.default_url_options = {host: 'http://localhost:3000'}
config.action_controller.default_url_options = {host: 'http://localhost:3000'}
config.action_mailer.default_url_options = {host: 'http://localhost:3000'}
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/dummy/config/environments/production.rb | spec/dummy/config/environments/production.rb | 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, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
# NGINX, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/lib/link_renamer_spec.rb | spec/lib/link_renamer_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe LinkRenamer, type: :model do
let(:html) { "<p><a href='http://google.com'></p>"}
let(:renamer){ Chaskiq::LinkRenamer }
it "will rename links" do
data = renamer.convert(html, "AAA")
expect(data).to include("AAA")
end
it "test_initialize_no_escape_attributes_option" do
html = "<html> <body>
<a id='google' href='http://google.com'>Google</a>
<a id='noescape' href='{{link_url}}'>Link</a>
</body> </html>"
[:nokogiri].each do |adapter|
pm = Premailer.new(html, :with_html_string => true, :adapter => adapter, :escape_url_attributes => false)
pm.to_inline_css
doc = pm.processed_doc
expect( doc.at('#google')['href']).to be == 'http://google.com'
expect(doc.at('#noescape')['href']).to be == '{{link_url}}'
end
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/lib/csv_importer_spec.rb | spec/lib/csv_importer_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe CsvImporter, type: :model do
let(:importer){ Chaskiq::CsvImporter.new }
it "will initialize" do
expect(importer).to be_an_instance_of Chaskiq::CsvImporter
end
it "will import data" do
data = importer.import("spec/fixtures/csv_example.csv")
expect(data.class).to be == Array
expect(data.size).to be 3
expect(data.first.size).to be 3
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/lib/config_spec.rb | spec/lib/config_spec.rb | require 'rails_helper'
module Chaskiq
RSpec.describe Config, type: :model do
let(:chaskiq_config){ Chaskiq::Config }
it "will setup" do
chaskiq_config.setup do |config|
config.mail_settings = {
:address => "someuser@gmail.com",
:user_name => "xxx", # Your SMTP user here.
:password => "xxx", # Your SMTP password here.
:authentication => :login,
:enable_starttls_auto => true
}
end
expect(chaskiq_config.mail_settings).to be_an_instance_of Hash
expect(Chaskiq::Config.mail_settings).to be_an_instance_of Hash
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/mailers/previews/chaskiq/campaign_mailer_preview.rb | spec/mailers/previews/chaskiq/campaign_mailer_preview.rb | module Chaskiq
# Preview all emails at http://localhost:3000/rails/mailers/campaign_mailer
class CampaignMailerPreview < ActionMailer::Preview
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/spec/mailers/chaskiq/campaign_mailer_spec.rb | spec/mailers/chaskiq/campaign_mailer_spec.rb | require "rails_helper"
module Chaskiq
RSpec.describe CampaignMailer, type: :mailer do
let(:template){ FactoryGirl.create(:chaskiq_template) }
let(:list){ FactoryGirl.create(:chaskiq_list) }
let(:subscriber){
list.create_subscriber FactoryGirl.attributes_for(:chaskiq_subscriber)
}
let(:campaign){ FactoryGirl.create(:chaskiq_campaign, template: template, list: list) }
let(:template_html){ "<p>{{name}}</p>"}
let(:premailer_template){"<p>
{{name}} {{last_name}} {{email}} {{campaign_url}}
{{campaign_subscribe}} {{campaign_unsubscribe}}
{{campaign_description}} {{track_image_url}}
this is the template</p>"}
before do
allow_any_instance_of(Chaskiq::Campaign).to receive(:premailer).and_return(premailer_template)
allow_any_instance_of(Chaskiq::Campaign).to receive(:html_content).and_return(template_html)
Chaskiq::CampaignMailer.newsletter(campaign, subscriber.subscriptions.first).deliver_now
end
it "pass subscriber attributes to template" do
at = campaign.attributes_for_mailer(subscriber)
expect(last_email.subject).to_not be_blank
expect(last_email.body).to include(subscriber.name)
expect(last_email.body).to include(subscriber.last_name)
expect(last_email.body).to include(subscriber.email)
expect(last_email.body).to include(at[:campaign_url])
expect(last_email.body).to include(at[:campaign_unsubscribe])
expect(last_email.body).to include(at[:campaign_subscribe])
expect(last_email.body).to include(at[:campaign_description])
expect(last_email.body).to include(at[:track_image_url])
end
it "should deliver with open.gif" do
expect(last_email.body).to include("open.gif")
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/chaskiq.rb | lib/chaskiq.rb | require 'chaskiq/engine'
require 'haml'
require 'simple_form'
require 'kaminari'
require 'font-awesome-rails'
require 'bootstrap-sass'
require 'chaskiq/engine'
require 'urlcrypt'
require 'cocoon'
require 'mustache'
require 'dotenv'
require 'carrierwave'
require 'coffee-rails'
require 'premailer'
require 'groupdate'
require 'chartkick'
require 'jquery-rails'
require 'deep_cloneable'
require 'aws/ses'
require 'ransack'
Dotenv.load
module Chaskiq
autoload :VERSION, 'chaskiq/version'
autoload :Config, 'chaskiq/config'
autoload :CsvImporter, 'chaskiq/csv_importer'
autoload :LinkRenamer, 'chaskiq/link_renamer'
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/generators/chaskiq/install_generator.rb | lib/generators/chaskiq/install_generator.rb | require 'securerandom'
module Chaskiq
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
desc "Creates Chaskiq initializer, routes and copy locale files to your application."
class_option :orm
def copy_initializer
#@underscored_user_name = "user".underscore
template '../templates/chaskiq.rb.erb', 'config/initializers/chaskiq.rb'
end
def setup_routes
route "mount Chaskiq::Engine => '/'"
end
#def self.source_root
# File.expand_path("../templates", __FILE__)
#end
def create_migrations
exec 'bundle exec rake chaskiq:install:migrations'
#Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
# name = File.basename(filepath)
# template "migrations/#{name}", "db/migrate/#{name}"
# sleep 1
#end
end
end
end
end | ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/chaskiq/version.rb | lib/chaskiq/version.rb | module Chaskiq
VERSION = "0.0.6"
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/chaskiq/csv_importer.rb | lib/chaskiq/csv_importer.rb | require "csv"
module Chaskiq
class CsvImporter
def import(file_path)
file = File.open(file_path)
CSV.parse(file.read)
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/chaskiq/link_renamer.rb | lib/chaskiq/link_renamer.rb | require "nokogiri"
module Chaskiq
class LinkRenamer
def self.convert(html, url_prefix="")
content = Nokogiri::HTML(html)
content.css("a").each do |link|
next if link.attr("class").present? && link.attr("class").include?("tpl-block")
val = link.attributes["href"].value
link.attributes["href"].value = self.rename_link(val, url_prefix)
end
#content.css("div").each do |node|
# if node.content !~ /\A\s*\Z/
# node.replace(content.create_element('p', node.inner_html.html_safe))
# end
#end
content.css('div.mojoMcContainerEmptyMessage').remove
#make sure nokogiri does not rips off my mustaches
content.to_html.gsub("%7B%7B", "{{").gsub("%7D%7D", "}}")
end
def self.rename_link(value, url_prefix)
"#{url_prefix}" + value
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/chaskiq/config.rb | lib/chaskiq/config.rb | module Chaskiq
class Config
mattr_accessor :mail_settings,
:authentication_method,
:ses_access_key,
:ses_access_secret_key,
:s3_bucket,
:chaskiq_secret_key
def self.setup
yield self
end
def self.configure!
begin
self.check_config_vars
self.config_urlcript
self.config_ses
self.config_fog
#we will rescue this in order to allow rails g chaskiq:install works
rescue Chaskiq::ConfigError => e
puts e
puts e.message
end
end
def self.config_urlcript
URLcrypt.key = chaskiq_secret_key
end
def self.config_ses
ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
:access_key_id => ses_access_key,
:secret_access_key => ses_access_secret_key
end
def self.config_fog
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ses_access_key,
:aws_secret_access_key => ses_access_secret_key ,
#:region => 'eu-west-1', # optional, defaults to 'us-east-1'
#:hosts => 's3.example.com', # optional, defaults to nil
#:endpoint => 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory = s3_bucket # required
#config.fog_public = false # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
end
def self.check_config_vars
raise ConfigError.new("chaskiq_secret_key") unless chaskiq_secret_key.present?
raise ConfigError.new("ses_access_key") unless ses_access_key.present?
raise ConfigError.new("ses_access_secret_key") unless ses_access_secret_key.present?
raise ConfigError.new("s3_bucket") unless s3_bucket.present?
end
end
class ConfigError < StandardError
attr_reader :object
def initialize(key)
@key = key
end
def message
"\033[31m #{@key} config key not found, add it in Chaskiq::Config.setup initializer \033[0m"
end
end
end | ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/lib/chaskiq/engine.rb | lib/chaskiq/engine.rb | module Chaskiq
class Engine < ::Rails::Engine
isolate_namespace Chaskiq
config.generators do |g|
g.test_framework :rspec
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
g.integration_tool :rspec
end
config.autoload_paths += Dir["#{config.root}/app/jobs"]
config.action_mailer.delivery_method = :ses
config.assets.precompile += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico)
config.assets.precompile += %w(chaskiq/manage/campaign_wizard.css chaskiq/iframe.js )
config.assets.precompile += %w(font-awesome.css)
initializer "chaskiq_setup", :after => :load_config_initializers, :group => :all do
Chaskiq::Config.configure!
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/config/routes.rb | config/routes.rb | Chaskiq::Engine.routes.draw do
root 'dashboard#show'
#public
resources :campaigns, only: :show do
member do
get :subscribe
get :unsubscribe
get :forward
end
resources :subscribers do
member do
get :delete
end
end
resources :tracks do
member do
get :click
get :open
get :bounce
get :spam
end
end
end
#private
scope 'manage',as: :manage do
resources :campaigns, controller: 'manage/campaigns' do
resources :wizard, controller: 'manage/campaign_wizard'
member do
get :preview
get :premailer_preview
get :test
get :deliver
get :clone
get :editor
get :purge
get :iframe
end
resources :attachments, controller: 'manage/attachments'
resources :metrics, controller: 'manage/metrics'
end
resources :lists, controller: 'manage/lists' do
member do
patch :upload
get :clear
end
resources :subscribers, controller: 'manage/subscribers'
end
resources :templates, controller: 'manage/templates'
end
resources :hooks do
collection do
end
end
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/config/initializers/simple_form_bootstrap.rb | config/initializers/simple_form_bootstrap.rb | # Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.error_notification_class = 'alert alert-danger'
config.button_class = 'btn btn-default'
config.boolean_label_class = nil
config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label, class: 'control-label'
b.use :input, class: 'form-control'
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :readonly
b.use :label, class: 'control-label'
b.use :input
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.wrapper tag: 'div', class: 'checkbox' do |ba|
ba.use :label_input
end
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'control-label'
b.use :input
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label, class: 'col-sm-3 control-label'
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.use :input, class: 'form-control'
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :readonly
b.use :label, class: 'col-sm-3 control-label'
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
ba.use :label_input, class: 'col-sm-9'
end
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.use :label, class: 'col-sm-3 control-label'
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label, class: 'sr-only'
b.use :input, class: 'form-control'
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
# Wrappers for forms and inputs using the Bootstrap toolkit.
# Check the Bootstrap docs (http://getbootstrap.com)
# to learn about the different styles for forms and inputs,
# buttons and other elements.
config.default_wrapper = :vertical_form
config.wrapper_mappings = {
check_boxes: :vertical_radio_and_checkboxes,
radio_buttons: :vertical_radio_and_checkboxes,
file: :vertical_file_input,
boolean: :vertical_boolean,
}
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
michelson/chaskiq-newsletters | https://github.com/michelson/chaskiq-newsletters/blob/1f0d0e6cf7f198e888d421471619bdfdedffa1d2/config/initializers/kaminari_config.rb | config/initializers/kaminari_config.rb | Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
| ruby | MIT | 1f0d0e6cf7f198e888d421471619bdfdedffa1d2 | 2026-01-04T17:52:24.705458Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/spec/spec_helper.rb | spec/spec_helper.rb | ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
require 'minitest/autorun' | ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment-sidekiq.rb | lib/apartment-sidekiq.rb | require 'apartment/sidekiq' | ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment/sidekiq.rb | lib/apartment/sidekiq.rb | require 'apartment/sidekiq/version'
require 'sidekiq'
require 'apartment/sidekiq/middleware/client'
require 'apartment/sidekiq/middleware/server'
module Apartment
module Sidekiq
module Middleware
def self.run
::Sidekiq.configure_client do |config|
config.client_middleware do |chain|
chain.add ::Apartment::Sidekiq::Middleware::Client
end
end
::Sidekiq.configure_server do |config|
config.client_middleware do |chain|
chain.add ::Apartment::Sidekiq::Middleware::Client
end
config.server_middleware do |chain|
if defined?(::Sidekiq::Batch::Server)
chain.insert_before ::Sidekiq::Batch::Server, ::Apartment::Sidekiq::Middleware::Server
else
chain.add ::Apartment::Sidekiq::Middleware::Server
end
end
end
end
end
end
end
require 'apartment/sidekiq/railtie' if defined?(Rails)
| ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment/sidekiq/version.rb | lib/apartment/sidekiq/version.rb | module Apartment
module Sidekiq
VERSION = "1.2.0"
end
end
| ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment/sidekiq/railtie.rb | lib/apartment/sidekiq/railtie.rb | module Apartment::Sidekiq
class Railtie < Rails::Railtie
initializer "apartment.sidekiq" do
Apartment::Sidekiq::Middleware.run
end
end
end
| ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment/sidekiq/middleware/client.rb | lib/apartment/sidekiq/middleware/client.rb | module Apartment::Sidekiq::Middleware
class Client
def call(worker_class, item, queue, redis_pool=nil)
item["apartment"] ||= Apartment::Tenant.current
yield
end
end
end | ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment/sidekiq/middleware/server.rb | lib/apartment/sidekiq/middleware/server.rb | module Apartment::Sidekiq::Middleware
class Server
def call(worker_class, item, queue)
Apartment::Tenant.switch(item['apartment']) do
yield
end
end
end
end
| ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
influitive/apartment-sidekiq | https://github.com/influitive/apartment-sidekiq/blob/2e5b59def9220ea2f7861c3e21bd8cdd49fe3155/lib/apartment/sidekiq/middleware/honeybadger/server.rb | lib/apartment/sidekiq/middleware/honeybadger/server.rb | module Apartment::Sidekiq::Middleware::Honeybadger
class Server
def call(worker_class, item, queue)
Honeybadger.context({tenant: Apartment::Tenant.current})
yield
end
end
end
| ruby | MIT | 2e5b59def9220ea2f7861c3e21bd8cdd49fe3155 | 2026-01-04T17:52:26.266886Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/benchmark/generate_sample_file.rb | benchmark/generate_sample_file.rb | #!/usr/bin/env ruby
filename = ARGV.shift
unless filename
puts "Syntax: ruby #{__FILE__} <filename>"
exit 1
end
num_records = ARGV.shift || 100000
num_records = num_records.to_i
element = <<-eos
<artist id="%i">
<name>Rock Star %i</name>
<active>true</active>
<description>...</description>
<genre>Rock,Metal</genre>
</artist>
eos
puts "Writing #{num_records} sample records to #{filename}, this will take a while..."
File.open(filename, 'w') do |f|
f.puts '<?xml version="1.0" encoding="UTF-8"?>'
f.puts '<artists>'
num_records.times do |count|
f.puts(element % [count, count])
end
f.puts '</artists>'
end
puts 'DONE!'
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/benchmark/benchmark.rb | benchmark/benchmark.rb | $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
require 'saxerator'
require 'benchmark'
file = ARGV.shift
unless File.exist?(file)
puts "Cannot find file #{file}"
exit 1
end
file = File.new(file)
ADAPTERS = %i[nokogiri ox oga rexml].freeze
class SaxeratorBenchmark
def initialize(file)
@file = file
end
def with_adapter(adapter) # rubocop:disable Metrics/MethodLength
puts '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
puts
puts "Benchmark with :#{adapter} parser"
puts
puts '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
puts
count = count2 = count3 = count4 = 0
Benchmark.bm do |x|
x.report('for_tag') do
Saxerator.parser(@file) { |confing| confing.adapter = adapter }
.for_tag(:artist).each { count += 1 }
end
x.report('at_depth') do
Saxerator.parser(@file) { |confing| confing.adapter = adapter }
.at_depth(2).each { count2 += 1 }
end
x.report('within') do
Saxerator.parser(@file) { |confing| confing.adapter = adapter }
.within(:artists).each { count3 += 1 }
end
x.report('composite') do
Saxerator.parser(@file) { |confing| confing.adapter = adapter }
.for_tag(:name)
.within(:artist).at_depth(3).each { count4 += 1 }
end
end
puts
puts '##########################################################'
puts
puts "for_tag: #{count} artist elements parsed"
puts "at_depth: #{count2} elements parsed"
puts "within: #{count3} artists children parsed"
puts "composite: #{count4} names within artist nested 3 tags deep parsed"
puts
end
end
saxerator_benchmark = SaxeratorBenchmark.new(file)
ADAPTERS.each { |adapter| saxerator_benchmark.with_adapter(adapter) }
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/spec_helper.rb | spec/spec_helper.rb | if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
add_filter 'spec/'
end
end
require 'support/fixture_file'
RSpec.configure do |config|
config.example_status_persistence_file_path = 'spec/examples.txt'
config.include FixtureFile
adapter = ENV['SAXERATOR_ADAPTER']
config.before(:suite) do |_|
unless adapter
puts "SAXERATOR_ADAPTER was not defined, using default"
next
end
puts "Using '#{adapter}' for parsing"
end
config.before do |example|
if adapter && !example.metadata[:nokogiri_only]
require 'saxerator/configuration'
require "saxerator/adapters/#{adapter}"
adapter_class = Saxerator::Adapters.const_get(adapter.capitalize, false)
allow_any_instance_of(Saxerator::Configuration).to receive(:adapter) { adapter_class }
end
end
end
require 'saxerator'
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/support/fixture_file.rb | spec/support/fixture_file.rb | module FixtureFile
def fixture_file(name)
File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', name))
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/saxerator_spec.rb | spec/lib/saxerator_spec.rb | require 'spec_helper'
RSpec.describe Saxerator do
context '#parser' do
subject(:parser) do
Saxerator.parser(xml)
end
context 'with a File argument' do
let(:xml) { fixture_file('flat_blurbs.xml') }
it 'can parse it' do
expect(parser.all).to eq('blurb' => %w[one two three])
end
it 'allows multiple operations on the same parser' do
# This exposes a bug where if a File is not reset only the first
# Enumerable method works as expected
expect(parser.for_tag(:blurb).first).to eq('one')
expect(parser.for_tag(:blurb).first).to eq('one')
end
it 'call each without block returns enumerator' do
enumerator = parser.for_tag(:blurb).each
expect(enumerator).to be_an(Enumerator)
expect(enumerator.to_a).to eq(%w(one two three))
end
end
context 'with a String argument' do
let(:xml) do
<<-eos
<book>
<name>Illiterates that can read</name>
<author>Eunice Diesel</author>
</book>
eos
end
it 'can parse it' do
expect(parser.all).to eq('name' => 'Illiterates that can read', 'author' => 'Eunice Diesel')
end
it 'call each without block returns enumerator' do
enumerator = parser.for_tag(:name).each
expect(enumerator).to be_an(Enumerator)
expect(enumerator.to_a).to eq(['Illiterates that can read'])
end
end
context 'raise exception when ' do
let(:broken_xml_1) do
<<-eos
<book>
<name>Illiterates that can read</name>
<author>Eunice Diesel</author>
eos
end
let(:broken_xml_2) do
<<-eos
<book>
<name>Illiterates that can read
<author>Eunice Diesel</author>
</book>
eos
end
unless ENV['SAXERATOR_ADAPTER'] == "rexml"
it 'ending node not found' do
expect { Saxerator.parser(broken_xml_1).all }.to raise_error(Saxerator::ParseException)
end
end
it 'node in the middle not closed' do
expect { Saxerator.parser(broken_xml_2).all }.to raise_error(Saxerator::ParseException)
end
end
end
context 'configuration' do
let(:xml) { '<foo><bar foo="bar">baz</bar></foo>' }
context 'output type' do
subject(:parser) do
Saxerator.parser(xml) do |config|
config.output_type = output_type
end
end
context 'with config.output_type = :hash' do
let(:output_type) { :hash }
specify { expect(parser.all).to eq('bar' => 'baz') }
end
context 'with config.output_type = :xml' do
let(:output_type) { :xml }
specify { expect(parser.all).to be_a REXML::Document }
specify { expect(parser.all.to_s).to include '<bar foo="bar">' }
end
context 'with an invalid config.output_type' do
let(:output_type) { 'lmao' }
specify { expect { parser }.to raise_error(ArgumentError) }
end
end
context 'symbolize keys' do
subject(:parser) do
Saxerator.parser(xml) do |config|
config.symbolize_keys!
config.output_type = :hash
end
end
specify { expect(parser.all).to eq(bar: 'baz') }
specify { expect(parser.all.name).to eq(:foo) }
it 'will symbolize attributes' do
parser.for_tag('bar').each do |tag|
expect(tag.attributes).to include(foo: 'bar')
end
end
end
context 'with ignore namespaces' do
let(:xml) do
<<-eos
<ns1:foo xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns1="http://foo.com" xmlns:ns3="http://bar.com">
<ns3:bar>baz</ns3:bar>
<ns3:bar bar="bar" ns1:foo="foo" class="class">bax</ns3:bar>
</ns1:foo>
eos
end
subject(:parser) do
Saxerator.parser(xml) do |config|
config.ignore_namespaces!
end
end
specify do
bar_count = 0
parser.for_tag('bar').each do |_|
bar_count += 1
end
expect(bar_count).to eq(2)
end
end
context 'with strip namespaces' do
let(:xml) do
<<-XML
<ns1:foo xmlns:ns1="http://foo.com" xmlns:ns3="http://baz.com">
<ns3:bar>baz</ns3:bar>
</ns1:foo>
XML
end
subject(:parser) do
Saxerator.parser(xml) do |config|
config.strip_namespaces!
end
end
specify { expect(parser.all).to eq('bar' => 'baz') }
specify { expect(parser.all.name).to eq('foo') }
context 'combined with symbolize keys' do
subject(:parser) do
Saxerator.parser(xml) do |config|
config.strip_namespaces!
config.symbolize_keys!
end
end
specify { expect(parser.all).to eq(bar: 'baz') }
end
context 'for specific namespaces' do
let(:xml) do
<<-XML
<ns1:foo xmlns:ns1="http://foo.com" xmlns:ns2="http://bar.com" xmlns:ns3="http://baz.com">
<ns2:bar>baz</ns2:bar>
<ns3:bar>biz</ns3:bar>
</ns1:foo>
XML
end
subject(:parser) do
Saxerator.parser(xml) do |config|
config.strip_namespaces! :ns1, :ns3
end
end
specify { expect(parser.all).to eq('ns2:bar' => 'baz', 'bar' => 'biz') }
specify { expect(parser.all.name).to eq('foo') }
end
end
end
context 'configuration with put_attributes_in_hash!' do
let(:xml) { '<foo foo="bar"><bar>baz</bar></foo>' }
subject(:parser) do
Saxerator.parser(xml) do |config|
config.put_attributes_in_hash!
end
end
it 'can parse it' do
expect(parser.all).to eq('bar' => 'baz', 'foo' => 'bar')
end
context 'with configured output_type :xml' do
subject(:parser) do
Saxerator.parser(xml) do |config|
config.put_attributes_in_hash!
config.output_type = :xml
end
end
context 'raises error with' do
specify { expect { parser }.to raise_error(ArgumentError) }
end
end
context 'with symbolize_keys!' do
subject(:parser) do
Saxerator.parser(xml) do |config|
config.put_attributes_in_hash!
config.symbolize_keys!
end
end
it 'will symbolize attribute hash keys' do
expect(parser.all.to_hash).to include(bar: 'baz', foo: 'bar')
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/builder/xml_builder_spec.rb | spec/lib/builder/xml_builder_spec.rb | # encoding: utf-8
require 'spec_helper'
describe 'Saxerator xml format' do
let(:xml) { fixture_file('nested_elements.xml') }
subject(:entry) do
Saxerator.parser(xml) do |config|
config.output_type = :xml
end.for_tag(:entry).first
end
it { is_expected.to be_a(REXML::Document) }
it 'looks like the original document' do
expected_xml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><entry><id>1</id><published>2012-01-01T16:17:00-06:00</published><updated>2012-01-01T16:17:00-06:00</updated><link href="https://example.com/blog/how-to-eat-an-airplane"/><title>How to eat an airplane</title><content type="html"><p>Airplanes are very large — this can present difficulty in digestion.</p></content><media:thumbnail url="http://www.gravatar.com/avatar/a9eb6ba22e482b71b266daadf9c9a080?s=80"/><author><name>Soul<utter</name></author><contributor type="primary"><name>Jane Doe</name></contributor><contributor><name>Leviticus Alabaster</name></contributor></entry>' # rubocop:disable Metrics/LineLength
expect(entry.to_s).to eq(expected_xml)
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/builder/hash_builder_spec.rb | spec/lib/builder/hash_builder_spec.rb | # encoding: utf-8
require 'spec_helper'
describe 'Saxerator (default) hash format' do
let(:xml) { fixture_file('nested_elements.xml') }
subject(:entry) { Saxerator.parser(xml).for_tag(:entry).first }
# string
specify { expect(entry['title']).to eq('How to eat an airplane') }
# hash and cdata inside name
specify { expect(entry['author']).to eq('name' => 'Soul<utter') }
# array of hashes
specify do
expect(entry['contributor'])
.to eq([{ 'name' => 'Jane Doe' }, { 'name' => 'Leviticus Alabaster' }])
end
# attributes on a hash
specify { expect(entry['contributor'][0].attributes['type']).to eq('primary') }
# attributes on a string
specify { expect(entry['content'].attributes['type']).to eq('html') }
# name on a hash
specify { expect(entry.name).to eq('entry') }
# name on a string
specify { expect(entry['title'].name).to eq('title') }
describe '#to_s' do
it 'preserves the element name' do
expect(entry['title'].to_a.name).to eq('title')
end
end
describe '#to_h' do
it 'preserves the element name' do
expect(entry.to_h.name).to eq('entry')
end
end
describe '#to_a' do
it 'preserves the element name on a parsed hash' do
expect(entry.to_a.name).to eq('entry')
end
it 'converts parsed hashes to nested key/value pairs (just like regular hashes)' do
expect(entry.to_a.first).to eq(['id', '1'])
end
it 'preserves the element name on a parsed string' do
expect(entry['title'].to_a.name).to eq('title')
end
it 'preserves the element name on an array' do
expect(entry['contributor'].to_a.name).to eq 'contributor'
end
end
# name on an array
specify { expect(entry['contributor'].name).to eq('contributor') }
# character entity decoding
specify do
expect(entry['content'])
.to eq('<p>Airplanes are very large — this can present difficulty in digestion.</p>')
end
context 'parsing an empty element' do
subject(:element) { entry['media:thumbnail'] }
it { is_expected.to be_empty }
it 'has attributes' do
expect(element.attributes.keys).to eq ['url']
end
it 'has a name' do
expect(element.name).to eq 'media:thumbnail'
end
end
describe 'Saxerator elements with both text and element children format' do
let(:xml) { fixture_file('mixed_text_with_elements.xml') }
subject(:description) { Saxerator.parser(xml).for_tag(:description).first }
it "emits an array of child elements in the order they appear in the document", :aggregate_failures do
expect(description.map(&:class))
.to eq([
Saxerator::Builder::StringElement,
Saxerator::Builder::ArrayElement,
Saxerator::Builder::StringElement,
Saxerator::Builder::HashElement
])
# verifying the nodes are what we expect them to be
expect(description.last.name).to eq 'p'
expect(description.last.attributes).to include('id' => '3')
expect(subject.first).to eq "This is a description."
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/for_tag_spec.rb | spec/lib/dsl/for_tag_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#for_tag' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<blurbs>
<blurb>one</blurb>
<blurb>two</blurb>
<blurb>three</blurb>
<notablurb>four</notablurb>
</blurbs>
eos
end
it 'only selects the specified tag' do
expect(parser.for_tag(:blurb).inject([], :<<)).to eq(['one', 'two', 'three'])
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/at_depth_spec.rb | spec/lib/dsl/at_depth_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#at_depth' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<publications>
<book>
<name>How to eat an airplane</name>
<author>Leviticus Alabaster</author>
</book>
<book>
<name>To wallop a horse in the face</name>
<author>Jeanne Clarewood</author>
</book>
</publications>
eos
end
it 'parses elements at the requested tag depth' do
expect(parser.at_depth(2).inject([], :<<)).to eq([
'How to eat an airplane',
'Leviticus Alabaster',
'To wallop a horse in the face',
'Jeanne Clarewood'
])
end
it 'works in combination with #for_tag' do
expect(parser.at_depth(2).for_tag(:name).inject([], :<<)).to eq([
'How to eat an airplane',
'To wallop a horse in the face'
])
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/with_attributes_spec.rb | spec/lib/dsl/with_attributes_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#with_attributes' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<book>
<name>How to eat an airplane</name>
<author>
<name type="primary" ridiculous="true">Leviticus Alabaster</name>
<name type="foreword" ridiculous="true">Eunice Diesel</name>
<name type="foreword">Jackson Frylock</name>
</author>
</book>
eos
end
it 'matches tags with the exact specified attributes' do
expect(parser.with_attributes(type: :primary, ridiculous: 'true').inject([], :<<)).to eq([
'Leviticus Alabaster'
])
end
it 'matches tags which have the specified attributes' do
expect(parser.with_attributes(%w[type ridiculous]).inject([], :<<))
.to eq(['Leviticus Alabaster', 'Eunice Diesel'])
end
it 'raises ArgumentError if you pass something other than a Hash or Array' do
expect { parser.with_attributes('asdf') }.to raise_error ArgumentError
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/all_spec.rb | spec/lib/dsl/all_spec.rb | require 'spec_helper'
describe 'Saxerator::FullDocument#all' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<blurbs>
<blurb>one</blurb>
<blurb>two</blurb>
<blurb>three</blurb>
<notablurb>four</notablurb>
<empty with="attribute"/>
</blurbs>
eos
end
it 'allows you to parse an entire document' do
expect(parser.all)
.to eq 'blurb' => ['one', 'two', 'three'], 'notablurb' => 'four', 'empty' => {}
end
context 'with_put_attributes_in_hash' do
subject(:parser) do
Saxerator.parser(xml) { |config| config.put_attributes_in_hash! }
end
it 'allows you to parse an entire document' do
expect(parser.all).to eq(
'blurb' => ['one', 'two', 'three'],
'notablurb' => 'four',
'empty' => { 'with' => 'attribute' }
)
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/within_spec.rb | spec/lib/dsl/within_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#within' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<magazine>
<name>The Smarterest</name>
<article>
<name>Is our children learning?</name>
<author>Hazel Nutt</author>
</article>
</magazine>
eos
end
it 'only parses elements nested within the specified tag' do
expect(parser.within(:article).inject([], :<<)).to eq([
'Is our children learning?',
'Hazel Nutt'
])
end
it 'works in combination with #for_tag' do
expect(parser.for_tag(:name).within(:article).inject([], :<<))
.to eq(['Is our children learning?'])
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/with_attribute_spec.rb | spec/lib/dsl/with_attribute_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#with_attribute' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<book>
<name>How to eat an airplane</name>
<author>
<name type="primary">Leviticus Alabaster</name>
<name type="foreword">Eunice Diesel</name>
</author>
</book>
eos
end
it 'matches tags with the specified attributes' do
expect(subject.with_attribute(:type).inject([], :<<)).to eq([
'Leviticus Alabaster',
'Eunice Diesel'
])
end
it 'matches tags with the specified attributes' do
expect(subject.with_attribute(:type, :primary).inject([], :<<)).to eq(['Leviticus Alabaster'])
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/for_tags_spec.rb | spec/lib/dsl/for_tags_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#for_tags' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<blurbs>
<blurb1>one</blurb1>
<blurb2>two</blurb2>
<blurb3>three</blurb3>
</blurbs>
eos
end
it 'only selects the specified tags' do
expect(parser.for_tags(%w[blurb1 blurb3]).inject([], :<<)).to eq(['one', 'three'])
end
it 'raises an ArgumentError for a non-Array argument' do
expect { parser.for_tags('asdf') }.to raise_error ArgumentError
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/spec/lib/dsl/child_of_spec.rb | spec/lib/dsl/child_of_spec.rb | require 'spec_helper'
describe 'Saxerator::DSL#child_of' do
subject(:parser) { Saxerator.parser(xml) }
let(:xml) do
<<-eos
<root>
<children>
<name>Rudy McMannis</name>
<children>
<name>Tom McMannis</name>
</children>
<grandchildren>
<name>Mildred Marston</name>
</grandchildren>
<name>Anne Welsh</name>
</children>
</root>
eos
end
it 'only parses children of the specified tag' do
expect(parser.child_of(:grandchildren).inject([], :<<)).to eq([
'Mildred Marston'
])
end
it 'works in combination with #for_tag' do
expect(parser.for_tag(:name).child_of(:children).inject([], :<<)).to eq([
'Rudy McMannis',
'Tom McMannis',
'Anne Welsh'
])
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator.rb | lib/saxerator.rb | require 'saxerator/version'
require 'saxerator/sax_handler'
require 'saxerator/dsl'
require 'saxerator/full_document'
require 'saxerator/document_fragment'
require 'saxerator/configuration'
require 'saxerator/builder'
require 'saxerator/builder/array_element'
require 'saxerator/builder/hash_element'
require 'saxerator/builder/string_element'
require 'saxerator/builder/hash_builder'
require 'saxerator/builder/xml_builder'
require 'saxerator/parser/accumulator'
require 'saxerator/parser/latched_accumulator'
require 'saxerator/latches/for_tags'
require 'saxerator/latches/at_depth'
require 'saxerator/latches/within'
require 'saxerator/latches/child_of'
require 'saxerator/latches/with_attributes'
module Saxerator
class ParseException < StandardError
end
extend self
def parser(xml)
config = Configuration.new
yield(config) if block_given?
FullDocument.new(xml, config)
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/full_document.rb | lib/saxerator/full_document.rb | module Saxerator
class FullDocument
include DSL
def initialize(source, config)
@source = source
@config = config
@latches = []
end
def all
DocumentFragment.new(@source, @config, @latches).first
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/version.rb | lib/saxerator/version.rb | module Saxerator
VERSION = '0.9.9'.freeze
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/sax_handler.rb | lib/saxerator/sax_handler.rb | module Saxerator
class SaxHandler
def characters(_text); end
def start_element(_name, _attrs = []); end
def end_element(_name); end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/dsl.rb | lib/saxerator/dsl.rb | module Saxerator
module DSL
def for_tag(*tags)
for_tags(tags)
end
def for_tags(tags)
raise ArgumentError, '#for_tags requires an Array argument' unless tags.is_a? Array
specify Latches::ForTags.new(tags.map(&:to_s))
end
def at_depth(depth)
specify Latches::AtDepth.new(depth.to_i)
end
def within(tag)
specify Latches::Within.new(tag.to_s)
end
def child_of(tag)
specify Latches::ChildOf.new(tag.to_s)
end
def with_attribute(name, value = nil)
specify Latches::WithAttributes.new(name.to_s => !value.nil? ? value.to_s : nil)
end
def with_attributes(attrs)
if attrs.is_a? Array
attrs = Hash[attrs.map { |k| [k, nil] }]
elsif attrs.is_a? Hash
attrs = Hash[attrs.map { |k, v| [k.to_s, v ? v.to_s : v] }]
else
raise ArgumentError, 'attributes should be a Hash or Array'
end
specify Latches::WithAttributes.new(attrs)
end
private
def specify(predicate)
DocumentFragment.new(@source, @config, @latches + [predicate])
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/configuration.rb | lib/saxerator/configuration.rb | module Saxerator
class Configuration
attr_writer :hash_key_generator
attr_reader :output_type
ADAPTER_TYPES = %i[ox nokogiri rexml oga].freeze
def initialize
@adapter = :rexml
@output_type = :hash
@put_attributes_in_hash = false
@ignore_namespaces = false
end
def adapter=(name)
unless ADAPTER_TYPES.include?(name)
raise ArgumentError, "Unknown adapter '#{name.inspect}'"
end
@adapter = name
end
def adapter
require "saxerator/adapters/#{@adapter}"
Saxerator::Adapters.const_get(@adapter.to_s.capitalize, false)
end
def output_type=(val)
raise ArgumentError, "Unknown output_type '#{val.inspect}'" unless Builder.valid?(val)
@output_type = val
raise_error_if_using_put_attributes_in_hash_with_xml
end
def output_type
@_output_type ||= Builder.to_class(@output_type)
end
def generate_key_for(val)
hash_key_generator.call val
end
def hash_key_normalizer
@hash_key_normalizer ||= ->(x) { x.to_s }
end
def hash_key_generator
@hash_key_generator || hash_key_normalizer
end
def symbolize_keys!
@hash_key_generator = ->(x) { hash_key_normalizer.call(x).to_sym }
end
def strip_namespaces!(*namespaces)
if namespaces.any?
matching_group = namespaces.join('|')
@hash_key_normalizer = ->(x) { x.to_s.gsub(/(#{matching_group}):/, '') }
else
@hash_key_normalizer = ->(x) { x.to_s.gsub(/\w+:/, '') }
end
end
def ignore_namespaces?
@ignore_namespaces
end
def ignore_namespaces!
@ignore_namespaces = true
end
def put_attributes_in_hash!
@put_attributes_in_hash = true
raise_error_if_using_put_attributes_in_hash_with_xml
end
def put_attributes_in_hash?
@put_attributes_in_hash
end
def raise_error_if_using_put_attributes_in_hash_with_xml
if @output_type != :hash && @put_attributes_in_hash
raise ArgumentError, "put_attributes_in_hash! is only valid \
when using output_type = :hash (the default)'"
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/document_fragment.rb | lib/saxerator/document_fragment.rb | module Saxerator
class DocumentFragment
include Enumerable
include DSL
def initialize(source, config = nil, latches = [])
@source = source
@latches = latches
@config = config
end
def each(&block)
return to_enum unless block_given?
# Always have to start at the beginning of a File
@source.rewind if @source.respond_to?(:rewind)
reader = Parser::LatchedAccumulator.new(@config, @latches, block)
@config.adapter.parse(@source, reader)
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/builder.rb | lib/saxerator/builder.rb | module Saxerator
module Builder
extend self
def valid?(type)
Builder.const_defined? "#{camel_case(type)}Builder"
end
def to_class(type)
Builder.const_get("#{camel_case(type)}Builder")
end
def camel_case(str)
str = str.to_s
return str if str !~ /_/ && str =~ /[A-Z]+.*/
str.split('_').map(&:capitalize).join
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/builder/hash_builder.rb | lib/saxerator/builder/hash_builder.rb | module Saxerator
module Builder
class HashBuilder
attr_reader :name
def initialize(config, name, attributes)
@config = config
@name = config.generate_key_for(name)
@attributes = normalize_attributes(attributes)
@children = []
end
def add_node(node)
@children << node
end
def to_s
StringElement.new(@children.join, @name, @attributes)
end
def to_hash
hash = HashElement.new(@name, @attributes)
@children.each do |child|
name = child.name
element = child.block_variable
add_to_hash_element(hash, name, element)
end
if @config.put_attributes_in_hash?
@attributes.each do |attribute|
attribute.each_slice(2) do |name, element|
add_to_hash_element(hash, name, element)
end
end
end
hash
end
def to_array
arr = @children.map do |child|
if child.kind_of?(String)
StringElement.new(child)
else
child.block_variable
end
end
ArrayElement.new(arr, @name, @attributes)
end
def add_to_hash_element(hash, name, element)
name = generate_key(name)
if hash.key? name
unless hash[name].is_a?(ArrayElement)
hash[name] = ArrayElement.new([hash[name]], name)
end
hash[name] << element
else
hash[name] = element
end
end
def block_variable
return to_hash unless @children.any? { |c| c.kind_of?(String) }
return to_s if @children.all? { |c| c.kind_of?(String) }
to_array
end
def normalize_attributes(attributes)
Hash[attributes.map { |key, value| [generate_key(key), value] }]
end
def generate_key(name)
@config.generate_key_for(name)
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/builder/xml_builder.rb | lib/saxerator/builder/xml_builder.rb | require 'rexml/document'
module Saxerator
module Builder
class XmlBuilder
attr_reader :name
def initialize(config, name, attributes)
@config = config
@name = name
@attributes = attributes
@children = []
@text = false
end
def add_node(node)
@text = true if node.is_a? String
@children << node
end
def to_xml(builder)
element = REXML::Element.new(name, nil, attribute_quote: :quote)
element.add_attributes(@attributes)
if @text
element.add_text(@children.join)
else
@children.each { |child| child.to_xml(element) }
end
builder.elements << element
end
def block_variable
builder = REXML::Document.new
builder << REXML::XMLDecl.new('1.0', 'UTF-8')
to_xml(builder)
builder
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/builder/string_element.rb | lib/saxerator/builder/string_element.rb | require 'saxerator/builder/array_element'
require 'delegate'
module Saxerator
module Builder
class StringElement < DelegateClass(String)
attr_accessor :attributes
attr_accessor :name
def initialize(str, name = nil, attributes = nil)
@name = name
@attributes = attributes
super(str)
end
def to_a
ArrayElement.new(self, name)
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/builder/array_element.rb | lib/saxerator/builder/array_element.rb | require 'delegate'
module Saxerator
module Builder
class ArrayElement < DelegateClass(Array)
attr_accessor :name, :attributes
def initialize(arr = [], name = nil, attributes = nil)
@name = name
@attributes = attributes
super(arr)
end
def to_a; self end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/builder/hash_element.rb | lib/saxerator/builder/hash_element.rb | require 'saxerator/builder/array_element'
require 'delegate'
module Saxerator
module Builder
class HashElement < DelegateClass(Hash)
attr_accessor :attributes
attr_accessor :name
def initialize(name = nil, attributes = nil)
@name = name
@attributes = attributes
super({})
end
def to_a
ArrayElement.new(super, name)
end
def to_h; self end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/latches/child_of.rb | lib/saxerator/latches/child_of.rb | module Saxerator
module Latches
class ChildOf < ::Saxerator::SaxHandler
def initialize(name)
@name = name
@depths = []
end
def start_element(name, _)
increment_depth(1) if depth_within_element > 0
@depths.push 1 if @name == name
end
def end_element(_)
return unless depth_within_element > 0
increment_depth(-1)
@depths.pop if @depths[-1].zero?
end
def open?
depth_within_element == 2
end
def increment_depth(amount)
@depths.map! { |depth| depth + amount }
end
def depth_within_element
!@depths.empty? ? @depths[-1] : 0
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/latches/with_attributes.rb | lib/saxerator/latches/with_attributes.rb | require 'saxerator/latches/abstract_latch'
module Saxerator
module Latches
class WithAttributes < AbstractLatch
def initialize(attrs)
@attrs = attrs
end
def start_element(_, attributes)
attributes = Hash[attributes]
if @attrs.all? { |k, v| attributes[k] && (v.nil? || attributes[k] == v) }
open
else
close
end
end
def end_element(_)
close
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/latches/abstract_latch.rb | lib/saxerator/latches/abstract_latch.rb | module Saxerator
module Latches
class AbstractLatch < ::Saxerator::SaxHandler
def open
@open = true
end
def close
@open = false
end
def open?
@open
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/latches/for_tags.rb | lib/saxerator/latches/for_tags.rb | require 'saxerator/latches/abstract_latch'
module Saxerator
module Latches
class ForTags < AbstractLatch
def initialize(names)
@names = names
end
def start_element(name, _)
@names.include?(name) ? open : close
end
def end_element(name)
close if @names.include?(name)
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/latches/within.rb | lib/saxerator/latches/within.rb | module Saxerator
module Latches
class Within < ::Saxerator::SaxHandler
def initialize(name)
@name = name
@depth_within_element = 0
end
def start_element(name, _)
@depth_within_element += 1 if name == @name || @depth_within_element > 0
end
def end_element(_)
@depth_within_element -= 1 if @depth_within_element > 0
end
def open?
@depth_within_element > 1
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/latches/at_depth.rb | lib/saxerator/latches/at_depth.rb | module Saxerator
module Latches
class AtDepth < ::Saxerator::SaxHandler
def initialize(depth)
@target_depth = depth
@current_depth = -1
end
def start_element(_, __)
@current_depth += 1
end
def end_element(_)
@current_depth -= 1
end
def open?
@current_depth == @target_depth
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/adapters/nokogiri.rb | lib/saxerator/adapters/nokogiri.rb | require 'forwardable'
require 'nokogiri'
module Saxerator
module Adapters
class Nokogiri < ::Nokogiri::XML::SAX::Document
extend Forwardable
def self.parse(source, reader)
parser = ::Nokogiri::XML::SAX::Parser.new(new(reader))
parser.parse(source)
end
def initialize(reader)
@reader = reader
@ignore_namespaces = reader.ignore_namespaces?
end
def_delegators :@reader, :start_element, :end_element, :characters
def_delegator :@reader, :characters, :cdata_block
def start_element_namespace(name, attrs = [], _prefix = nil, _uri = nil, _ns = [])
return super unless @ignore_namespaces
start_element(name, strip_namespace(attrs))
end
def end_element_namespace(name, _prefix = nil, _uri = nil)
return super unless @ignore_namespaces
end_element(name)
end
def error(message)
raise Saxerator::ParseException, message
end
private
def strip_namespace(attrs)
attrs.map { |attr| [attr.localname, attr.value] }
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/adapters/oga.rb | lib/saxerator/adapters/oga.rb | require 'forwardable'
require 'oga'
module Saxerator
module Adapters
class Oga
extend Forwardable
def self.parse(source, reader)
parser = ::Oga::XML::SaxParser.new(new(reader), source, strict: true)
parser.parse
rescue LL::ParserError => message
raise Saxerator::ParseException, message
end
def initialize(reader)
@reader = reader
@ignore_namespaces = reader.ignore_namespaces?
end
def_delegator :@reader, :characters, :on_text
def_delegator :@reader, :characters, :on_cdata
def on_element(namespace, name, attrs = {})
name = "#{namespace}:#{name}" if namespace && !@ignore_namespaces
attrs = @ignore_namespaces ? strip_namespace(attrs) : attrs.to_a
@reader.start_element(name, attrs)
end
def after_element(namespace, name)
name = "#{namespace}:#{name}" if namespace && !@ignore_namespaces
@reader.end_element(name)
end
private
def strip_namespace(attrs)
attrs.map { |k, v| [k.gsub(NAMESPACE_MATCHER, ''), v] }
end
NAMESPACE_MATCHER = /\A.+:/
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/adapters/rexml.rb | lib/saxerator/adapters/rexml.rb | require 'forwardable'
require 'rexml/document'
require 'rexml/streamlistener'
module Saxerator
module Adapters
class Rexml
extend Forwardable
include REXML::StreamListener
def self.parse(source, reader)
handler = new(reader)
REXML::Document.parse_stream(source, handler)
rescue REXML::ParseException => message
raise Saxerator::ParseException, message
end
def initialize(reader)
@reader = reader
@ignore_namespaces = reader.ignore_namespaces?
end
def_delegator :@reader, :characters, :text
def_delegator :@reader, :characters, :cdata
def tag_start(name, attrs)
name = strip_namespace(name) if @ignore_namespaces
@reader.start_element(name, attrs)
end
def tag_end(name)
name = strip_namespace(name) if @ignore_namespaces
@reader.end_element(name)
end
private
def strip_namespace(name)
name.split(':').last
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/adapters/ox.rb | lib/saxerator/adapters/ox.rb | require 'forwardable'
require 'ox'
module Saxerator
module Adapters
class Ox # < ::Ox::Sax
extend Forwardable
def self.parse(source, reader)
handler = new(reader)
::Ox.sax_parse(handler, source)
end
attr_accessor :name
attr_reader :attributes
attr_reader :reader
def initialize(reader)
@reader = reader
@attributes = {}
@name = ''
end
def guard!
reader.start_element(name, attributes.to_a) unless name.empty?
reset!
end
def attr(name, value)
attributes[name.to_s] = value
end
def start_element(name)
guard!
name = name.to_s
name = strip_namespace(name) if reader.ignore_namespaces?
self.name = name
end
def end_element(name)
guard!
name = name.to_s
name = strip_namespace(name) if reader.ignore_namespaces?
reader.end_element(name)
end
def text(str)
guard!
reader.characters(str)
end
alias cdata text
def error(message, _, _)
raise Saxerator::ParseException, message
end
private
def reset!
@attributes.clear
@name = ''
end
def strip_namespace(name)
name.split(':').last
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/parser/accumulator.rb | lib/saxerator/parser/accumulator.rb | module Saxerator
module Parser
class Accumulator < ::Saxerator::SaxHandler
def initialize(config, block)
@stack = []
@config = config
@block = block
end
def start_element(name, attrs = [])
@stack.push @config.output_type.new(@config, name, Hash[attrs])
end
def end_element(_)
if @stack.size > 1
last = @stack.pop
@stack[-1].add_node last
else
@block.call(@stack.pop.block_variable)
end
end
def characters(string)
@stack[-1].add_node(string) unless string.strip.empty?
end
def accumulating?
!@stack.empty?
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
soulcutter/saxerator | https://github.com/soulcutter/saxerator/blob/bdae3703d777a41cb070d7a79ca0a1d32de894cd/lib/saxerator/parser/latched_accumulator.rb | lib/saxerator/parser/latched_accumulator.rb | module Saxerator
module Parser
class LatchedAccumulator < ::Saxerator::SaxHandler
def initialize(config, latches, block)
@latches = latches
@accumulator = Accumulator.new(config, block)
@ignore_namespaces = config.ignore_namespaces?
end
def check_latches_and_passthrough(method, *args)
@latches.each { |latch| latch.send(method, *args) }
@accumulator.send(method, *args) if @accumulator.accumulating? || @latches.all?(&:open?)
end
def start_element(name, attrs = [])
check_latches_and_passthrough(:start_element, name, attrs)
end
def end_element(name)
check_latches_and_passthrough(:end_element, name)
end
def characters(string)
check_latches_and_passthrough(:characters, string)
end
def ignore_namespaces?
@ignore_namespaces
end
end
end
end
| ruby | MIT | bdae3703d777a41cb070d7a79ca0a1d32de894cd | 2026-01-04T17:52:28.472040Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/version.rb | version.rb | module ActionAuth
VERSION = "1.8.7"
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/jobs/action_auth/application_job.rb | app/jobs/action_auth/application_job.rb | module ActionAuth
class ApplicationJob < ActiveJob::Base
end
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/helpers/action_auth/application_helper.rb | app/helpers/action_auth/application_helper.rb | module ActionAuth
module ApplicationHelper
end
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/webauthn_credentials_controller.rb | app/controllers/action_auth/webauthn_credentials_controller.rb | class ActionAuth::WebauthnCredentialsController < ApplicationController
before_action :authenticate_user!
layout "action_auth/application"
def new
end
def options
if current_user.webauthn_id.blank?
current_user.update!(webauthn_id: WebAuthn.generate_user_id)
end
create_options = WebAuthn::Credential.options_for_create(
user: {
id: current_user.webauthn_id,
name: current_user.email
},
exclude: current_user.webauthn_credentials.pluck(:external_id)
)
session[:current_challenge] = create_options.challenge
respond_to do |format|
format.json { render json: create_options }
if defined?(Turbo)
format.turbo_stream { render json: create_options }
end
end
end
def create
webauthn_credential = WebAuthn::Credential.from_create(params)
begin
webauthn_credential.verify(session[:current_challenge])
credential = current_user.webauthn_credentials.build(
external_id: webauthn_credential.id,
nickname: params[:credential_nickname],
public_key: webauthn_credential.public_key,
sign_count: webauthn_credential.sign_count,
key_type: key_type
)
if credential.save
render json: { status: "ok" }, status: :ok
else
render json: "Couldn't add your Security Key", status: :unprocessable_entity
end
rescue WebAuthn::Error => e
Rails.logger.error "❌ Verification failed: #{e.message}"
render json: "Verification failed: #{e.message}", status: :unprocessable_entity
end
end
def destroy
current_user.webauthn_credentials.destroy(params[:id])
redirect_to sessions_path
end
private
def key_type
transports = params.dig(:response, :transports)
return :unknown unless transports.present?
transport_types = {
["internal", "hybrid"] => :passkey,
["usb", "nfc"] => :hardware,
["bluetooth", "wireless"] => :wireless,
}.freeze
transport_types.each do |keys, type|
if transports.is_a?(String)
return type if keys.include?(transports)
elsif transports.is_a?(Array)
return type if (keys & transports).any?
end
end
:unknown
end
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/webauthn_credential_authentications_controller.rb | app/controllers/action_auth/webauthn_credential_authentications_controller.rb | class ActionAuth::WebauthnCredentialAuthenticationsController < ApplicationController
before_action :ensure_user_not_authenticated
before_action :ensure_login_initiated
layout "action_auth/application"
rate_limit to: 5,
within: 20.seconds,
only: :create,
name: "webauthn-throttle",
with: -> { redirect_to sign_in_path, alert: "Too many attempts. Try again later." }
def new
get_options = WebAuthn::Credential.options_for_get(allow: user.webauthn_credentials.pluck(:external_id))
session[:current_challenge] = get_options.challenge
@options = get_options
end
def create
webauthn_credential = WebAuthn::Credential.from_get(params)
credential = user.webauthn_credentials.find_by(external_id: webauthn_credential.id)
begin
webauthn_credential.verify(
session[:current_challenge],
public_key: credential.public_key,
sign_count: credential.sign_count
)
credential.update!(sign_count: webauthn_credential.sign_count)
session.delete(:webauthn_user_id)
session = user.sessions.create
cookie_options = { value: session.id, httponly: true }
cookie_options[:secure] = Rails.env.production? if Rails.env.production?
cookie_options[:same_site] = :lax unless Rails.env.test?
cookies.signed.permanent[:session_token] = cookie_options
render json: { status: "ok" }, status: :ok
rescue WebAuthn::Error => e
Rails.logger.error "❌ Verification failed: #{e.message}"
render json: "Verification failed: #{e.message}", status: :unprocessable_entity
end
end
private
def user
@user ||= ActionAuth::User.find_by(id: session[:webauthn_user_id])
end
def ensure_login_initiated
return unless session[:webauthn_user_id].blank?
redirect_to sign_in_path
end
def ensure_user_not_authenticated
return unless current_user
redirect_to main_app.root_path
end
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/passwords_controller.rb | app/controllers/action_auth/passwords_controller.rb | module ActionAuth
class PasswordsController < ApplicationController
before_action :set_user
before_action :validate_pwned_password, only: :update
rate_limit to: 3,
within: 60.seconds,
only: :update,
name: "password-reset-throttle",
with: -> { redirect_to sign_in_path, alert: "Too many password reset attempts. Try again later." }
def edit
end
def update
if @user.update(user_params)
redirect_to sign_in_path, notice: "Your password has been changed"
else
render :edit, status: :unprocessable_entity
end
end
private
def set_user
@user = Current.user
end
def user_params
params.permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
end
def validate_pwned_password
return unless ActionAuth.configuration.pwned_enabled?
# Check minimum password requirements
if params[:password].present? && ActionAuth.configuration.password_complexity_check? && !Rails.env.test? &&
(params[:password] !~ /[A-Z]/ || params[:password] !~ /[a-z]/ || params[:password] !~ /[0-9]/ || params[:password] !~ /[^A-Za-z0-9]/)
@user.errors.add(:password, "must include at least one uppercase letter, one lowercase letter, one number, and one special character.")
render :edit, status: :unprocessable_entity and return
end
pwned = Pwned::Password.new(params[:password])
if pwned.pwned?
@user.errors.add(:password, "has been pwned #{pwned.pwned_count} times. Please choose a different password.")
render :edit, status: :unprocessable_entity
end
end
end
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
kobaltz/action_auth | https://github.com/kobaltz/action_auth/blob/b43f513090a1188e3f8f400ba4317c9b96c99181/app/controllers/action_auth/users_controller.rb | app/controllers/action_auth/users_controller.rb | module ActionAuth
class UsersController < ApplicationController
before_action :authenticate_user!
def destroy
Current.user.destroy
redirect_to main_app.root_url, notice: "Your account has been deleted."
end
end
end
| ruby | MIT | b43f513090a1188e3f8f400ba4317c9b96c99181 | 2026-01-04T17:52:32.033910Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.