repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws/aws_queue_client.rb
module EventQ module Amazon class QueueClient def initialize(options = {}) if options.has_key?(:aws_key) Aws.config[:credentials] = Aws::Credentials.new(options[:aws_key], options[:aws_secret]) end if !options.has_key?(:aws_account_number) raise ':aws_account_nu...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/date_writer.rb
module EventQ module SerializationProviders module JRuby module Oj class DateWriter < AttributeWriter def valid?(obj) obj.is_a?(Date) && !obj.is_a?(DateTime) end def exec(obj) { '^O': 'Date', year: obj.year, ...
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws/version.rb
# frozen_string_literal: true module EventQ module Amazon VERSION = "1.17.0" end end
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws.rb
<filename>eventq_aws/lib/eventq_aws.rb<gh_stars>0 require 'aws-sdk-core' require 'eventq_base' require 'eventq_aws/version' require 'eventq_aws/aws_eventq_client' require 'eventq_aws/aws_queue_client' require 'eventq_aws/aws_queue_manager' require 'eventq_aws/aws_subscription_manager' require_relative 'eventq_aws/aws_...
adamgeorgeson/eventq
eventq_base/lib/eventq_base.rb
<filename>eventq_base/lib/eventq_base.rb<gh_stars>0 require 'securerandom' require 'redlock' require 'class_kit' require 'hash_kit' require_relative 'eventq_base/version' require_relative 'eventq_base/eventq_logger' require_relative 'eventq_base/queue' require_relative 'eventq_base/exchange' require_relative 'eventq_...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/rational_writer.rb
module EventQ module SerializationProviders module JRuby module Oj class RationalWriter < AttributeWriter def valid?(obj) obj.is_a?(Rational) end def exec(obj) { '^O': 'Rational', numerator: obj.numerator, ...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/class_writer.rb
<reponame>adamgeorgeson/eventq module EventQ module SerializationProviders module JRuby module Oj class ClassWriter < AttributeWriter def valid?(obj) false end def exec(obj) hash = { '^o': obj.class } obj.instance_variables.each do |k...
adamgeorgeson/eventq
eventq_rabbitmq/lib/eventq_rabbitmq/rabbitmq_queue_manager.rb
<filename>eventq_rabbitmq/lib/eventq_rabbitmq/rabbitmq_queue_manager.rb module EventQ module RabbitMq class QueueManager X_DEAD_LETTER_EXCHANGE = 'x-dead-letter-exchange'.freeze X_MESSAGE_TTL = 'x-message-ttl'.freeze attr_accessor :durable def initialize @event_raised_exchange =...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/array_writer.rb
module EventQ module SerializationProviders module JRuby module Oj class ArrayWriter < AttributeWriter def valid?(obj) obj.is_a?(Array) end def exec(obj) array = [] obj.each do |a| array << AttributeWriter.exec(a) ...
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws/aws_queue_manager.rb
module EventQ module Amazon class QueueManager VISIBILITY_TIMEOUT = 'VisibilityTimeout'.freeze MESSAGE_RETENTION_PERIOD = 'MessageRetentionPeriod'.freeze def initialize(options) if options[:client] == nil raise ':client (QueueClient) must be specified.'.freeze end ...
adamgeorgeson/eventq
eventq_rabbitmq/spec/eventq_rabbitmq/rabbitmq_queue_client_spec.rb
RSpec.describe EventQ::RabbitMq::QueueClient do let(:client) do return EventQ::RabbitMq::QueueClient.new({ endpoint: 'rabbitmq' }) end let(:connection) { client.get_connection } let(:channel) { connection.create_channel } it 'should use dead-letter exchange' do manager = EventQ::RabbitMq::QueueMa...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/exceptions.rb
require_relative 'exceptions/invalid_signature_exception'
adamgeorgeson/eventq
eventq_base/spec/eventq_base/serialization_providers/jruby/oj/serializer_spec.rb
require_relative 'test_item' RSpec.describe EventQ::SerializationProviders::JRuby::Oj::Serializer do let(:hash1) do { string: 'foo', time: Time.now } end let(:hash2) do { string: 'bar', datetime: DateTime.now } end let(:item1) do TestItem.new.tap do |e| e.string = 'foo' e.number = 10 ...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/queue.rb
module EventQ class Queue attr_accessor :name attr_accessor :allow_retry attr_accessor :retry_delay attr_accessor :max_retry_attempts attr_accessor :allow_retry_back_off attr_accessor :max_retry_delay attr_accessor :require_signature def initialize @allow_retry = false #de...
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws/aws_subscription_manager.rb
<filename>eventq_aws/lib/eventq_aws/aws_subscription_manager.rb module EventQ module Amazon class SubscriptionManager def initialize(options) if options[:client] == nil raise "[#{self.class}] - :client (QueueClient) must be specified." end @client = options[:client] ...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/exchange.rb
<reponame>adamgeorgeson/eventq module EventQ class Exchange attr_accessor :name end end
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/attribute_writer.rb
module EventQ module SerializationProviders module JRuby module Oj class AttributeWriter def self.exec(obj) aw = descendants.detect { |a| a.new.valid?(obj) } || ClassWriter aw.new.exec(obj) end def self.descendants descendants = [] ...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/hash_writer.rb
module EventQ module SerializationProviders module JRuby module Oj class HashWriter < AttributeWriter def valid?(obj) obj.is_a?(Hash) end def exec(obj) obj.each do |key, value| obj[key] = AttributeWriter.exec(value) end ...
adamgeorgeson/eventq
eventq_aws/spec/integration/aws_queue_worker_v2_spec.rb
<filename>eventq_aws/spec/integration/aws_queue_worker_v2_spec.rb require 'spec_helper' RSpec.describe EventQ::Amazon::QueueWorkerV2, integration: true do let(:queue_client) do EventQ::Amazon::QueueClient.new({ aws_account_number: EventQ.AWS_ACCOUNT_NUMBER, aws_region: 'eu-west-1' }) end let(:queue_manager...
adamgeorgeson/eventq
eventq_aws/spec/integration/aws_queue_manager_spec.rb
<filename>eventq_aws/spec/integration/aws_queue_manager_spec.rb require 'spec_helper' RSpec.describe EventQ::Amazon::QueueManager, integration: true do let(:queue_client) do EventQ::Amazon::QueueClient.new({ aws_account_number: EventQ.AWS_ACCOUNT_NUMBER, aws_region: 'eu-west-1' }) end subject do EventQ...
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws/aws_queue_worker.rb
module EventQ module Amazon class QueueWorker include EventQ::WorkerId APPROXIMATE_RECEIVE_COUNT = 'ApproximateReceiveCount'.freeze MESSAGE = 'Message'.freeze attr_accessor :is_running def initialize @threads = [] @forks = [] @is_running = false @o...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/queue_message.rb
module EventQ class QueueMessage extend ClassKit attr_accessor_type :id, type: String attr_accessor_type :retry_attempts, type: Integer attr_accessor_type :type, type: String attr_accessor_type :content attr_accessor_type :content_type, type: String attr_accessor_type :created, type: Floa...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/version.rb
module EventqBase VERSION = "1.17.2" end
adamgeorgeson/eventq
eventq_aws/spec/aws_queue_client_spec.rb
require 'spec_helper' RSpec.describe EventQ::Amazon::QueueClient do let(:options) { { aws_account_number: '123' } } subject { described_class.new(options) } describe '#sqs' do specify do expect(subject.sqs).to be_a Aws::SQS::Client end end describe '#sns' do specify do expect(subje...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/date_time_writer.rb
module EventQ module SerializationProviders module JRuby module Oj class DateTimeWriter < AttributeWriter def valid?(obj) obj.is_a?(DateTime) end def exec(obj) seconds = obj.strftime('%S%N') d = 1_000_000_000 if seconds.st...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj.rb
<reponame>adamgeorgeson/eventq require_relative 'oj/attribute_writer' require_relative 'oj/class_writer' require_relative 'oj/rational_writer' require_relative 'oj/date_time_writer' require_relative 'oj/date_writer' require_relative 'oj/time_writer' require_relative 'oj/array_writer' require_relative 'oj/hash_writer' r...
adamgeorgeson/eventq
eventq_base/spec/eventq_base/serialization_providers/manager_spec.rb
<filename>eventq_base/spec/eventq_base/serialization_providers/manager_spec.rb<gh_stars>0 RSpec.describe EventQ::SerializationProviders::Manager do describe '#get_provider' do context 'OJ' do if RUBY_PLATFORM =~ /java/ it 'returns expected provider' do expect(subject.get_provider(EventQ::S...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby/oj/value_writer.rb
<reponame>adamgeorgeson/eventq<gh_stars>0 module EventQ module SerializationProviders module JRuby module Oj class ValueWriter < AttributeWriter def valid?(obj) obj.is_a?(String) || obj.is_a?(Integer) || obj.is_a?(Float) end def exec(obj) obj ...
adamgeorgeson/eventq
eventq_rabbitmq/lib/eventq_rabbitmq.rb
require 'eventq_base' if RUBY_PLATFORM =~ /java/ require 'march_hare' else require 'bunny' end require 'hash_kit' require_relative '../lib/eventq_rabbitmq/version' require_relative '../lib/eventq_rabbitmq/rabbitmq_queue_client' require_relative '../lib/eventq_rabbitmq/rabbitmq_queue_manager' if RUBY_PLATFORM =~ /...
adamgeorgeson/eventq
eventq_rabbitmq/spec/eventq_rabbitmq/rabbitmq_queue_worker_v2_spec.rb
RSpec.describe EventQ::RabbitMq::QueueWorkerV2 do let(:client) do return EventQ::RabbitMq::QueueClient.new({ endpoint: 'rabbitmq' }) end let(:connection) { client.get_connection } let(:channel) { connection.create_channel } after do begin channel.close if channel.open? connection.close if ...
adamgeorgeson/eventq
eventq_base/lib/eventq_base/serialization_providers/jruby.rb
require_relative 'jruby/oj' require_relative 'jruby/oj_serialization_provider'
adamgeorgeson/eventq
eventq_rabbitmq/lib/eventq_rabbitmq/rabbitmq_queue_worker.rb
module EventQ module RabbitMq class QueueWorker include EventQ::WorkerId attr_accessor :is_running def initialize @threads = [] @forks = [] @is_running = false @retry_exceeded_block = nil @on_retry_block = nil @on_error_block = nil @hash...
adamgeorgeson/eventq
eventq_aws/lib/eventq_aws/aws_eventq_client.rb
module EventQ module Amazon # Implements a general interface to raise an event # EventQ::RabbitMq::EventQClient is the sister-class which does the same for RabbitMq class EventQClient def initialize(options) if options[:client] == nil raise ':client (QueueClient) must be specifie...
james2m/reports
test/dummy4/app/reports/simple_report.rb
<reponame>james2m/reports class SimpleReport < Reports::Base end
james2m/reports
lib/reports/scoped.rb
<reponame>james2m/reports module Reports class Scoped < Base def initialize(options = {}) @scopes = Array(options['scopes']) super end private def base_relation @base_relation ||= base_class end def scoped_rows @scoped_rows ||= @scopes.inject(base_relation) do |rela...
james2m/reports
lib/reports/railtie.rb
<filename>lib/reports/railtie.rb require 'reports' require 'rails' module Reports class Railtie < Rails::Railtie initializer "reports.load", :after => "action_dispatch.configure" do |app| reloader = rails5? ? ActiveSupport::Reloader : ActionDispatch::Reloader if reloader.respond_to?(:to_prepare) ...
james2m/reports
lib/reports/base.rb
module Reports class Base class NotImplementedError < ::NotImplementedError; end include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming def initialize(options = {}) @options = options options.stringify_keys! end def file file = Fil...
james2m/reports
reports.gemspec
<gh_stars>0 # -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "reports/version" Gem::Specification.new do |s| s.name = "reports" s.version = Reports::VERSION s.date = `git log -1 --format="%cd" --date=short lib/reports/version.rb` s.authors = ["James McCarthy"...
james2m/reports
test/test_helper.rb
<reponame>james2m/reports<gh_stars>0 require 'rubygems' gem 'minitest' require 'minitest/autorun' # Configure Rails Environment environment = ENV["RAILS_ENV"] = 'test' rails_root = File.expand_path('../dummy4', __FILE__) # Load dummy rails app require File.expand_path('config/environment.rb', rails_root) Dir["#{F...
james2m/reports
lib/reports/periodic.rb
module Reports class Periodic < Scoped class InvalidPeriodError < ArgumentError; end class Period < Struct.new(:type, :title); end attr_reader :period attr_accessor :month, :from, :to class << self def periods @periods ||= ['for_month', 'between_months', 'year_to_date', 'all']....
james2m/reports
lib/report.rb
class Report include ActiveModel::Model attr_accessor :type delegate :title, :from, :to, :period, :month, :file_name, :stream, to: :report, allow_nil: true def self.all Reports.all.map { |klass| new('type' => String(klass)) } end def initialize(options = {}) @type = String(options.delete('type')...
james2m/reports
lib/reports/row.rb
<reponame>james2m/reports<gh_stars>0 module Reports class Row def initialize(row) @row = row end def to_columns @columns ||= columns.map { |column| send(column) } end def columns raise NotImplementedError end end end
james2m/reports
lib/reports.rb
require 'csv' require 'reports/row' require 'reports/base' require 'reports/scoped' require 'reports/periodic' require 'reports/periodic/scopes' require 'report' require 'reports/version' require 'reports/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 module Reports def self.all @all ||= Base.descenda...
james2m/reports
lib/reports/periodic/scopes.rb
module Reports class Periodic module Scopes def every(*args) all end def for_month(date, column='created_at') where(["DATE_FORMAT(#{quoted_table_name}.#{connection.quote_column_name column}, '%Y%m') = DATE_FORMAT(?, '%Y%m')", date]) end def between_months(date1, da...
james2m/reports
test/reports/base_test.rb
<reponame>james2m/reports require 'test_helper' describe Reports::Base do before do end describe "new" do describe "type" do let(:user) { nil } subject { SimpleReport.new } it "assign the type to the report" do subject.type.must_equal 'simple' end end end end
bjjb/adminimum
test/test_helper.rb
<filename>test/test_helper.rb $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'adminimum' require 'minitest/autorun'
bjjb/adminimum
lib/adminimum.rb
require "adminimum/version" module Adminimum # Your code goes here... end
s-p-k/acg_chef
cookbooks/apache/recipes/default.rb
<reponame>s-p-k/acg_chef<gh_stars>0 # # Cookbook:: apache # Recipe:: default # # Copyright:: 2019, The Authors, All Rights Reserved. # include_recipe 'apache::webserver'
s-p-k/acg_chef
cookbooks/chef-workstation/recipes/hello-recipe.rb
package 'cowsay' file '/home/spk/hello.txt' do action :create content 'Hello world of mine.' end
s-p-k/acg_chef
cookbooks/apache/recipes/webserver.rb
<filename>cookbooks/apache/recipes/webserver.rb # # Cookbook:: apache # Recipe:: webeserver # # Copyright:: 2019, The Authors, All Rights Reserved. package 'apache2' do action :install end
s-p-k/acg_chef
cookbooks/chef-workstation/recipes/default.rb
# # Cookbook:: chef-workstation # Recipe:: default # # Copyright:: 2019, The Authors, All Rights Reserved. include_recipe 'chef-workstation::hello-recipe'
umbresp/ELang
einterpreter.rb
<filename>einterpreter.rb if ARGV[0] if ARGV[0].end_with? ".e" # stuff begin stuff = File.read(ARGV[0]) arr = stuff.split(" ") output = "" for i in arr len = i.length thing = len.chr output += thing end puts output rescue Exception => e put...
sonots/triglav
lib/triglav/error/bad_request.rb
<gh_stars>1-10 module Triglav module Error class BadRequest < Triglav::Error::StandardError def initialize(message = nil) @code = 400 @message = message || "Bad request." end end end end
sonots/triglav
benchmark/client.rb
require 'triglav_client' class Client class Error < StandardError attr_reader :cause def initialize(message, cause) @cause = cause super(message) end end class AuthenticationError < Error; end class ConnectionError < Error; end attr_reader :url, :username, :password, :authenticator ...
sonots/triglav
config/routes.rb
<filename>config/routes.rb Rails.application.routes.draw do namespace :api do namespace :v1 do get '/apidocs' => 'apidocs#index' post '/auth/token' => 'auth#create' delete '/auth/token' => 'auth#destroy' get '/auth/me' => 'auth#me' resources :users get '/cluste...
sonots/triglav
app/models/job.rb
class Job < ApplicationRecord validates :logical_op, inclusion: { in: %w(and or) } has_many :jobs_input_resources, dependent: :destroy has_many :jobs_output_resources, dependent: :destroy has_many :input_resources, through: :jobs_input_resources, source: 'resource' has_many :output_resources, through: :jobs_o...
sonots/triglav
lib/triglav/error/standard_error.rb
<reponame>sonots/triglav module Triglav module Error class StandardError < ::StandardError attr_reader :code, :message def initialize(message = nil) @code = 500 @message = message || "Some error was occurred." end end end end
sonots/triglav
app/models/user.rb
class User < ApplicationRecord serialize :groups, JSON ADMIN_ROLE = 'triglav_admin' def admin? !!self.groups.try(:include?, ADMIN_ROLE) end attr_accessor :password after_destroy :invalidate_api_keys # authenticator is reserved for future extension such as LDAP authentication validates :authentica...
sonots/triglav
app/models/job_message.rb
<gh_stars>1-10 # Consumer monitors a JobMessage rather than a Message. # # JobMessage is created (fired) if AND/OR conditions are statisfied. class JobMessage < ApplicationRecord belongs_to :job validates :job_id, presence: true validates :time, presence: true, numericality: { only_integer: true } validates :ti...
sonots/triglav
spec/factories/resources.rb
<gh_stars>1-10 FactoryGirl.define do factory :resource do description "MyString" uri "hdfs://localhost/path/to/file.csv.gz" unit "daily" timezone "+09:00" span_in_days nil consumable true notifiable false end end
sonots/triglav
spec/rails_helper.rb
<filename>spec/rails_helper.rb # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!"...
sonots/triglav
spec/factories/job_messages.rb
<reponame>sonots/triglav<gh_stars>1-10 FactoryGirl.define do factory :job_message do job_id 1 time 1467298800 # "2016-07-01" in +09:00 timezone "+09:00" end end
sonots/triglav
app/serializers/resource_each_serializer.rb
class ResourceEachSerializer < ActiveModel::Serializer attributes :uri, :unit, :timezone, :span_in_days, :consumable, :notifiable include Swagger::Blocks swagger_schema :ResourceEachResponse do allOf do schema do key :'$ref', :AggregatedResourceEachResponse end schema do pr...
sonots/triglav
spec/models/api_key_spec.rb
<gh_stars>1-10 require 'rails_helper' RSpec.describe ApiKey, type: :model do describe '.create' do it do api_key = ApiKey.create!(user_id: 1) expect(api_key.access_token).to be_present expect(api_key.user_id).to be_present expect(api_key.expires_at).to be_present expect(api_key.last...
sonots/triglav
app/controllers/api/v1/apidocs_controller.rb
module Api module V1 class ApidocsController < ApplicationController SWAGGERED_CLASSES = [ self, Api::V1::AuthController, ApiKeySerializer, JobSerializer, JobEachSerializer, Api::V1::JobsController, MessageSerializer, MessageEachSerializer, ...
sonots/triglav
spec/factories/jobs.rb
<reponame>sonots/triglav FactoryGirl.define do factory :job do uri "http://localhost/path/to/job?query=parameter" logical_op "or" end factory :job_with_resources, parent: :job do after(:create) do |job| 2.times do |i| resource = create(:resource, uri: "resource://input/uri/#{i}") ...
sonots/triglav
lib/tasks/swagger.rake
<reponame>sonots/triglav<filename>lib/tasks/swagger.rake require 'tempfile' namespace :swagger do VERSION = File.read("#{Rails.root}/VERSION").chomp SWAGGER_JSON_PATH = "#{Rails.root}/tmp/swagger.json" SWAGGER_CODEGEN_CLI_PATH = "#{Rails.root}/bin/swagger-codegen-cli.jar" TRIGLAV_CLIENT_JAVA_PATH = File.expand...
sonots/triglav
spec/requests/api/v1/messages_spec.rb
<reponame>sonots/triglav # coding: utf-8 require 'rails_helper' RSpec.describe 'Message resources', :type => :request do let(:params) do {} end let(:env) do { 'CONTENT_TYPE' => 'application/json', 'HOST' => 'triglav.analytics.mbga.jp', 'HTTP_ACCEPT' => 'application/json', 'HTTP_...
sonots/triglav
spec/models/resource_spec.rb
require 'rails_helper' RSpec.describe Resource, type: :model do describe "#set_default" do context 'with daily' do let(:resource) do FactoryGirl.create(:resource, unit: 'daily') end it do expect(resource.span_in_days).to eq(32) expect(resource.timezone).to eq(Settings.r...
sonots/triglav
benchmark/send_messages.rb
require_relative 'client' require 'parallel' require 'optparse' params = ARGV.getopts('p:d:u:') num_parallels = Integer(params['p'] || 2) duration = Integer(params['d'] || 1) triglav_url = params['u'] || 'http://localhost:7800' puts "-p num_parallels: #{num_parallels} -d duration: #{duration} -u triglav_url: #{triglav...
sonots/triglav
spec/models/job_spec.rb
require 'rails_helper' RSpec.describe Job, type: :model do describe '#create_or_update_with_resources!' do context 'create a new job' do let(:params) do FactoryGirl.build(:job).attributes.except('id').merge({ 'input_resources' => [ FactoryGirl.build(:resource, uri: "resource:...
sonots/triglav
lib/tasks/release.rake
namespace :release do task :core do sh "git tag #{VERSION} || true" sh "git push origin #{VERSION}" end task :"client-java" do Dir.chdir(TRIGLAV_CLIENT_JAVA_PATH) do sh "git commit -a -m '#{VERSION}'" sh "git push origin master" end end task :"client-ruby" do Dir.chdir(TRIGLA...
sonots/triglav
app/serializers/resource_serializer.rb
class ResourceSerializer < ActiveModel::Serializer attributes :id, :description, :uri, :unit, :timezone, :span_in_days, :consumable, :notifiable, :created_at, :updated_at def self.request_params(params) params.require(:uri) params.require(:unit) params.permit(*reques...
sonots/triglav
spec/factories/messages.rb
require 'securerandom' FactoryGirl.define do factory :message do uuid SecureRandom.uuid resource_uri "hdfs://localhost/path/to/file.csv.gz" resource_unit "daily" resource_time 1467298800 # "2016-07-01" in +09:00 resource_timezone "+09:00" payload '{"foo":"bar"}' end end
sonots/triglav
spec/requests/api/v1/job_messages_spec.rb
# coding: utf-8 require 'rails_helper' RSpec.describe 'JobMessage resources', :type => :request do let(:params) do {} end let(:env) do { 'CONTENT_TYPE' => 'application/json', 'HOST' => 'triglav.analytics.mbga.jp', 'HTTP_ACCEPT' => 'application/json', 'HTTP_AUTHORIZATION' => acce...
sonots/triglav
app/serializers/user_serializer.rb
<reponame>sonots/triglav class UserSerializer < ActiveModel::Serializer attributes :id, :name, :description, :authenticator, :groups, :email, :created_at, :updated_at include Swagger::Blocks swagger_schema :UserResponse, required: [:id, :name] do property :id do key :type, :integer key :format, ...
sonots/triglav
app/controllers/api/v1/resources_controller.rb
<filename>app/controllers/api/v1/resources_controller.rb module Api module V1 class ResourcesController < ApplicationController include Swagger::Blocks # GET /aggregated_resources # GET /aggregated_resources.json swagger_path '/aggregated_resources' do operation :get do ...
sonots/triglav
app/controllers/application_controller.rb
class ApplicationController < ActionController::API before_action :set_operator after_action :set_access_log_info def set_operator RecordWithOperator.operator = current_user end def current_access_token request.env['HTTP_AUTHORIZATION'] end def current_user=(user) @current_user = user e...
sonots/triglav
app/controllers/api/v1/jobs_controller.rb
module Api module V1 class JobsController < ApplicationController include Swagger::Blocks # GET /jobs # GET /jobs.json swagger_path '/jobs' do operation :get do key :description, 'Returns all jobs' key :operationId, 'listJobs' key :tags, ['jobs'] ...
sonots/triglav
spec/models/message_spec.rb
require 'rails_helper' require 'securerandom' RSpec.describe Message, type: :model do let(:message_params) { { resource_uri: 'hdfs://foo/bar', resource_unit: 'daily', resource_time: 1356361200, resource_timezone: '+09:00', payload: '{"path":"hdfs://foo/bar","last_modification_time":...
sonots/triglav
app/serializers/api_key_serializer.rb
<gh_stars>1-10 class ApiKeySerializer < ActiveModel::Serializer attributes :access_token, :expires_at include Swagger::Blocks swagger_schema :"Credential", required: [:username, :password] do property :username do key :type, :string end property :password do key :type, :string end ...
sonots/triglav
spec/models/job_message_spec.rb
<gh_stars>1-10 require 'rails_helper' RSpec.describe JobMessage, type: :model do let(:job_message_params) { { job_id: 1, time: 1356361200, timezone: '+09:00', } } describe '#validates' do it 'valid' do expect { JobMessage.create!(job_message_params) }.not_to raise_error e...
sonots/triglav
app/controllers/api/v1/users_controller.rb
## We may not need this module Api module V1 class UsersController < ApplicationController before_action :authenticate! # before_action :admin! before_action :check_authenticator!, only: [:create, :update] include Swagger::Blocks swagger_path '/users' do operation :get do ...
sonots/triglav
spec/requests/api/v1/resources_spec.rb
# coding: utf-8 require 'rails_helper' RSpec.describe 'Resource resources', :type => :request do let(:params) do {} end let(:env) do { 'CONTENT_TYPE' => 'application/json', 'HOST' => 'triglav.analytics.mbga.jp', 'HTTP_ACCEPT' => 'application/json', 'HTTP_AUTHORIZATION' => access...
sonots/triglav
app/models/job_internal_message.rb
<reponame>sonots/triglav # Internal representation to handle AND/OR condtions # of Messesges to produce a JobMessage. # # See job_message.rb class JobInternalMessage < ApplicationRecord end
sonots/triglav
app/models/resource.rb
# frozen-string-literal: true class Resource < ApplicationRecord has_many :messages, primary_key: 'uri', foreign_key: 'resource_uri' validates :unit, inclusion: { in: %w(singular daily hourly) } # monthly, streaming support? validates :timezone, presence: true, format: { with: /\A[+-]\d\d:\d\d\z/ } before_sa...
sonots/triglav
app/serializers/job_each_serializer.rb
class JobEachSerializer < ActiveModel::Serializer attributes :id, :uri, :logical_op, :created_at, :updated_at include Swagger::Blocks swagger_schema :JobEachResponse do property :id do key :type, :integer key :format, :int64 end property :uri do key :type, :string end prope...
sonots/triglav
lib/triglav/rack/access_logger.rb
require 'time' module Triglav module Rack class AccessLogger PID = Process.pid def initialize(app, logger=nil) @app = app @logger = logger || $stdout end def call(env) began_at = Time.now.instance_eval { to_i + (usec/1000000.0) } status, headers, body = ...
sonots/triglav
app/controllers/api/v1/messages_controller.rb
<filename>app/controllers/api/v1/messages_controller.rb module Api module V1 class MessagesController < ApplicationController include Swagger::Blocks # GET /messages # GET /messages.json # # MEMO: Query can not use schema type swagger_path '/messages' do operation :get...
sonots/triglav
spec/models/user_spec.rb
<reponame>sonots/triglav require 'rails_helper' RSpec.describe User, type: :model do before(:all) { User.delete_all } describe '#authenticator=' do context 'with local' do it do expect(User.create(authenticator: 'local', password: '<PASSWORD>')).to be_valid end end context 'other...
sonots/triglav
app/models/api_key.rb
<gh_stars>1-10 require 'securerandom' class ApiKey < ApplicationRecord belongs_to :user validates :user_id, :presence => true before_create :generate_access_token before_create :extend_expiration scope :expired, -> { where('expires_at < ?', Time.current) } def expired? self.expires_at < Time.curren...
sonots/triglav
spec/requests/api/v1/users_spec.rb
<gh_stars>1-10 # coding: utf-8 require 'rails_helper' RSpec.describe 'User resources', :type => :request do let(:params) do {} end let(:env) do { 'CONTENT_TYPE' => 'application/json', 'HOST' => 'triglav.analytics.mbga.jp', 'HTTP_ACCEPT' => 'application/json', 'HTTP_AUTHORIZATION...
sonots/triglav
app/models/jobs_output_resource.rb
class JobsOutputResource < ApplicationRecord belongs_to :job belongs_to :resource end
sonots/triglav
app/controllers/api/v1/job_messages_controller.rb
<gh_stars>1-10 module Api module V1 class JobMessagesController < ApplicationController include Swagger::Blocks # GET /job_messages # GET /job_messages.json # # MEMO: Query can not use schema type swagger_path '/job_messages' do operation :get do key :descrip...
sonots/triglav
lib/rails_runner.rb
<gh_stars>1-10 # cf. http://qiita.com/sonots/items/2bf7f15adb40c012a643 APP_PATH = File.expand_path('../../config/application', __FILE__) unless defined?(APP_PATH) require_relative '../config/boot' options = { environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup } ENV["RAILS_ENV"] = options[:enviro...
sonots/triglav
spec/factories/users.rb
<filename>spec/factories/users.rb FactoryGirl.define do factory :user do sequence(:name) { |i| "user #{i}" } description { "description for #{name}"} authenticator 'local' email "<EMAIL>" groups { [] } to_create do |instance| instance.save validate: false end trait :triglav_a...
sonots/triglav
lib/triglav/error/invalid_authenticity_credential.rb
<gh_stars>1-10 module Triglav module Error class InvalidAuthenticityCredential < Triglav::Error::StandardError def initialize @code = 401 @message = 'Not authenticated. Invalid authenticity credential.' end end end end
sonots/triglav
app/models/message.rb
<reponame>sonots/triglav # Agent (or Producer) sends a Message as an event class Message < ApplicationRecord belongs_to :resource, primary_key: 'uri', foreign_key: 'resource_uri' validates :resource_uri, presence: true validates :resource_unit, presence: true, inclusion: { in: %w(singular daily hourly) } valid...
sonots/triglav
benchmark/fetch_messages.rb
<filename>benchmark/fetch_messages.rb require_relative 'client' require 'parallel' require 'optparse' params = ARGV.getopts('p:d:o:') num_parallels = Integer(params['p'] || 2) duration = Integer(params['d'] || 1) offset = Integer(params['o'] || 0) triglav_url = params['u'] || 'http://localhost:7800' puts "-p (num_para...
sonots/triglav
config/puma.rb
APP_ROOT = File.dirname(File.dirname(__FILE__)) require 'server/starter/puma_listener' listener = ::Server::Starter::PumaListener status_file = File.join(APP_ROOT, 'tmp/pids/start_server.stat') pidfile File.join(APP_ROOT, 'tmp/pids/puma.pid') state_path File.join(APP_ROOT, 'tmp/pids/puma.state') # Run puma via start...