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 | eki-177/abyme | https://github.com/eki-177/abyme | spec/generators/abyme/view_generator_spec.rb | Ruby | mit | 87 | master | 1,790 | require "rails_helper"
require "generators/abyme/view/view_generator"
RSpec.describe Abyme::Generators::ViewGenerator, type: :generator do
destination File.expand_path("../../dummy/", __dir__)
context "with no arguments or when SimpleForm is not defined" do
before(:all) do
run_generator %w[test]
end... |
github | eki-177/abyme | https://github.com/eki-177/abyme | spec/system/abyme_options_spec.rb | Ruby | mit | 87 | master | 5,527 | require "rails_helper"
require_relative "../support/helpers/add_nested_attributes"
RSpec.describe "Helper options", type: :system do
before do
driven_by :selenium_chrome_headless
end
context "For new resources" do
describe "Partials default & custom path" do
it "should set the correct partial when... |
github | eki-177/abyme | https://github.com/eki-177/abyme | spec/system/nested_attributes_spec.rb | Ruby | mit | 87 | master | 3,489 | require "rails_helper"
require_relative "../support/helpers/add_nested_attributes"
RSpec.describe "Nested attributes behaviour", type: :system do
before do
driven_by :selenium_chrome_headless
end
let(:description) { "La mise en abyme — également orthographiée mise en abysme ou plus rarement mise en abîme1 —... |
github | eki-177/abyme | https://github.com/eki-177/abyme | spec/support/helpers/add_nested_attributes.rb | Ruby | mit | 87 | master | 1,438 | def add_tasks(number = 2)
number.times { find_by_id("add-task").click }
titles = find_all_by_id('input', /project_tasks_attributes_\d*_title/)
descriptions = find_all_by_id('textarea', /project_tasks_attributes_\d*_description/ )
titles.each_with_index {|title, n| title.fill_in(with: "Task #{n + 1}") }
descri... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | Rakefile | Ruby | mit | 87 | master | 798 | require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: ['dummy:prepare', :spec]
require 'rake/clean'
CLEAN.include 'spec/dummy/db/*sqlite3', 'spec/dummy/log/*', 'spec/dummy/public/assets/*', 'spec/dummy/tmp/**/*'
namespace :dummy do
desc 'Setup dummy app database... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | activeadmin-ajax_filter.gemspec | Ruby | mit | 87 | master | 2,176 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'active_admin/ajax_filter/version'
Gem::Specification.new do |gem|
gem.name = 'activeadmin-ajax_filter'
gem.version = ActiveAdmin::AjaxFilter::VERSION
gem.authors = ['Al... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/spec_helper.rb | Ruby | mit | 87 | master | 4,623 | # This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# file... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/rails_helper.rb | Ruby | mit | 87 | master | 1,919 | # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../dummy/config/environment', __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'phantomjs/poltergeist'
require 'database_cleaner'
Capybara.javascript_... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/active_admin/inputs/ajax_core_spec.rb | Ruby | mit | 87 | master | 5,797 | require 'active_admin/inputs/ajax_core'
RSpec.describe ActiveAdmin::Inputs::AjaxCore do
before(:each) do
Temping.create(:record) do
with_columns do |t|
t.string :name
t.string :email
end
end
end
class StubFilter < ActiveAdmin::Inputs::Filters::SelectInput
include ActiveAd... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/features/ajax_form_input_spec.rb | Ruby | mit | 87 | master | 2,218 | RSpec.describe ActiveAdmin::Inputs::AjaxSelectInput, type: :feature, js: true do
let!(:subcategories) { create_list(:subcategory, Subcategory::AJAX_LIMIT + 1) }
let(:subcategory) { subcategories.last }
context 'items' do
let(:selectize_selector) { '#item_subcategory_input' }
describe 'new item creation'... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/app/admin/dashboard.rb | Ruby | mit | 87 | master | 908 | ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
content title: proc { I18n.t('active_admin.dashboard') } do
div class: 'blank_slate_container', id: 'dashboard_default_message' do
span class: 'blank_slate' do
span I18n.t('active_admin.das... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/app/admin/subcategories.rb | Ruby | mit | 87 | master | 210 | ActiveAdmin.register Subcategory do
include ActiveAdmin::AjaxFilter
decorate_with SubcategoryDecorator.name
permit_params :id, :name, :category_id
config.sort_order = 'id_asc'
config.per_page = 3
end |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/app/admin/items.rb | Ruby | mit | 87 | master | 560 | ActiveAdmin.register Item do
permit_params :id, :name, :subcategory_id, tag_ids: []
config.sort_order = 'id_asc'
form do |f|
f.semantic_errors(*f.object.errors.attribute_names)
f.inputs do
f.input :name
f.input :subcategory, as: :ajax_select, data: {
search_fields: [:name],
... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/app/admin/tags.rb | Ruby | mit | 87 | master | 496 | ActiveAdmin.register Tag do
include ActiveAdmin::AjaxFilter
permit_params :id, :name, :subcategory_id
config.sort_order = 'id_asc'
form do |f|
f.semantic_errors(*f.object.errors.attribute_names)
f.inputs do
f.input :name
f.input :subcategory, as: :ajax_select, data: {
search_field... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/db/schema.rb | Ruby | mit | 87 | master | 2,396 | # 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
# dat... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/db/migrate/20150910072150_create_active_admin_comments.rb | Ruby | mit | 87 | master | 579 | class CreateActiveAdminComments < ActiveRecord::Migration
def self.up
create_table :active_admin_comments do |t|
t.string :namespace
t.text :body
t.string :resource_id, null: false
t.string :resource_type, null: false
t.references :author, polymorphic: true
t.timestamps
e... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/db/migrate/20150910072505_initial_schema.rb | Ruby | mit | 87 | master | 416 | class InitialSchema < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :name, null: false
end
create_table :subcategories do |t|
t.string :name, null: false
t.references :category, null: false, index: true
end
create_table :items do |t|
t.string... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/db/migrate/20200418135023_create_tags.rb | Ruby | mit | 87 | master | 321 | class CreateTags < ActiveRecord::Migration[5.2]
def change
create_table :tags do |t|
t.string :name, null: false
t.references :subcategory, null: false, index: true
end
create_join_table :items, :tags do |t|
t.index [:item_id, :tag_id]
t.index [:tag_id, :item_id]
end
end
end |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/config/application.rb | Ruby | mit | 87 | master | 702 | require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails ver... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/config/environments/production.rb | Ruby | mit | 87 | master | 3,893 | require "active_support/core_ext/integer/time"
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 applica... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/config/environments/development.rb | Ruby | mit | 87 | master | 2,412 | require "active_support/core_ext/integer/time"
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 any time
# it changes. This slows down response time but is perfect for developme... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/dummy/config/initializers/active_admin.rb | Ruby | mit | 87 | master | 8,426 | ActiveAdmin.setup do |config|
# == Site Title
#
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = 'Dummy'
# Set the link url for the title. For example, to take
# users to your main site. Defaults to no link.
#
# config.site_title_link ... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/support/selectize_helpers.rb | Ruby | mit | 87 | master | 1,452 | module SelectizeHelpers
# Input text to selectize field
def fill_in_selectize(text, selector = selectize_selector)
find("#{selector} .selectize-input input").native.send_keys(text)
wait_for_ajax
end
# Get current selectize items
def selectize_items_in_dropdown(selector = selectize_selector)
# Wai... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | spec/support/wait_for_ajax.rb | Ruby | mit | 87 | master | 650 | module WaitForAjax
def wait_for_ajax(count = 1)
page.execute_script 'window._ajaxCalls = 0, window._ajaxCompleteCounter = function() { window._ajaxCalls += 1; }'
page.execute_script '$(document).on("ajaxComplete", window._ajaxCompleteCounter)'
Timeout.timeout(Capybara.default_max_wait_time) do
loop... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/Gemfile | Ruby | mit | 87 | master | 2,622 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.2.3"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.8", ">= 7.0.4.3"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "spro... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/db/schema.rb | Ruby | mit | 87 | master | 2,884 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/db/seeds.rb | Ruby | mit | 87 | master | 1,214 | require 'faker'
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of ... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/db/migrate/20230425060437_devise_create_admin_users.rb | Ruby | mit | 87 | master | 1,436 | # frozen_string_literal: true
class DeviseCreateAdminUsers < ActiveRecord::Migration[7.0]
def change
create_table :admin_users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/db/migrate/20230425060439_create_active_admin_comments.rb | Ruby | mit | 87 | master | 414 | class CreateActiveAdminComments < ActiveRecord::Migration[7.0]
def self.up
create_table :active_admin_comments do |t|
t.string :namespace
t.text :body
t.references :resource, polymorphic: true
t.references :author, polymorphic: true
t.timestamps
end
add_index :active_admin_... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/db/migrate/20230425060707_initial_schema.rb | Ruby | mit | 87 | master | 421 | class InitialSchema < ActiveRecord::Migration[7.0]
def change
create_table :categories do |t|
t.string :name, null: false
end
create_table :subcategories do |t|
t.string :name, null: false
t.references :category, null: false, index: true
end
create_table :items do |t|
t.s... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/db/migrate/20230425060708_create_tags.rb | Ruby | mit | 87 | master | 321 | class CreateTags < ActiveRecord::Migration[7.0]
def change
create_table :tags do |t|
t.string :name, null: false
t.references :subcategory, null: false, index: true
end
create_join_table :items, :tags do |t|
t.index [:item_id, :tag_id]
t.index [:tag_id, :item_id]
end
end
end |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/app/admin/subcategories.rb | Ruby | mit | 87 | master | 431 | ActiveAdmin.register Subcategory do
include ActiveAdmin::AjaxFilter
decorate_with SubcategoryDecorator.name
permit_params :id, :name, :category_id
config.sort_order = 'id_asc'
config.per_page = 3
show do |subcategory|
panel 'Async panel', class: 'async-panel', 'data-url' => panel_admin_subcategory_pat... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/app/admin/admin_users.rb | Ruby | mit | 87 | master | 493 | ActiveAdmin.register AdminUser do
permit_params :email, :password, :password_confirmation
index do
selectable_column
id_column
column :email
column :current_sign_in_at
column :sign_in_count
column :created_at
actions
end
filter :email
filter :current_sign_in_at
filter :sign_in_... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/app/admin/items.rb | Ruby | mit | 87 | master | 822 | ActiveAdmin.register Item do
permit_params :id, :name, :subcategory_id, tag_ids: []
config.sort_order = 'id_asc'
filter :subcategory, as: :ajax_select, data: {
url: :filter_admin_subcategories_path,
search_fields: [:name],
limit: 7,
}
filter :tags, as: :ajax_select, data: {
url: :filter_admi... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/app/models/admin_user.rb | Ruby | mit | 87 | master | 258 | class AdminUser < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
end |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/config/routes.rb | Ruby | mit | 87 | master | 277 | Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
end |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/config/application.rb | Ruby | mit | 87 | master | 701 | require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Blog
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails vers... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/config/environments/production.rb | Ruby | mit | 87 | master | 3,890 | require "active_support/core_ext/integer/time"
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 applica... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/config/initializers/devise.rb | Ruby | mit | 87 | master | 15,473 | # frozen_string_literal: true
# Assuming you have not yet modified this file, each configuration option below
# is set to its default value. Note that some are commented out while others
# are not: uncommented lines are intended to protect your configuration from
# breaking changes in upgrades (i.e., in the event that... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | test_app/blog/config/initializers/active_admin.rb | Ruby | mit | 87 | master | 10,725 | ActiveAdmin.setup do |config|
# == Site Title
#
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = "Blog"
# Set the link url for the title. For example, to take
# users to your main site. Defaults to no link.
#
# config.site_title_link =... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | lib/active_admin/ajax_filter.rb | Ruby | mit | 87 | master | 1,454 | require 'active_admin'
require 'active_admin/ajax_filter/engine'
require 'active_admin/ajax_filter/version'
require 'active_admin/inputs/ajax_core'
require 'active_admin/inputs/ajax_select_input'
require 'active_admin/inputs/filters/ajax_select_input'
module ActiveAdmin
module AjaxFilter
class << self
# @p... |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | lib/active_admin/ajax_filter/engine.rb | Ruby | mit | 87 | master | 215 | require 'rails/engine'
module ActiveAdmin
module AjaxFilter
# Including an Engine tells Rails that this gem contains assets
class Engine < ::Rails::Engine
require 'selectize-rails'
end
end
end |
github | holyketzer/activeadmin-ajax_filter | https://github.com/holyketzer/activeadmin-ajax_filter | lib/active_admin/inputs/ajax_core.rb | Ruby | mit | 87 | master | 2,599 | module ActiveAdmin
module Inputs
module AjaxCore
DEFAULT_LIMIT = 5
def pluck_column
klass.reorder("#{method} asc").limit(collection_limit).uniq.pluck(method)
end
def input_html_options
super.merge(
'data-limit' => collection_limit,
'data-value-field' =... |
github | rktjmp/tileup | https://github.com/rktjmp/tileup | tileup.gemspec | Ruby | mit | 87 | develop | 956 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'tileup/version'
Gem::Specification.new do |spec|
spec.name = 'tileup'
spec.version = TileUp::VERSION
spec.date = Date.today.to_s
spec.summary = "Turn an image into a... |
github | rktjmp/tileup | https://github.com/rktjmp/tileup | lib/tileup/logger.rb | Ruby | mit | 87 | develop | 2,120 | require 'logger'
require 'ostruct'
module TileUp
# Base logger class, subclass this, do not use directly.
class TileUpLogger
def self.sym_to_severity(sym)
severities = {
:debug => Logger::DEBUG,
:info => Logger::INFO,
:warn => Logger::WARN,
:error => Logger::E... |
github | rktjmp/tileup | https://github.com/rktjmp/tileup | lib/tileup/tiler.rb | Ruby | mit | 87 | develop | 5,221 | require 'ostruct'
require 'RMagick'
require 'fileutils'
require 'tileup/logger'
module TileUp
class Tiler
def initialize(image_filename, options)
default_options = {
auto_zoom_levels: nil,
tile_width: 256,
tile_height: 256,
filename_prefix: "map_tile",
output_dir: ... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | keisan.gemspec | Ruby | mit | 87 | master | 1,131 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'keisan/version'
Gem::Specification.new do |spec|
spec.name = "keisan"
spec.version = Keisan::VERSION
spec.authors = ["Christopher Locke"]
spec.email = ["proje... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan.rb | Ruby | mit | 87 | master | 5,165 | require "keisan/version"
require "keisan/exceptions"
require "keisan/util"
require "keisan/ast/node"
require "keisan/ast/cell"
require "keisan/ast/literal"
require "keisan/ast/variable"
require "keisan/ast/constant_literal"
require "keisan/ast/number"
require "keisan/ast/string"
require "keisan/ast/null"
require "kei... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/token.rb | Ruby | mit | 87 | master | 465 | module Keisan
class Token
attr_reader :string
def initialize(string)
raise Exceptions::InvalidToken.new(string) unless string.match(regex)
@string = string
end
def type
self.class.type
end
def self.type
@type ||= Util.underscore(self.to_s.split("::").last).to_sym
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parser.rb | Ruby | mit | 87 | master | 9,570 | module Keisan
class Parser
KEYWORDS = %w(let puts break continue).freeze
attr_reader :tokens, :components
def initialize(string: nil, tokens: nil)
if string.nil? && tokens.nil?
raise Exceptions::InternalError.new("Invalid arguments")
end
if !string.nil?
@tokens = Token... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokenizer.rb | Ruby | mit | 87 | master | 1,618 | module Keisan
class Tokenizer
TOKEN_CLASSES = [
Tokens::Null,
Tokens::Boolean,
Tokens::Word,
Tokens::Number,
Tokens::Assignment,
Tokens::BitwiseShift,
Tokens::LogicalOperator,
Tokens::ArithmeticOperator,
Tokens::BitwiseOperator,
Tokens::Comma,
Toke... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/context.rb | Ruby | mit | 87 | master | 4,049 | module Keisan
class Context
attr_reader :function_registry,
:variable_registry,
:allow_recursive,
:allow_multiline,
:allow_blocks,
:allow_random
def initialize(parent: nil,
random: nil,
allow_recursive: false,
allow_multil... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/function.rb | Ruby | mit | 87 | master | 1,290 | module Keisan
class Function
attr_reader :name, :arity
def initialize(name, arity = 1)
@name = name
@arity = arity
end
def value(ast_function, context = nil)
raise Exceptions::NotImplementedError.new
end
def evaluate(ast_function, context = nil)
raise Exceptions::Not... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/evaluator.rb | Ruby | mit | 87 | master | 1,923 | module Keisan
class Evaluator
attr_reader :calculator
def initialize(calculator, cache: nil)
@calculator = calculator
@cache = cache
end
def evaluate(expression, definitions = {})
context = calculator.context.spawn_child(definitions: definitions, transient: true)
evaluate_ast... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/exceptions.rb | Ruby | mit | 87 | master | 837 | module Keisan
module Exceptions
class BaseError < ::StandardError; end
class InternalError < BaseError; end
class StandardError < BaseError; end
class NotImplementedError < InternalError; end
class InvalidToken < StandardError; end
class TokenizingError < StandardError; end
class ParseE... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/string_and_group_parser.rb | Ruby | mit | 87 | master | 6,371 | module Keisan
class StringAndGroupParser
class Portion
attr_reader :start_index, :end_index
def initialize(start_index)
@start_index = start_index
end
end
class StringPortion < Portion
attr_reader :string, :escaped_string
def initialize(expression, start_index)
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/util.rb | Ruby | mit | 87 | master | 367 | module Keisan
class Util
def self.underscore(str)
str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').downcase
end
def self.array_split(array, &block)
array.inject([[]]) do |results, element|
if yield(element)
results << []
else
results.last << element
en... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast.rb | Ruby | mit | 87 | master | 1,654 | require "date"
require "time"
module Keisan
module AST
def self.parse(expression)
AST::Builder.new(string: expression).ast
end
end
end
module KeisanNumeric
def to_node
Keisan::AST::Number.new(self)
end
def value(context = nil)
self
end
end
module KeisanString
def to_node
Keis... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/interpreter.rb | Ruby | mit | 87 | master | 810 | require "keisan/repl"
module Keisan
class Interpreter
attr_reader :calculator
def initialize(allow_recursive: false)
@calculator = Calculator.new(allow_recursive: allow_recursive)
end
def run(file_name)
if file_name.nil?
run_from_stdin
else
run_from_file(file_name)... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/repl.rb | Ruby | mit | 87 | master | 2,264 | require "coderay"
require "readline"
module Keisan
class Repl
COMMANDS = %w(
reset
quit
variables
functions
allow_recursive
).freeze
attr_reader :calculator
def initialize
@running = true
initialize_completion_commands
reset
end
def reset
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/calculator.rb | Ruby | mit | 87 | master | 2,051 | module Keisan
class Calculator
attr_reader :context
# Note, allow_recursive would be more appropriately named:
# allow_unbound_functions_in_function_definitions, but it is too late for that.
def initialize(context: nil, allow_recursive: false, allow_blocks: true, allow_multiline: true, allow_random: ... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/variables/registry.rb | Ruby | mit | 87 | master | 1,680 | require "set"
module Keisan
module Variables
class Registry
attr_reader :shadowed
def initialize(variables: {}, shadowed: [], parent: nil, use_defaults: true, force: false)
@hash = {}
@shadowed = ::Set.new(shadowed.map(&:to_s))
@parent = parent
@use_defaults = use_def... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/variables/default_registry.rb | Ruby | mit | 87 | master | 353 | module Keisan
module Variables
class DefaultRegistry < Registry
VARIABLES = {
"PI" => Math::PI,
"E" => Math::E,
"I" => Complex(0,1),
"INF" => Float::INFINITY
}
def self.registry
@registry ||= Registry.new(variables: VARIABLES, parent: nil, force: true).fr... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/bitwise_operator.rb | Ruby | mit | 87 | master | 489 | module Keisan
module Tokens
class BitwiseOperator < Operator
AND = /(?:\&)/
OR = /(?:\|)/
XOR = /(?:\^)/
NOT = /(?:\~+)/
REGEX = /(#{AND}|#{OR}|#{XOR}|#{NOT})/
def self.regex
REGEX
end
def operator_type
case string
when AND
:"&"
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/assignment.rb | Ruby | mit | 87 | master | 627 | module Keisan
module Tokens
class Assignment < Operator
REGEX = /(
(?: # possible compound operators in front of equals
\|\| |
\&\& |
\*\* |
\+ |
\- |
\* |
\/ |
\% |
\& |
\| |
\^ |
\<\< |
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/logical_operator.rb | Ruby | mit | 87 | master | 985 | module Keisan
module Tokens
class LogicalOperator < Operator
LESS_THAN_OR_EQUAL_TO = /(?:\<\=)/
GREATER_THAN_OR_EQUAL_TO = /(?:\>\=)/
LESS_THAN = /(?:\<)/
GREATER_THAN = /(?:\>)/
AND = /(?:\&\&)/
OR = /(?:\|\|)/
EQUAL = /(?:\=\=)/
NOT_EQUAL = /(?:\!\=)/
NOT = ... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/number.rb | Ruby | mit | 87 | master | 660 | module Keisan
module Tokens
class Number < Token
INTEGER_REGEX = /\d+/
BINARY_REGEX = /0b[0-1]+/
OCTAL_REGEX = /0o[0-7]+/
HEX_REGEX = /0x[0-9a-fA-F]+/
FLOATING_POINT_REGEX = /\d+\.\d+/
SCIENTIFIC_NOTATION_REGEX = /\d+(?:\.\d+)?e(?:\+|\-)?\d+/
REGEX = /(#{BINARY_REGEX}|#{... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/group.rb | Ruby | mit | 87 | master | 427 | module Keisan
module Tokens
class Group < Token
attr_reader :sub_tokens
def initialize(string)
@string = string
@sub_tokens = Tokenizer.new(string[1...-1]).tokens
end
# Either :round, :square
def group_type
case string[0]
when "("
:round
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/boolean.rb | Ruby | mit | 87 | master | 288 | module Keisan
module Tokens
class Boolean < Token
REGEX = /((?:\btrue\b)|(?:\bfalse\b))/
def self.regex
REGEX
end
def value
case string
when "true"
true
else
false
end
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/arithmetic_operator.rb | Ruby | mit | 87 | master | 686 | module Keisan
module Tokens
class ArithmeticOperator < Operator
EXPONENT = /(?:\*\*)/
TIMES = /(?:\*)/
DIVIDE = /(?:\/)/
MODULO = /(?:\%)/
PLUS_OR_MINUS = /(?:[\+\-]+)/
REGEX = /(#{EXPONENT}|#{TIMES}|#{DIVIDE}|#{MODULO}|#{PLUS_OR_MINUS})/
def self.regex
REGEX
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/tokens/bitwise_shift.rb | Ruby | mit | 87 | master | 377 | module Keisan
module Tokens
class BitwiseShift < Operator
LEFT_SHIFT = /(?:<<)/
RIGHT_SHIFT = /(?:>>)/
REGEX = /(#{LEFT_SHIFT}|#{RIGHT_SHIFT})/
def self.regex
REGEX
end
def operator_type
case string
when LEFT_SHIFT
:<<
when RIGHT_SHI... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/group.rb | Ruby | mit | 87 | master | 213 | module Keisan
module Parsing
class Group < Element
attr_reader :components
def initialize(sub_tokens)
@components = Parser.new(tokens: sub_tokens).components
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/dot_word.rb | Ruby | mit | 87 | master | 203 | module Keisan
module Parsing
class DotWord < Component
attr_reader :name
def initialize(name)
@name = name
end
def arguments
[]
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/dot_operator.rb | Ruby | mit | 87 | master | 218 | module Keisan
module Parsing
class DotOperator < Element
attr_reader :name, :arguments
def initialize(name, arguments)
@name = name
@arguments = arguments
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/hash.rb | Ruby | mit | 87 | master | 1,326 | module Keisan
module Parsing
class Hash < Element
attr_reader :key_value_pairs
def initialize(key_value_pairs)
key_value_pairs = Array(key_value_pairs)
if key_value_pairs.size == 1 && key_value_pairs.first.empty?
@key_value_pairs = []
else
@key_value_pairs ... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/operator.rb | Ruby | mit | 87 | master | 339 | module Keisan
module Parsing
class Operator < Component
def arity
node_class.arity
end
def priority
node_class.priority
end
def associativity
node_class.associativity
end
def node_class
raise Exceptions::NotImplementedError.new
end... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/indexing.rb | Ruby | mit | 87 | master | 238 | module Keisan
module Parsing
class Indexing < SquareGroup
attr_reader :arguments
def initialize(arguments)
@arguments = arguments
end
def node_class
AST::Indexing
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/compound_assignment.rb | Ruby | mit | 87 | master | 280 | module Keisan
module Parsing
class CompoundAssignment < Operator
attr_reader :compound_operator
def initialize(compound_operator)
@compound_operator = compound_operator
end
def node_class
AST::Assignment
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/parsing/function.rb | Ruby | mit | 87 | master | 222 | module Keisan
module Parsing
class Function < Element
attr_reader :name, :arguments
def initialize(name, arguments)
@name = name
@arguments = Array(arguments)
end
end
end
end |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/variable.rb | Ruby | mit | 87 | master | 2,115 | module Keisan
module AST
class Variable < Literal
attr_reader :name
def initialize(name)
@name = name
end
def variable_truthy?(context)
context.has_variable?(name) && context.variable(name).true?
end
def value(context = nil)
context ||= Context.new
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/bitwise_and.rb | Ruby | mit | 87 | master | 332 | module Keisan
module AST
class BitwiseAnd < BitwiseOperator
def self.symbol
:"&"
end
def blank_value
~0
end
def evaluate(context = nil)
children[1..-1].inject(children.first.evaluate(context)) {|total, child| total & child.evaluate(context)}
end
en... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/cell_assignment.rb | Ruby | mit | 87 | master | 2,003 | module Keisan
module AST
class CellAssignment
attr_reader :assignment, :context, :lhs, :rhs
def initialize(assignment, context, lhs, rhs)
@assignment = assignment
@context = context
@lhs = lhs
@rhs = rhs
end
def evaluate
lhs = lhs_evaluate_and_chec... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/bitwise_right_shift.rb | Ruby | mit | 87 | master | 338 | module Keisan
module AST
class BitwiseRightShift < BitwiseOperator
def self.symbol
:>>
end
def blank_value
0
end
def evaluate(context = nil)
children[1..-1].inject(children.first.evaluate(context)) {|total, child| total >> child.evaluate(context)}
end
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/exponent.rb | Ruby | mit | 87 | master | 2,124 | module Keisan
module AST
class Exponent < ArithmeticOperator
def self.symbol
:**
end
def blank_value
1
end
def simplify(context = nil)
context ||= Context.new
super(context)
# Reduce to basic binary exponents
reduced = children.reve... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/boolean.rb | Ruby | mit | 87 | master | 852 | module Keisan
module AST
class Boolean < ConstantLiteral
attr_reader :bool
def initialize(bool)
@bool = bool
end
def value(context = nil)
bool
end
def true?
bool
end
def !
Boolean.new(!bool)
end
def and(other)
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/cell.rb | Ruby | mit | 87 | master | 1,567 | module Keisan
module AST
class Cell < Node
attr_accessor :node
def initialize(node)
@node = node
end
def unbound_variables(context = nil)
node.unbound_variables(context)
end
def unbound_functions(context = nil)
node.unbound_functions(context)
en... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/function.rb | Ruby | mit | 87 | master | 2,585 | module Keisan
module AST
class Function < Parent
attr_reader :name
def initialize(arguments = [], name)
@name = name
super(arguments)
end
def value(context = nil)
context ||= Context.new
function_from_context(context).value(self, context)
end
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/list.rb | Ruby | mit | 87 | master | 974 | module Keisan
module AST
class List < Parent
def initialize(children = [])
super(children)
end
def evaluate(context = nil)
return self if frozen?
context ||= Context.new
@children = children.map {|child| child.is_a?(Cell) ? child : child.evaluate(context)}
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/hash.rb | Ruby | mit | 87 | master | 2,007 | module Keisan
module AST
class Hash < Node
include Enumerable
def initialize(key_value_pairs)
@hash = ::Hash[key_value_pairs.map(&:to_a).map {|k,v| [k.value, v.to_node]}]
end
def freeze
values.each(&:freeze)
super
end
def [](key)
key = key.to_... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/bitwise_xor.rb | Ruby | mit | 87 | master | 331 | module Keisan
module AST
class BitwiseXor < BitwiseOperator
def self.symbol
:"^"
end
def blank_value
0
end
def evaluate(context = nil)
children[1..-1].inject(children.first.evaluate(context)) {|total, child| total ^ child.evaluate(context)}
end
end... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/null.rb | Ruby | mit | 87 | master | 486 | module Keisan
module AST
class Null < ConstantLiteral
def initialize
end
def value(context = nil)
nil
end
def true?
false
end
def equal(other)
other = other.to_node
other.is_a?(AST::Null) ? Boolean.new(value == other.value) : super
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/variable_assignment.rb | Ruby | mit | 87 | master | 1,872 | module Keisan
module AST
class VariableAssignment
attr_reader :assignment, :context, :lhs, :rhs
def initialize(assignment, context, lhs, rhs)
@assignment = assignment
@context = context
@lhs = lhs
@rhs = rhs
end
def evaluate
case assignment.compoun... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/unary_logical_not.rb | Ruby | mit | 87 | master | 891 | module Keisan
module AST
class UnaryLogicalNot < UnaryOperator
def value(context = nil)
return !child.value(context)
end
def self.symbol
:"!"
end
def evaluate(context = nil)
context ||= Context.new
node = child.evaluate(context).to_node
case ... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/unary_identity.rb | Ruby | mit | 87 | master | 511 | module Keisan
module AST
class UnaryIdentity < UnaryOperator
def value(context = nil)
child.value(context)
end
def evaluate(context = nil)
child.evaluate(context)
end
def self.symbol
nil
end
def simplify(context = nil)
child.simplify(con... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/node.rb | Ruby | mit | 87 | master | 4,042 | module Keisan
module AST
class Node
def value(context = nil)
raise Exceptions::NotImplementedError.new
end
def unbound_variables(context = nil)
Set.new
end
def unbound_functions(context = nil)
Set.new
end
def well_defined?(context = nil)
... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/unary_minus.rb | Ruby | mit | 87 | master | 803 | module Keisan
module AST
class UnaryMinus < UnaryOperator
def value(context = nil)
return -1 * child.value(context)
end
def evaluate(context = nil)
-child.evaluate(context)
end
def self.symbol
:"-"
end
def simplify(context = nil)
context... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/cache.rb | Ruby | mit | 87 | master | 609 | module Keisan
module AST
class Cache
def initialize
@cache = {}
end
def fetch_or_build(string)
return @cache[string] if @cache.has_key?(string)
build_from_scratch(string).tap do |ast|
unless frozen?
# Freeze the AST to keep it from changing in the ... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/constant_literal.rb | Ruby | mit | 87 | master | 4,767 | module Keisan
module AST
class ConstantLiteral < Literal
def evaluate(context = nil)
self
end
def ==(other)
case other
when ConstantLiteral
value == other.value
else
false
end
end
def to_s
case value
when R... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/parent.rb | Ruby | mit | 87 | master | 2,033 | module Keisan
module AST
class Parent < Node
attr_reader :children
def initialize(children = [])
children = Array(children).map do |child|
child.is_a?(Cell) ? child : child.to_node
end
raise Exceptions::InternalError.new unless children.is_a?(Array)
@children... |
github | project-eutopia/keisan | https://github.com/project-eutopia/keisan | lib/keisan/ast/unary_operator.rb | Ruby | mit | 87 | master | 797 | module Keisan
module AST
class UnaryOperator < Operator
def initialize(children = [])
children = Array(children)
super(children)
if children.count != 1
raise Exceptions::ASTError.new("Unary operator takes has a single child")
end
end
def child
c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.