source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | vinsol/github2s3 | https://github.com/vinsol/github2s3 | github2s3.rb | Ruby | mit | 47 | master | 3,375 | #!/usr/bin/ruby
#############################################################
# Requirements:
# ruby + aws-s3 gem + colorize gem
# git
#
# Author: Akhil Bansal (http://webonrails.com)
#############################################################
#############################################################
# C... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | graphql-connections.gemspec | Ruby | mit | 47 | master | 2,003 | # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "graphql/connections/version"
Gem::Specification.new do |spec|
spec.name = "graphql-connections"
spec.version = GraphQL::Paging::VERSION
spec.authors = ["Misha Merkushin"]
spec.... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections.rb | Ruby | mit | 47 | master | 498 | # frozen_string_literal: true
require "active_record"
require "graphql"
module GraphQL
module Connections
end
end
require "graphql/connections/stable"
require "graphql/connections/base"
require "graphql/connections/keyset/base"
require "graphql/connections/keyset/asc"
require "graphql/connections/keyset/desc"
... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/stable.rb | Ruby | mit | 47 | master | 1,147 | # frozen_string_literal: true
module GraphQL
module Connections
# Cursor-based pagination to work with `ActiveRecord::Relation`s.
# Implements a mechanism for serving stable connections based on column values.
# If objects are created or destroyed during pagination, the list of items won't be disrupted.
... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/base.rb | Ruby | mit | 47 | master | 1,280 | # frozen_string_literal: true
module GraphQL
module Connections
# Base class for pagination implementations
class Base < ::GraphQL::Pagination::Connection
attr_reader :opaque_cursor
delegate :arel_table, to: :items
def initialize(*args, opaque_cursor: true, **kwargs)
@opaque_curso... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/chewy.rb | Ruby | mit | 47 | master | 753 | # frozen_string_literal: true
module GraphQL
module Connections
class Chewy < ::GraphQL::Pagination::RelationConnection
private
def load_nodes
@nodes ||= limited_nodes.objects
end
def relation_count(relation)
offset = relation_offset(relation) || 0
limit = relati... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/keyset/base.rb | Ruby | mit | 47 | master | 1,487 | # frozen_string_literal: true
module GraphQL
module Connections
module Keyset
# Base class for keyset pagination implementations
class Base < ::GraphQL::Connections::Base
attr_reader :field_key
SEPARATOR = "/"
def initialize(*args, keys:, separator: SEPARATOR, **kwargs)
... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/keyset/desc.rb | Ruby | mit | 47 | master | 3,056 | # frozen_string_literal: true
module GraphQL
module Connections
module Keyset
# Implements keyset pagination by two fields with desc order
class Desc < ::GraphQL::Connections::Keyset::Base
def has_previous_page
if last
nodes.any? &&
items.where(arel_table[f... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/keyset/asc.rb | Ruby | mit | 47 | master | 2,822 | # frozen_string_literal: true
module GraphQL
module Connections
module Keyset
# Implements keyset pagination by two fields with asc order
class Asc < ::GraphQL::Connections::Keyset::Base
def has_previous_page
if last
nodes.any? &&
items.where(arel_table[fie... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/primary_key/asc.rb | Ruby | mit | 47 | master | 632 | # frozen_string_literal: true
module GraphQL
module Connections
# Implements pagination by one field with asc order
module PrimaryKey
class Asc < Base
PAGE_COMPARABLE_METHODS = {
previous: {query: :lt, cursor: :lteq},
next: {query: :gt, cursor: :gteq}
}
SLIC... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/primary_key/desc.rb | Ruby | mit | 47 | master | 641 | # frozen_string_literal: true
module GraphQL
module Connections
# Implements pagination by one field with desc order
module PrimaryKey
class Desc < Base
PAGE_COMPARABLE_METHODS = {
previous: {query: :gt, cursor: :gteq},
next: {query: :lt, cursor: :lteq}
}.freeze
... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | lib/graphql/connections/primary_key/base.rb | Ruby | mit | 47 | master | 3,271 | # frozen_string_literal: true
module GraphQL
module Connections
module PrimaryKey
# Base class for PrimaryKey pagination implementations
class Base < ::GraphQL::Connections::Base
COMPARABLE_METHODS = %i[
gt lt lteq gteq
].freeze
def initialize(*args, primary_key: ni... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/spec_helper.rb | Ruby | mit | 47 | master | 1,035 | # frozen_string_literal: true
require "bundler/setup"
require "graphql/connections"
require "pry-byebug"
require "combustion"
Combustion.initialize! :active_record
require "rspec/rails"
require "test_prof/recipes/rspec/before_all"
require "test_prof/recipes/rspec/let_it_be"
require "test_prof/recipes/logging"
requir... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/lib/stable_spec.rb | Ruby | mit | 47 | master | 2,334 | # frozen_string_literal: true
require "spec_helper"
describe GraphQL::Connections::Stable do
shared_examples "Key examples" do |primary_key|
context "when desc is false" do
let(:desc) { false }
it { is_expected.to be_a(GraphQL::Connections::PrimaryKey::Asc) }
it { is_expected.to have_attribu... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/lib/chewy_spec.rb | Ruby | mit | 47 | master | 6,204 | # frozen_string_literal: true
require "spec_helper"
describe GraphQL::Connections::Chewy, focus: true do
let_it_be(:msg_a) { create :message, tag: "A", username: "Bart", body: "Bart is super Bart" }
let_it_be(:msg_b) { create :message, tag: "B", username: "Bart", body: "Hello! I'm Bart!" }
let_it_be(:msg_c) { c... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/lib/keyset/asc_spec.rb | Ruby | mit | 47 | master | 5,864 | # frozen_string_literal: true
require "spec_helper"
describe GraphQL::Connections::Keyset::Asc do
let_it_be(:msg_a) { Message.create!(body: "A", created_at: Time.local(2020, 10, 2, 15)) }
let_it_be(:msg_b) { Message.create!(body: "B", created_at: Time.local(2020, 10, 2, 14)) }
let_it_be(:msg_c) { Message.create... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/lib/keyset/desc_spec.rb | Ruby | mit | 47 | master | 6,186 | # frozen_string_literal: true
require "spec_helper"
describe GraphQL::Connections::Keyset::Desc do
let_it_be(:msg_a) { Message.create!(body: "A", created_at: Time.local(2020, 10, 2, 15)) }
let_it_be(:msg_b) { Message.create!(body: "B", created_at: Time.local(2020, 10, 2, 14)) }
let_it_be(:msg_c) { Message.creat... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/lib/primary_key/desc_spec.rb | Ruby | mit | 47 | master | 7,382 | # frozen_string_literal: true
require "spec_helper"
describe GraphQL::Connections::PrimaryKey::Desc do
let_it_be(:msg_a) { Message.create!(body: "A", created_at: Time.local(2020, 10, 2, 15)) }
let_it_be(:msg_b) { Message.create!(body: "B", created_at: Time.local(2020, 10, 2, 14)) }
let_it_be(:msg_c) { Message.c... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/lib/primary_key/asc_spec.rb | Ruby | mit | 47 | master | 7,702 | # frozen_string_literal: true
require "spec_helper"
describe GraphQL::Connections::PrimaryKey::Asc do
let_it_be(:msg_a) { Message.create!(body: "A", created_at: Time.local(2020, 10, 2, 15)) }
let_it_be(:msg_b) { Message.create!(body: "B", created_at: Time.local(2020, 10, 2, 14)) }
let_it_be(:msg_c) { Message.cr... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/internal/app/indexes/messages_index.rb | Ruby | mit | 47 | master | 988 | # frozen_string_literal: true
class MessagesIndex < Chewy::Index
settings analysis: {
filter: {
autocomplete_filter: {
type: "edge_ngram",
min_gram: 2,
max_gram: 20
}
},
analyzer: {
autocomplete: {
type: "custom",
tokenizer: "standard",
fi... |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/internal/db/schema.rb | Ruby | mit | 47 | master | 275 | # frozen_string_literal: true
ActiveRecord::Schema.define do
create_table :messages do |t|
t.text :username, null: true
t.text :body, null: true
t.text :tag, null: true
t.boolean :deleted, null: false, default: false
t.timestamps null: false
end
end |
github | evilmartians/graphql-connections | https://github.com/evilmartians/graphql-connections | spec/factories/messages.rb | Ruby | mit | 47 | master | 306 | # frozen_string_literal: true
FactoryBot.define do
factory :message, class: "Message" do
sequence(:username) { |n| Faker::Internet.unique.username(specifier: 3..32, separators: %w[.]) }
body { Faker::Movies::LordOfTheRings.quote }
trait :deleted do
deleted { true }
end
end
end |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | Gemfile | Ruby | mit | 47 | master | 503 | source 'https://rubygems.org'
# Rails
gem 'rails', '~>4.2'
# Database
gem 'sqlite3'
# Required to use 'has_secure_password' in ActiveRecord
gem 'bcrypt'
# Serializers for the JSON responses
gem 'active_model_serializers'
# Used for API authorization
gem 'cancan'
group :test do
# Rspec
gem 'rspec-rails', '~> 3.... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/spec_helper.rb | Ruby | mit | 47 | master | 2,566 | # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdir... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/routing/api/v1/sessions_routing_spec.rb | Ruby | mit | 47 | master | 437 | require 'spec_helper'
describe 'routes for Sessions' do
it 'routes post /api/sessions to sessions#create' do
expect({:post => '/api/sessions'}).to route_to(:controller => 'api/v1/sessions', :action => 'create', :format => :json)
end
it 'routes delete /api/sessions to sessions#destroy' do
expect({:delete... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/routing/api/v1/cat_entries_routing_spec.rb | Ruby | mit | 47 | master | 1,092 | require 'spec_helper'
describe 'routes for Cat entries' do
it 'routes /api/cat_entries to cat_entries#index' do
expect({:get => '/api/cat_entries'}).to route_to(:controller => 'api/v1/cat_entries', :action => 'index', :format => :json)
end
it 'routes /api/cat_entries/:id to cat_entries#show' do
expect({... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/routing/api/v1/users_routing_spec.rb | Ruby | mit | 47 | master | 800 | require 'spec_helper'
describe 'routes for Users' do
it 'routes /api/users/:id to users#show' do
expect({:get => '/api/users/1'}).to route_to(:controller => 'api/v1/users', :action => 'show', :id => '1', :format => :json)
end
it 'routes post /api/users to users#create' do
expect({:post => '/api/users'})... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/factories/users.rb | Ruby | mit | 47 | master | 294 | FactoryGirl.define do
factory :user do
email 'test@lofocat.dev'
password '12345678'
password_confirmation '12345678'
end
factory :admin_user, :class => User do
email 'admin@lofocat.dev'
password '12345678'
password_confirmation '12345678'
admin true
end
end |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/factories/cat_entries.rb | Ruby | mit | 47 | master | 441 | FactoryGirl.define do
factory :cat_entry do
user { FactoryGirl.build(:user) }
breed 'Persian'
color 'Grey'
longitude 13.222444
latitude 34.234123
contact_phone '0031123456789'
contact_email 'found_a_cat@lofocats.com'
event_date { Date.new(2015,9,26) }
entry_type 'lost'
photo_ur... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/controllers/application_controller_spec.rb | Ruby | mit | 47 | master | 1,559 | require 'spec_helper'
describe ApplicationController do
controller do
def index
raise CanCan::AccessDenied
end
end
describe 'Handling of CanCan Access denied exceptions' do
before do
get :index
end
it { should respond_with 401 }
end
describe '#current_user' do
let(:user... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/controllers/api/v1/users_controller_spec.rb | Ruby | mit | 47 | master | 4,404 | require 'spec_helper'
describe Api::V1::UsersController do
describe "GET #index" do
before do
FactoryGirl.create(:user)
FactoryGirl.create(:admin_user)
expect(controller).to receive(:authorize!).with(:read_all, User)
get :index
end
it { should respond_with 200 }
... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/controllers/api/v1/sessions_controller_spec.rb | Ruby | mit | 47 | master | 1,929 | require 'spec_helper'
describe Api::V1::SessionsController do
describe "POST '/api/sessions'" do
let(:user) { FactoryGirl.create :user }
before do
expect(controller).to receive(:authorize!).with(:create, :session)
post :create, { :session => credentials }
end
context 'without session p... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/controllers/api/v1/cat_entries_controller_spec.rb | Ruby | mit | 47 | master | 3,990 | require 'spec_helper'
describe Api::V1::CatEntriesController do
describe "GET #index" do
before do
3.times do |i|
FactoryGirl.create(:cat_entry, :breed => "Breed #{i}", :user => FactoryGirl.create(:user,
:email => "user#{i}@lofocats.com"))
end
2.times do |i|
FactoryGir... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/lib/api_constraints_spec.rb | Ruby | mit | 47 | master | 681 | require 'spec_helper'
describe ApiConstraints do
let(:api_constraints_v1) { ApiConstraints.new(version: 1) }
let(:api_constraints_v2) { ApiConstraints.new(version: 2, default: true) }
describe "matches?" do
it "returns true when the version matches the 'Accept' header" do
request = double(host: 'lofo... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/models/user_spec.rb | Ruby | mit | 47 | master | 990 | require 'spec_helper'
describe User do
# Attributes
it { should respond_to :email, :email= }
it { should respond_to :password, :password= }
it { should respond_to :password_confirmation, :password_confirmation= }
it { should respond_to :password_digest, :password_digest= }
it { should respond_to :admin, :... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/models/ability_spec.rb | Ruby | mit | 47 | master | 3,563 | require 'spec_helper'
require 'cancan/matchers'
describe Ability do
let(:user) { nil }
subject { Ability.new(user) }
context 'administrator' do
let(:user) { FactoryGirl.build(:admin_user) }
it 'should be able to manage the whole universe' do
expect(subject.can?(:manage, :all)).to be true
end... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/models/cat_entry_spec.rb | Ruby | mit | 47 | master | 2,238 | require 'spec_helper'
describe CatEntry do
subject { FactoryGirl.build(:cat_entry) }
it { should respond_to :user, :user= }
it { should respond_to :breed, :breed= }
it { should respond_to :color, :color= }
it { should respond_to :longitude, :longitude= }
it { should respond_to :latitude, :latitude= }
it... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/models/authentication_token_spec.rb | Ruby | mit | 47 | master | 661 | require 'spec_helper'
describe AuthenticationToken do
subject { FactoryGirl.create(:authentication_token) }
### Attributes ###
it { should respond_to :user, :user= }
it { should respond_to :token, :token= }
it { should respond_to :expires_at, :expires_at= }
### Validations ###
it { should be_valid }
... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/serializers/cat_entry_serializer_spec.rb | Ruby | mit | 47 | master | 630 | require 'spec_helper'
describe CatEntrySerializer do
let(:cat_entry) { FactoryGirl.create(:cat_entry, :user => FactoryGirl.create(:user)) }
subject { CatEntrySerializer.new(cat_entry).to_json }
it 'should serialize the correct attributes' do
expect(subject).to eq '{"id":1,"breed":"Persian","color":"Grey","... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/serializers/user_session_serializer_spec.rb | Ruby | mit | 47 | master | 584 | require 'spec_helper'
describe UserSessionSerializer do
let(:user) { FactoryGirl.build(:user, :id => 1) }
let(:authentication_token) { FactoryGirl.build(:authentication_token, :user => user) }
let(:session_information) { {:user => user, :authentication_token => authentication_token} }
subject { UserSessionSer... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/serializers/user_serializer_spec.rb | Ruby | mit | 47 | master | 279 | require 'spec_helper'
describe UserSerializer do
let(:user) { FactoryGirl.create(:user) }
subject { UserSerializer.new(user).to_json }
it 'should serialize the correct attributes' do
expect(subject).to eq '{"id":1,"email":"test@lofocat.dev","admin":null}'
end
end |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | spec/serializers/authentication_token_serializer_spec.rb | Ruby | mit | 47 | master | 357 | require 'spec_helper'
describe AuthenticationTokenSerializer do
let(:authentication_token) { FactoryGirl.build(:authentication_token) }
subject { AuthenticationTokenSerializer.new(authentication_token).to_json }
it 'should serialize the correct attributes' do
expect(subject).to eq '{"token":"ABCD-EFAAA-ABC... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | lib/api_constraints.rb | Ruby | mit | 47 | master | 389 | # Simple constraint to match the desired API version in the routes
class ApiConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
end
# Resolve if the given request matches this version or reached the default version
def matches?(req)
@default || req.headers[... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | lib/validators/email_validator.rb | Ruby | mit | 47 | master | 338 | # A simple email validator (regex is not mine :), retrieved by Rails documentation)
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || "is not an email")... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | lib/tasks/db.rake | Ruby | mit | 47 | master | 3,826 | namespace :db do
desc 'Loads demo data to the db'
task :load_demo_data => :environment do
administrator = User.create(:email => 'administrator@lofocats.com', :password => 'administrator', :password_confirmation => 'administrator', :admin => true)
user = User.create(:email => 'user@lofocats.com', :password =... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/serializers/user_session_serializer.rb | Ruby | mit | 47 | master | 476 | # Serialized attributes for a Session consisting of the user & authentication token
class UserSessionSerializer < ActiveModel::Serializer
# The signed in user
has_one :user
# The created authentication token
has_one :authentication_token
# Extracts the user from the given object (hash)
def user
obj... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/serializers/cat_entry_serializer.rb | Ruby | mit | 47 | master | 285 | class CatEntrySerializer < ActiveModel::Serializer
# Serialized attirbutes for the Cat entry
attributes :id, :breed, :color, :longitude, :latitude, :contact_phone, :contact_email, :event_date, :entry_type, :resolved, :chip, :photo_url
# Include user as well
has_one :user
end |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/models/authentication_token.rb | Ruby | mit | 47 | master | 798 | class AuthenticationToken < ActiveRecord::Base
### Relations ###
# The user for this authentication token
belongs_to :user, :inverse_of => :authentication_tokens
### Hooks ###
# Set expiration upon save
before_save :set_expiration
### Validations ###
validates :user, :presence => true
validates :t... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/models/ability.rb | Ruby | mit | 47 | master | 555 | class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.admin?
# Admin
can :manage, :all
elsif user.id.present?
# Normal user
can :destroy, :session
can :read, CatEntry
can :create, CatEntry
can :update, CatEntry, :user_id => user... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/models/cat_entry.rb | Ruby | mit | 47 | master | 1,057 | class CatEntry < ActiveRecord::Base
### Relations ###
belongs_to :user, :inverse_of => :cat_entries
### Validations ###
validates :user, :presence => true
validates :breed, :presence => true, :length => { :maximum => 128 }
validates :color, :presence => true, :length => { :maximum => 48 }
validates :long... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/models/user.rb | Ruby | mit | 47 | master | 729 | class User < ActiveRecord::Base
### Relations ###
# Enable Rails' functionality for password management
has_secure_password
has_many :authentication_tokens, :inverse_of => :user, :dependent => :destroy
has_many :cat_entries, :inverse_of => :user, :dependent => :destroy
### Validations ###
validates :em... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/controllers/application_controller.rb | Ruby | mit | 47 | master | 771 | class ApplicationController < ActionController::Base
# CSRF handling for APIS (instead of raising exceptions)
protect_from_forgery :with => :null_session
# Whenever an AccessDenied is raised based on the current ability, respond with 401
rescue_from CanCan::AccessDenied do |exception|
head 401
end
# R... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/controllers/api/v1/sessions_controller.rb | Ruby | mit | 47 | master | 1,062 | class Api::V1::SessionsController < ApplicationController
# POST '/api/sessions'
def create
authorize! :create, :session
# Fail with missing params
handle_authentication_failure and return unless params[:session].present?
email = params[:session][:email]
password = params[:session][:passwor... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/controllers/api/v1/cat_entries_controller.rb | Ruby | mit | 47 | master | 2,038 | class Api::V1::CatEntriesController < ApplicationController
# Load the cat entry with the given id
before_filter :load_cat_entry, :only => [:show, :update, :destroy]
# GET '/api/cat_entries'
def index
authorize! :read, CatEntry
@cat_entries = CatEntry.all
render :json => @cat_entries
end
# G... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | app/controllers/api/v1/users_controller.rb | Ruby | mit | 47 | master | 1,437 | class Api::V1::UsersController < ApplicationController
# Load the user based on the id parameter
before_filter :load_user, :only => [:show, :update, :destroy]
# GET '/api/users'
def index
authorize! :read_all, User
render :json => User.all
end
# GET '/api/users/:id'
def show
authorize! :... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | config/routes.rb | Ruby | mit | 47 | master | 514 | Rails.application.routes.draw do
namespace :api, :defaults => { :format => :json } do
# Serve and default to v1 version of the API
scope :module => :v1, :constraints => ApiConstraints.new(version: 1, default: true) do
# Users
resources :users, :only => [:index, :show, :create, :update, :destroy]
... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | config/application.rb | Ruby | mit | 47 | master | 515 | require File.expand_path('../boot', __FILE__)
require "rails"
require "active_model/railtie"
#require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
#require "action_mailer/railtie"
#require "action_view/railtie"
Bundler.require(*Rails.groups)
module LofoCatsApi
class App... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | config/environments/test.rb | Ruby | mit | 47 | master | 1,541 | 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 suit... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | config/environments/development.rb | Ruby | mit | 47 | master | 1,505 | 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 serv... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | db/schema.rb | Ruby | mit | 47 | master | 2,348 | # 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 sou... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | db/migrate/20150920101142_create_users.rb | Ruby | mit | 47 | master | 324 | class CreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
t.string :email, :null => false, default: ""
t.string :password_digest, :null => false, default: ""
t.boolean :admin
t.timestamps
end
add_index :users, :email, unique: true
end
... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | db/migrate/20150920182059_create_authentication_tokens.rb | Ruby | mit | 47 | master | 453 | class CreateAuthenticationTokens < ActiveRecord::Migration
def change
create_table :authentication_tokens do |t|
t.integer :user_id, :null => false
t.string :token, :null => false
t.datetime :expires_at, :null => false
t.timestamps null: false
end
add_index :authentication_tokens... |
github | iridakos/lofocats_api | https://github.com/iridakos/lofocats_api | db/migrate/20150920192224_create_cat_entries.rb | Ruby | mit | 47 | master | 802 | class CreateCatEntries < ActiveRecord::Migration
def change
create_table :cat_entries do |t|
t.integer :user_id, :null => false
t.string :breed, :null => false
t.string :color, :null => false
t.string :longitude, :null => false
t.string :latitude, :null => false
t.string :conta... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | active_record_compose.gemspec | Ruby | mit | 47 | main | 1,807 | # frozen_string_literal: true
require_relative "lib/active_record_compose/version"
Gem::Specification.new do |spec|
spec.name = "active_record_compose"
spec.version = ActiveRecordCompose::VERSION
spec.authors = [ "hamajyotan" ]
spec.email = [ "hamajyotan@gmail.com" ]
spec.description = "activemodel form ob... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | Rakefile | Ruby | mit | 47 | main | 264 | # frozen_string_literal: true
require 'bundler/gem_tasks'
require 'minitest/test_task'
Minitest::TestTask.create
require 'rubocop/rake_task'
RuboCop::RakeTask.new
task :typecheck do
sh 'bundle exec steep check'
end
task default: %i[test rubocop typecheck] |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | Gemfile | Ruby | mit | 47 | main | 1,222 | # frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in active_record_compose.gemspec
gemspec
ar_version = ENV.fetch("AR", "latest")
case ar_version
when "latest"
gem "activerecord"
gem "railties"
when "head"
gem "activemodel", github: "rails/rails"
gem "activerecord... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose.rb | Ruby | mit | 47 | main | 425 | # frozen_string_literal: true
require "active_record"
require_relative "active_record_compose/version"
require_relative "active_record_compose/exceptions"
require_relative "active_record_compose/model"
# namespaces in gem `active_record_compose`.
#
# Most of the functionality resides in {ActiveRecordCompose::Model}.... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/inspectable.rb | Ruby | mit | 47 | main | 4,778 | # frozen_string_literal: true
require "active_support/parameter_filter"
require_relative "attributes"
module ActiveRecordCompose
# It provides #inspect behavior.
# It tries to replicate the inspect format provided by ActiveRecord as closely as possible.
#
# @example
# class Model < ActiveRecordCompose::Mo... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/persistence.rb | Ruby | mit | 47 | main | 4,282 | # frozen_string_literal: true
require_relative "callbacks"
require_relative "composed_collection"
module ActiveRecordCompose
using ComposedCollection::PackagePrivate
module Persistence
extend ActiveSupport::Concern
include ActiveRecordCompose::Callbacks
# Save the models that exist in models.
# ... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/transaction_support.rb | Ruby | mit | 47 | main | 4,611 | # frozen_string_literal: true
require "active_support/core_ext/module"
module ActiveRecordCompose
module TransactionSupport
extend ActiveSupport::Concern
included do
define_callbacks :commit, :rollback, :before_commit, scope: [ :kind, :name ]
end
# steep:ignore:start
class_methods do
... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/composed_collection.rb | Ruby | mit | 47 | main | 3,911 | # frozen_string_literal: true
require_relative "wrapped_model"
module ActiveRecordCompose
using WrappedModel::PackagePrivate
# Object obtained by {ActiveRecordCompose::Model#models}.
#
# It functions as a collection that contains the object to be saved.
class ComposedCollection
include Enumerable
... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/wrapped_model.rb | Ruby | mit | 47 | main | 4,367 | # frozen_string_literal: true
require "active_support/core_ext/object"
module ActiveRecordCompose
# @private
class WrappedModel
# @param model [Object] the model instance.
# @param destroy [Boolean, Proc, Symbol] Controls whether the model should be destroyed.
# - Boolean: if `true`, the model will ... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/callbacks.rb | Ruby | mit | 47 | main | 2,517 | # frozen_string_literal: true
module ActiveRecordCompose
# Provides hooks into the life cycle of an ActiveRecordCompose model,
# allowing you to insert custom logic before or after changes to the object's state.
#
# The callback flow generally follows the same structure as Active Record:
#
# * `before_vali... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/exceptions.rb | Ruby | mit | 47 | main | 1,386 | # frozen_string_literal: true
module ActiveRecordCompose
# Occurs when a circular reference is detected in the containing model.
#
# @example
# class Model < ActiveRecordCompose::Model
# def initialize
# super()
# models << self # Adding itself to models creates a circular refe... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/attributes.rb | Ruby | mit | 47 | main | 6,357 | # frozen_string_literal: true
require_relative "attributes/attribute_predicate"
require_relative "attributes/delegation"
require_relative "attributes/querying"
require_relative "exceptions"
module ActiveRecordCompose
# Provides attribute-related functionality for use within ActiveRecordCompose::Model.
#
# This ... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/railtie.rb | Ruby | mit | 47 | main | 451 | # frozen_string_literal: true
require "rails"
require "active_record_compose"
require "active_record/railtie"
module ActiveRecordCompose
class Railtie < Rails::Railtie
initializer "active_record_compose.set_filter_attributes", after: "active_record.set_filter_attributes" do
ActiveSupport.on_load(:active_r... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/validations.rb | Ruby | mit | 47 | main | 3,990 | # frozen_string_literal: true
require_relative "composed_collection"
require_relative "exceptions"
module ActiveRecordCompose
using ComposedCollection::PackagePrivate
module Validations
extend ActiveSupport::Concern
include ActiveModel::Validations::Callbacks
included do
validate :validate_mod... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/model.rb | Ruby | mit | 47 | main | 4,672 | # frozen_string_literal: true
require_relative "attributes"
require_relative "composed_collection"
require_relative "inspectable"
require_relative "persistence"
require_relative "transaction_support"
require_relative "validations"
module ActiveRecordCompose
# This is the core class of {ActiveRecordCompose}.
#
#... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/attributes/delegation.rb | Ruby | mit | 47 | main | 1,097 | # frozen_string_literal: true
require_relative "attribute_predicate"
module ActiveRecordCompose
module Attributes
# @private
class Delegation
# @return [Symbol] The attribute name as symbol
attr_reader :attribute
def initialize(attribute:, to:, allow_nil: false)
@attribute = attri... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/attributes/attribute_predicate.rb | Ruby | mit | 47 | main | 495 | # frozen_string_literal: true
module ActiveRecordCompose
module Attributes
# @private
class AttributePredicate
def initialize(value)
@value = value
end
def call
case value
when true then true
when false, nil then false
else
if value.respond... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | lib/active_record_compose/attributes/querying.rb | Ruby | mit | 47 | main | 1,714 | # frozen_string_literal: true
require_relative "attribute_predicate"
module ActiveRecordCompose
module Attributes
# @private
# This provides predicate methods based on the attributes.
#
# @example
# class AccountRegistration < ActiveRecordCompose::Model
# def initialize
# @ac... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose_test.rb | Ruby | mit | 47 | main | 205 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordComposeTest < ActiveSupport::TestCase
test "that it has a version number" do
assert { ActiveRecordCompose::VERSION }
end
end |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/test_helper.rb | Ruby | mit | 47 | main | 530 | # frozen_string_literal: true
require "minitest/reporters"
Minitest::Reporters.use!
require "minitest/power_assert"
require "debug"
require "i18n"
I18n.load_path += Dir[File.join(__dir__, "config/locales/*.yml")]
# Since Rails 7.1, test_case implicitly depends on deprecator.
require "active_support/deprecator"
re... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/support/model.rb | Ruby | mit | 47 | main | 806 | # frozen_string_literal: true
require "test/support/schema"
class Account < ApplicationRecord
has_one :profile
has_one :credential
validates :name, presence: true
validates :email, presence: true
validates :email, format: { with: /\.edu\z/ }, on: :education
end
class Profile < ApplicationRecord
belongs_t... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/support/schema.rb | Ruby | mit | 47 | main | 965 | # frozen_string_literal: true
require "test/support/configuration"
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
connects_to database: { writing: :primary }
end
ApplicationRecord.connection_pool.with_connection do |conn|
conn.create_table :accounts, force: true do |t|
t.string :name, ... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_callback_abort_test.rb | Ruby | mit | 47 | main | 1,284 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelCallbackAbortTest < ActiveSupport::TestCase
class CallbackWithAbort < ActiveRecordCompose::Model
def initialize(account = Account.new)
@account = account
super()
models << account
end
attribute :throw_... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_uniquify_save_test.rb | Ruby | mit | 47 | main | 3,820 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelUniquifySaveTest < ActiveSupport::TestCase
class Inner
include ActiveModel::Model
include ActiveModel::Validations::Callbacks
include ActiveModel::Attributes
define_model_callbacks :save
define_model_callbacks :... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_twice_validation_test.rb | Ruby | mit | 47 | main | 985 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelTwiceValidationTest < ActiveSupport::TestCase
class FailureOnTwiceValidation < ActiveRecordCompose::Model
def initialize(model = nil)
super()
models.push(model)
@validation_count = 0
end
before_validat... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/wrapped_model_test.rb | Ruby | mit | 47 | main | 2,165 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::WrappedModelTest < ActiveSupport::TestCase
test "returns true if and only if model is equivalent" do
account = Account.new
profile = Profile.new
wrapped_model = ActiveRecordCompose::WrappedModel.new(account)
assert { wra... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_context_test.rb | Ruby | mit | 47 | main | 3,555 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelContextTest < ActiveSupport::TestCase
class ComposedModel < ActiveRecordCompose::Model
def initialize(attributes)
@account = Account.new
@profile = account.then { _1.profile || _1.build_profile }
super
mo... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_lint_test.rb | Ruby | mit | 47 | main | 622 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelLintTest < ActiveSupport::TestCase
include ActiveModel::Lint::Tests
class ComposedModel < ActiveRecordCompose::Model
def initialize(account = Account.new)
@account = account
@profile = account.then { _1.profile ||... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/circular_reference_detection_test.rb | Ruby | mit | 47 | main | 1,023 | # frozen_string_literal: true
require "test_helper"
class CircularReferenceDetectionTest < ActiveSupport::TestCase
test "cannot add self to models" do
m1 = klass.new
m1.model = m1
assert_raises(ActiveRecordCompose::CircularReferenceDetected) do
assert { m1.save }
end
end
test "there must... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_with_if_option_test.rb | Ruby | mit | 47 | main | 1,128 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelWithIfOptionTest < ActiveSupport::TestCase
class ComposedModelWithOperationLog < ActiveRecordCompose::Model
def initialize(attributes = {})
@account = Account.new(name: "foobar", email: "foobar@example.com")
@operati... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_attribute_query_test.rb | Ruby | mit | 47 | main | 2,811 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelAttributeQueryTest < ActiveSupport::TestCase
class ComposedModel < ActiveRecordCompose::Model
def initialize(attributes = {})
@account = Account.new
@profile = account.build_profile
super(attributes)
mode... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_nested_test.rb | Ruby | mit | 47 | main | 1,340 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelNestedTest < ActiveSupport::TestCase
class InnerComposedModel < ActiveRecordCompose::Model
def initialize
@account = Account.new
super()
models << account
end
validates :name, length: { maximum: 10 }
... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_inspect_test.rb | Ruby | mit | 47 | main | 5,942 | # frozen_string_literal: true
require "pp"
require "stringio"
require "test_helper"
require "active_support/core_ext/time"
class ActiveRecordCompose::ModelInspectTest < ActiveSupport::TestCase
test "returns an ActiveRecord model-like #inspect" do
klass =
Class.new(ActiveRecordCompose::Model) do
de... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/railtie_test.rb | Ruby | mit | 47 | main | 591 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::RailtieTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
test "The filter_parameters settings in the rails application are reflected in the filter_attributes" do
require "fake_app/application"
assert_ch... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/composed_collection_test.rb | Ruby | mit | 47 | main | 1,468 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ComposedCollectionTest < ActiveSupport::TestCase
test "#empty should return true if the element is absent and false if the element is present" do
collection = ActiveRecordCompose::ComposedCollection.new(nil)
assert { collection.... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/model_attribute_test.rb | Ruby | mit | 47 | main | 1,889 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::ModelAttributeTest < ActiveSupport::TestCase
test "If you don't call super in initialize, the attributes won't be accessible because they won't be initialized." do
klass =
Class.new(ActiveRecordCompose::Model) do
def in... |
github | hamajyotan/active_record_compose | https://github.com/hamajyotan/active_record_compose | test/active_record_compose/delegate_attribute_test.rb | Ruby | mit | 47 | main | 2,377 | # frozen_string_literal: true
require "test_helper"
class ActiveRecordCompose::DelegateAttributeTest < ActiveSupport::TestCase
class Inner
include ActiveModel::Model
include ActiveModel::Attributes
attribute :x
attribute :y
attribute :z
end
class Dummy
include ActiveRecordCompose::Attr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.