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 | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/Rakefile | Ruby | mit | 44 | master | 940 | require 'rubygems'
require 'bundler'
namespace :check do
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:design) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.rspec_opts = "-cfd"
end
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)
na... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/Gemfile | Ruby | mit | 44 | master | 208 | source :rubygems
gem "cukesalad", ">=0.8.1"
gem "rspec", ">=2.8.0", :require => 'spec'
gem "capybara", ">=0.4.1.2"
gem "sinatra", ">=1.2.0"
group :test, :development do
gem 'sinatra-reloader', '0.5.0'
end |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/spec/calculator_spec.rb | Ruby | mit | 44 | master | 1,297 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require 'rubygems'
require 'bundler'
Bundler.setup
require 'calculator'
describe Calculator do
it "starts with zero" do
calc = Calculator.new
calc.display.should == 0
end
it "shows the current number" do
calc = Calculator.new
calc.enter... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/spec/web_calculator_spec.rb | Ruby | mit | 44 | master | 2,369 | $:.unshift(File.dirname(__FILE__) + '/../lib/')
require 'web_calculator'
require 'capybara'
require 'capybara/dsl'
Capybara.app = WebCalculator
Capybara.default_driver = :rack_test
describe "WebCalculator", :type => :request do
include Capybara
before(:each) do
Capybara.reset_sessions!
end
context "ho... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/lib/calculator.rb | Ruby | mit | 44 | master | 1,005 | class Calculator
OPERATIONS = {
plus: '+',
minus: '-',
equals: '='
}
attr_reader :display
def initialize
show 0
@operands = []
end
def enter value
show value
@operands.push value
end
def get_ready_to op
calculate_if_necessary
start_next_calculation
@... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/lib/web_calculator.rb | Ruby | mit | 44 | master | 1,435 | require 'sinatra/base'
require 'erb'
$:.unshift(File.dirname(__FILE__), '.')
require 'calculator'
class WebCalculator < Sinatra::Base
use Rack::Session::Pool
configure :development, :test do
require 'sinatra/reloader'
end
helpers do
def available_operations
Calculator::OPERATIONS
end
... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/lib/web_calculating_individual.rb | Ruby | mit | 44 | master | 473 | require 'capybara/dsl'
module WebCalculatingIndividual
include Capybara::DSL
def role_preparation
switch_on_the_calculator
end
def switch_on_the_calculator
visit '/'
end
def enter value
fill_in 'number', :with => value
end
def press operator
click_button operator.to_s
end
def... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/features/lib/tasks/switch_on_the_calculator.rb | Ruby | mit | 44 | master | 242 | in_order_to "switch on the calculator" do
require 'rspec/expectations'
extend RSpec::Matchers
switch_on_the_calculator
self.should respond_to :enter
self.should respond_to :press
self.should respond_to :look_at_the_display
end |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/features/lib/tasks/reference/calculations.rb | Ruby | mit | 44 | master | 334 | module Calculations
def follow_the_steps_for sum
enter_numbers_and_operators_for sum
end
def enter_numbers_and_operators_for sum
operators = Calculator::OPERATIONS.invert
sum.each do | token |
enter token.to_i if token =~ /\d+/
press operators[token] if operators.include? token
e... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/features/lib/roles/back_door/calculating_individual.rb | Ruby | mit | 44 | master | 541 | require 'calculator'
module CalculatingIndividual
def role_preparation
switch_on_the_calculator
end
def switch_on_the_calculator
@calculator = Calculator.new
@operate_with = Calculator::OPERATIONS
end
def enter value
@calculator.enter value.to_i
end
def press next_operator
if next... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/features/lib/roles/front_door/calculating_individual.rb | Ruby | mit | 44 | master | 221 | require 'web_calculator'
require 'web_calculating_individual'
require 'capybara/dsl'
Capybara.app = WebCalculator
Capybara.default_driver = :selenium
module CalculatingIndividual
include WebCalculatingIndividual
end |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/features/lib/roles/side_door/calculating_individual.rb | Ruby | mit | 44 | master | 222 | require 'web_calculator'
require 'web_calculating_individual'
require 'capybara/dsl'
Capybara.app = WebCalculator
Capybara.default_driver = :rack_test
module CalculatingIndividual
include WebCalculatingIndividual
end |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | Examples/Calculator/features/support/env.rb | Ruby | mit | 44 | master | 204 | $:.unshift(File.dirname(__FILE__) + '/../../lib') #where to find the calculator implementation
require 'cukesalad'
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/cli.rb | Ruby | mit | 44 | master | 1,479 | require 'aruba/api'
module CukeSalad
class CLI
def self.create_new_project project
structure = Structure.new
structure.setup project
end
def self.configure_existing_project project=nil
`cd #{project}` if project
structure = Structure.new
structure.setup_cucumber_with_cukesa... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/cucumber_steps.rb | Ruby | mit | 44 | master | 1,257 | require 'cukesalad/salad'
def in_order_to(do_something, *with_attributes, &actions)
CukeSalad::TaskAuthor.in_order_to(do_something, *with_attributes, &actions)
end
World(CukeSalad::TaskAuthor)
World(CukeSalad::Specifics)
Given /^(?:I am|you are) a(?:n)? ([a-zA-Z ]+)$/ do |role|
@actor = CukeSalad::Actor.new(role)... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/director.rb | Ruby | mit | 44 | master | 856 | require 'cukesalad/codify/const_name'
module CukeSalad
class Director
include Codify
#TODO: Needs refactoring
def explain_the_role description
name = ConstName.from description
begin
find_directives_for name
rescue NameError
raise "I can't find a role called '#{ nam... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/specifics.rb | Ruby | mit | 44 | master | 785 | module CukeSalad
module Specifics
def understand_the details
@info = with_specifics_from( details )
end
def value_of(symbol)
@info[symbol]
end
def with_specifics_from details
result = {}
names_and_values_in(details).each_slice(2) do |name_value|
result[symbolized ... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/actor.rb | Ruby | mit | 44 | master | 1,250 | require 'cukesalad/director'
module CukeSalad
class Actor
def initialize this_type_of_role, directed_by=Director.new
@director = directed_by
@note_pad = {}
get_into_character_for this_type_of_role
end
def perform described_task, details = {}
get_ready_to_perform described_task
... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/task_author.rb | Ruby | mit | 44 | master | 595 | require 'cukesalad/codify/const_name'
module CukeSalad
module TaskAuthor
def in_order_to do_something, *with_attributes, &actions
TaskAuthor.in_order_to do_something, *with_attributes, &actions
end
def TaskAuthor.in_order_to do_something, *with_attributes, &actions
attr_map = with_attributes... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | lib/cukesalad/codify/const_name.rb | Ruby | mit | 44 | master | 522 | module CukeSalad
module Codify
module ConstName
def ConstName.from sentence
joined_together capitalised( words_from sentence )
end
private
def ConstName.joined_together words
words.join
end
def ConstName.words_from this_sentence
on_word_bou... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | spec/cukesalad/cli_spec.rb | Ruby | mit | 44 | master | 2,108 | $:.unshift(File.dirname(__FILE__), ".")
require 'spec_helper'
require 'cukesalad/cli'
# don't override aruba path
module CukeSalad
class CLI
class Structure
def initialize
end
end
end
end
def dir_exists? file
File.exists?("tmp/aruba/"+file)
end
def file_content file
IO.read("tmp/aruba/"+f... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | spec/cukesalad/task_author_spec.rb | Ruby | mit | 44 | master | 1,060 | require 'spec_helper'
require 'cukesalad/task_author'
class SomeActor
def see_how_to_do something
extend something
end
def do_your_thing
perform_task
end
def value_of thing
"this is the info"
end
end
module CukeSalad
describe 'TaskAuthor' do
include TaskAuthor
it "creates a module b... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | spec/cukesalad/actor_spec.rb | Ruby | mit | 44 | master | 2,727 | require 'spec_helper'
module SetThePlaceAtTheTable
def perform_task
place = []
place_the_fork_on_the_left_of place
place_the_knife_on_the_right_of place
place
end
end
module LayTheTable
def perform_task
value_of( :with_places_for ).to_i
end
end
module Butler
def place_the_fork_on_th... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | spec/cukesalad/director_spec.rb | Ruby | mit | 44 | master | 922 | require 'spec_helper'
class Something
end
class Another
end
class MoreThanOneWord
end
module CukeSalad
describe Director do
before :each do
@director = Director.new
end
it "gives you directives (i.e. a class) for Something" do
the_thing_we_found = @director.how_do_i_perform "something"
... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | spec/cukesalad/specifics_spec.rb | Ruby | mit | 44 | master | 2,490 | require 'spec_helper'
class NeedingSpecifics
include CukeSalad::Specifics
end
module CukeSalad
describe Specifics do
context 'name value pairs' do
[ "specific 'information'",
'specific "information"'
].each do | specifics |
it "can be found in: #{specifics}" do
somethin... |
github | RiverGlide/CukeSalad | https://github.com/RiverGlide/CukeSalad | spec/cukesalad/codify/as_const_name_spec.rb | Ruby | mit | 44 | master | 883 | require 'spec_helper'
require 'cukesalad/codify/const_name'
module CukeSalad
module Codify
describe ConstName do
it "gives you ClassName from when it's already a class name" do
ConstName.from( "ClassName" ).should == "ClassName"
end
it "gives you ClassName when separated by spaces... |
github | mongoid/evolver | https://github.com/mongoid/evolver | evolver.gemspec | Ruby | mit | 44 | master | 744 | # encoding: utf-8
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
require "evolver/version"
Gem::Specification.new do |s|
s.name = "evolver"
s.version = Evolver::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Durran Jordan"]
s.email = ["durr... |
github | mongoid/evolver | https://github.com/mongoid/evolver | Rakefile | Ruby | mit | 44 | master | 628 | require "bundler"
Bundler.setup
require "rake"
require "rspec/core/rake_task"
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "evolver/version"
task :gem => :build
task :build do
system "gem build evolver.gemspec"
end
task :install => :build do
system "sudo gem install evolver-#{Evolver::VERSION... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/spec_helper.rb | Ruby | mit | 44 | master | 751 | $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "spec"))
require "evolver"
require "rspec"
require "db/evolver/migrations/20120519113509_rename_bands_to_artists"
require "db/evolver/migrations/2012... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/evolver_spec.rb | Ruby | mit | 44 | master | 5,814 | require "spec_helper"
describe Evolver do
describe ".find" do
let(:session) do
Mongoid.default_session
end
context "when the migration exists" do
let(:found) do
described_class.find("RenameBandsToArtists", session)
end
it "returns the migration instance" do
fo... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/db/evolver/migrations/20120520152200_add_likes_to_label.rb | Ruby | mit | 44 | master | 267 | class AddLikesToLabel
include Evolver::Migration
sessions :default, :mongohq_repl
def execute
session[:labels].find.update_all("$set" => { "likes" => 0 })
end
def revert
session[:labels].find.update_all("$unset" => { "likes" => true })
end
end |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/db/evolver/migrations/20120519113509_rename_bands_to_artists.rb | Ruby | mit | 44 | master | 274 | class RenameBandsToArtists
include Evolver::Migration
sessions :default
def execute
session[:labels].find.update_all("$rename" => { "bands" => "artists" })
end
def revert
session[:labels].find.update_all("$rename" => { "artists" => "bands" })
end
end |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/db/evolver/migrations/20120727130510_copy_labels_to_secondary.rb | Ruby | mit | 44 | master | 282 | class CopyLabelsToSecondary
include Evolver::Migration
sessions :default
def execute
session.use(:evolver_secondary)
session[:labels].insert({ bands: [ "Tool" ]})
end
def revert
session.use(:evolver_secondary)
session[:labels].find.remove_all
end
end |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/db/evolver/migrations/20120729122212_add_impressions_to_label.rb | Ruby | mit | 44 | master | 275 | class AddImpressionsToLabel
include Evolver::Migration
sessions :mongohq_repl
def execute
session[:labels].find.update_all("$set" => { "impressions" => 0 })
end
def revert
session[:labels].find.update_all("$unset" => { "impressions" => true })
end
end |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/evolver/migrator_spec.rb | Ruby | mit | 44 | master | 1,677 | require "spec_helper"
describe Evolver::Migrator do
let(:session) do
Mongoid.default_session
end
before(:all) do
session[:evolver_migrations].find.remove_all
end
describe "#execute" do
let(:migrator) do
described_class.new({ default: session })
end
context "when no migrations h... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/evolver/sessions_spec.rb | Ruby | mit | 44 | master | 445 | require "spec_helper"
describe Evolver::Sessions do
describe "#sessions" do
context "when an evolver.yml is present" do
it "contains the default session" do
end
it "contains additional configured sessions" do
end
end
context "when a mongoid.yml is present" do
it "con... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/evolver/loggable_spec.rb | Ruby | mit | 44 | master | 420 | require "spec_helper"
describe Evolver::Loggable do
describe "#logger=" do
let(:klass) do
Class.new do
include Evolver::Loggable
end.new
end
let(:logger) do
Logger.new($stdout).tap do |log|
log.level = Logger::INFO
end
end
before do
klass.logger =... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/evolver/migration_spec.rb | Ruby | mit | 44 | master | 2,610 | require "spec_helper"
describe Evolver::Migration do
describe ".file" do
let(:caller) do
"/some/dir/db/evolver/migrations/20120519113509_rename_bands_to_artists.rb:30"
end
it "returns the filename" do
RenameBandsToArtists.file(caller).should eq(
"20120519113509_rename_bands_to_arti... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/evolver/extensions/time_spec.rb | Ruby | mit | 44 | master | 627 | require "spec_helper"
describe Evolver::Extensions::Time do
describe "#to_evolver_timestamp" do
let(:time) do
Time.new(2012, 1, 5, 12, 45, 30)
end
let(:stamp) do
time.to_evolver_timestamp
end
it "returns the timestamp in YYYYMMDDHHMMSS format" do
stamp.should eq("20120105124... |
github | mongoid/evolver | https://github.com/mongoid/evolver | spec/rails/generators/evolver_spec.rb | Ruby | mit | 44 | master | 409 | require "spec_helper"
describe Evolver::Generators::Base do
describe ".next_migration_number" do
let(:time) do
Time.now
end
let(:expected) do
Time.now.to_evolver_timestamp[0...12]
end
let(:timestamp) do
described_class.next_migration_number("/path")
end
it "returns ... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver.rb | Ruby | mit | 44 | master | 3,688 | # encoding: utf-8
require "mongoid"
require "evolver/extensions"
require "evolver/loggable"
require "evolver/migrator"
require "evolver/railtie"
require "evolver/sessions"
require "evolver/version"
require "rails/generators/evolver"
module Evolver
include Loggable
extend self
# Get an instance of the migration ... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver/migrator.rb | Ruby | mit | 44 | master | 4,158 | # encoding: utf-8
require "evolver/loggable"
require "evolver/migration"
module Evolver
class Migrator
include Loggable
TEMPLATE = File.join(File.dirname(__FILE__), "stats.txt.erb")
attr_reader :sessions
# Execute the migrations. This grabs all pending migrations in order and
# calls execute o... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver/loggable.rb | Ruby | mit | 44 | master | 1,082 | # encoding: utf-8
module Evolver
# Contains logging behaviour.
module Loggable
# Get the logger.
#
# @note Will try to grab Rails' logger first before creating a new logger
# with stdout.
#
# @example Get the logger.
# Loggable.logger
#
# @return [ Logger ] The logger.
... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver/migration.rb | Ruby | mit | 44 | master | 2,252 | # encoding: utf-8
require "active_support/concern"
module Evolver
module Migration
extend ActiveSupport::Concern
attr_reader :file, :session, :time
# Instantiate the migration.
#
# @example Instantiate the migration.
# Migration.new(file, session, time)
#
# @param [ String ] file ... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver/railtie.rb | Ruby | mit | 44 | master | 207 | # encoding: utf-8
require "rails/railtie"
module Evolver
class Railtie < Rails::Railtie
# Expose evolver's rake tasks to Rails.
rake_tasks do
load "evolver/tasks/db.rake"
end
end
end |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver/tasks/db.rake | Ruby | mit | 44 | master | 410 | # encoding: utf-8
namespace :evolver do
desc "Execute any pending MongoDB data migrations on all sessions."
task migrate: :environment do
Evolver.migrate
end
desc "Revert the last run MongoDB data migration."
task revert: :environment do
Evolver.revert
end
desc "Get statistics on all pending an... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/evolver/extensions/time.rb | Ruby | mit | 44 | master | 1,165 | # encoding: utf-8
require "time"
module Evolver
module Extensions
module Time
FORMAT = "%Y%m%d%H%M%S"
# Convert the time to a migration friendly time that will be prefixed in
# the file name.
#
# @example Generate the timestamp.
# time.to_evolver_timestamp
#
# ... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/rails/generators/evolver.rb | Ruby | mit | 44 | master | 772 | # encoding: utf-8
require "rails/generators"
require "rails/generators/migration"
require "rails/generators/named_base"
module Evolver
module Generators
class Base < Rails::Generators::NamedBase
include Rails::Generators::Migration
class << self
# Get the next migration number, ignoring the... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/rails/generators/evolver/migration_generator.rb | Ruby | mit | 44 | master | 544 | # encoding: utf-8
require "rails/generators/evolver"
module Evolver
module Generators
class MigrationGenerator < Base
source_root File.join(File.dirname(__FILE__), "templates")
# Create the migration file.
#
# @example Create the migration file.
# generator.create_migration_file... |
github | mongoid/evolver | https://github.com/mongoid/evolver | lib/rails/generators/evolver/templates/migration.rb | Ruby | mit | 44 | master | 242 | class <%= migration_class_name %>
include Evolver::Migration
sessions :default
def execute
# Insert your code to migrate the database forward here.
end
def revert
# Insert your code to revert the migration here.
end
end |
github | mrsool/zatca | https://github.com/mrsool/zatca | zatca.gemspec | Ruby | mit | 44 | main | 2,210 | # frozen_string_literal: true
require_relative "lib/zatca/version"
Gem::Specification.new do |spec|
spec.name = "zatca"
spec.version = ZATCA::VERSION
spec.authors = ["Omar Bahareth"]
spec.email = ["obahareth@mrsool.co"]
spec.summary = "A library for generating QR Codes for the e-invoice standard by ZATCA i... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/spec_helper.rb | Ruby | mit | 44 | main | 5,264 | # 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 | mrsool/zatca | https://github.com/mrsool/zatca | spec/lib/zatca_spec.rb | Ruby | mit | 44 | main | 760 | describe ZATCA::Tags do
let(:tags) { FIXTURES_TAGS }
describe "#render_qr_code" do
it "instantiates a QRCodeGenerator and calls #render with a hash of tags" do
expect_any_instance_of(ZATCA::QRCodeGenerator).to receive(:render)
ZATCA.render_qr_code(tags: tags)
end
it "instantiates a QRCode... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/lib/zatca/qr_code_generator_spec.rb | Ruby | mit | 44 | main | 13,789 | describe ZATCA::QRCodeGenerator do
let(:tags_generator) { ZATCA::QRCodeGenerator.new(tags: ZATCA::Tags.new(FIXTURES_TAGS)) }
let(:unicode_tags_generator) { ZATCA::QRCodeGenerator.new(tags: ZATCA::Tags.new(FIXTURES_UNICODE_TAGS)) }
let(:base64_generator) { ZATCA::QRCodeGenerator.new(base64: FIXTURES_BASE64_QR_CODE... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/lib/zatca/tag_spec.rb | Ruby | mit | 44 | main | 1,897 | describe ZATCA::Tag do
let(:tag) { ZATCA::Tag.new(key: :seller_name, value: "Mrsool") }
let(:unicode_tag) { ZATCA::Tag.new(key: :seller_name, value: "مرسول") }
describe "#id" do
it "gets mapped from seller_name to 1" do
expect(ZATCA::Tag.new(key: :seller_name, value: "").id).to eq(1)
end
it "g... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/lib/zatca/tags_spec.rb | Ruby | mit | 44 | main | 2,401 | describe ZATCA::Tags do
let(:tags) { ZATCA::Tags.new(FIXTURES_TAGS) }
let(:unicode_tags) { ZATCA::Tags.new(FIXTURES_UNICODE_TAGS) }
describe "#to_base64" do
it "generates valid Base64 with ASCII tags" do
base64 = tags.to_base64
expected_base64 = "AQZNcnNvb2wCDzMxMDIyODgzMzQwMDAwMwMUMjAyMS0xMC0yMF... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/lib/zatca/ubl/invoice_spec.rb | Ruby | mit | 44 | main | 5,038 | describe ZATCA::UBL::Invoice do
def clear_dynamic_values_from_xml(xml)
xml.gsub(/<ds:DigestValue>.*<\/ds:DigestValue>/, "")
.gsub(/<ds:SignatureValue>.*<\/ds:SignatureValue>/, "")
.gsub(/<cbc:EmbeddedDocumentBinaryObject mimeCode="text\/plain">.*<\/cbc:EmbeddedDocumentBinaryObject>/, "")
end
cont... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/lib/zatca/ubl/invoice_subtype_builder_spec.rb | Ruby | mit | 44 | main | 2,395 | RSpec.describe ZATCA::UBL::InvoiceSubtypeBuilder do
subject { described_class }
describe "#build" do
it "builds standard tax invoice subtype" do
code = subject.build(
simplified: false,
third_party: false,
nominal: false,
exports: false,
summary: false,
sel... |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/support/vcr.rb | Ruby | mit | 44 | main | 251 | require "vcr"
VCR.configure do |config|
config.cassette_library_dir = "spec/cassettes"
config.hook_into :webmock
config.ignore_localhost = true
config.default_cassette_options = {record: :new_episodes}
config.configure_rspec_metadata!
end |
github | mrsool/zatca | https://github.com/mrsool/zatca | spec/support/fixtures.rb | Ruby | mit | 44 | main | 459 | def fixtures_dir
File.join(File.dirname(__FILE__), "..", "fixtures")
end
def read_xml_fixture(file_name)
file_path = File.join(fixtures_dir, "xml", file_name)
File.read(file_path)
end
def read_certificate(file_name)
File.read(certificate_path(file_name))
end
def private_key_fixtures_path(file_name)
File.j... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca.rb | Ruby | mit | 44 | main | 1,196 | # frozen_string_literal: true
require_relative "zatca/version"
require_relative "zatca/types"
require "active_support/all"
require "zeitwerk"
require "dry-initializer"
require "dry-types"
loader = Zeitwerk::Loader.for_gem
loader.inflector.inflect(
"zatca" => "ZATCA",
"qr_code_generator" => "QRCodeGenerator",
"... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/qr_code_extractor.rb | Ruby | mit | 44 | main | 678 | require "nokogiri"
require "base64"
class ZATCA::QRCodeExtractor
attr_reader :invoice_base64
def initialize(invoice_base64:)
@invoice_base64 = invoice_base64
end
def extract
xml_invoice = Base64.strict_decode64(invoice_base64)
extract_qr_code_base64_from_xml(xml_invoice)
end
private
def e... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/hacks.rb | Ruby | mit | 44 | main | 2,614 | module ZATCA::Hacks
extend self
# rubocop:disable Layout/HeredocIndentation
# rubocop:disable Layout/ClosingHeredocIndentation
# ZATCA also hashes serverside to ensure our signed properties hash is correct.
# However ZATCA does not format the XML to use the same whitespace needed for
# hashing. They genera... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/hashing.rb | Ruby | mit | 44 | main | 552 | class ZATCA::Hashing
# Returns the content as:
# - hash - SHA256 digest (bytes)
# - hexdigest - SHA256 digest (hex)
# - base64 - SHA256 digest (bytes) then Base64 encoded
# - hexdigest_base64 - SHA256 digest (hex) then Base64 encoded
def self.generate_hashes(content)
sha256 = Digest::SHA256.digest(conte... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/client.rb | Ruby | mit | 44 | main | 5,579 | require "httpx"
require "json"
# This wraps the API described here:
# https://sandbox.zatca.gov.sa/IntegrationSandbox
class ZATCA::Client
attr_accessor :before_submitting_request, :before_parsing_response
# API URLs are not present in developer portal, they can only be found in a PDF
# called Fatoora Portal Use... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/tags.rb | Ruby | mit | 44 | main | 1,153 | require "base64"
module ZATCA
class Tags
def initialize(tags)
keys_to_coerce_to_string = tags.except(:timestamp).keys
stringified_tags = tags.map do |key, value|
if keys_to_coerce_to_string.include?(key)
[key, value.to_s]
else
[key, value]
end
end.to_... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/qr_code_generator.rb | Ruby | mit | 44 | main | 550 | require "rqrcode"
module ZATCA
class QRCodeGenerator
def initialize(tags: nil, base64: nil)
@tags = tags
@base64 = base64
end
def render(size: 256)
qr_code = generate
qr_code.as_png(size: size, border_modules: 2)&.to_data_url
end
private
def generate
if @tags... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/tags_schema.rb | Ruby | mit | 44 | main | 760 | require "dry-schema"
module ZATCA
TagsSchema = Dry::Schema.Params do
required(:seller_name).filled(:string)
required(:vat_registration_number).filled(:string)
required(:timestamp).filled([:date_time, :string])
# Using strings to avoid any floating point approximations, we're not doing
# any cal... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/tag.rb | Ruby | mit | 44 | main | 863 | module ZATCA
class Tag
TAG_IDS = {
seller_name: 1,
vat_registration_number: 2,
timestamp: 3,
invoice_total: 4,
vat_total: 5,
xml_invoice_hash: 6,
ecdsa_signature: 7,
ecdsa_public_key: 8,
ecdsa_stamp_signature: 9 # TODO: is this needed ?
}.freeze
PHASE... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/signing/certificate.rb | Ruby | mit | 44 | main | 2,479 | class ZATCA::Signing::Certificate
attr_accessor :serial_number, :issuer_name, :cert_content_without_headers,
:hash, :public_key, :public_key_without_headers, :signature,
:public_key_bytes
# Returns the certificate hashed with SHA256 then Base64 encoded
def self.generate_base64_hash(base64_certificate)
... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/signing/ecdsa.rb | Ruby | mit | 44 | main | 1,803 | require "starkbank-ecdsa"
class ZATCA::Signing::ECDSA
def self.sign(content:, private_key: nil, private_key_path: nil, decode_from_base64: false)
private_key = parse_private_key(key: private_key, key_path: private_key_path, decode_from_base64: decode_from_base64)
ecdsa_signature = EllipticCurve::Ecdsa.sign(... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/signing/csr.rb | Ruby | mit | 44 | main | 6,582 | class ZATCA::Signing::CSR
attr_reader :key, :csr_options, :mode
# For security purposes, please provide your own private key.
# If you don't provide one, a new unsecure one will be generated for testing purposes.
def initialize(
csr_options:,
mode: :production,
private_key_path: nil,
private_ke... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/base_component.rb | Ruby | mit | 44 | main | 4,019 | require "dry-initializer"
require_relative "../types"
class ZATCA::UBL::BaseComponent
extend Dry::Initializer
attr_accessor :elements, :attributes, :name, :value, :index
# def self.guard_dig(obj)
# unless obj.respond_to?(:dig)
# raise TypeError, "#{obj.class.name} does not have #dig method"
# end
... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/builder.rb | Ruby | mit | 44 | main | 6,055 | class ZATCA::UBL::Builder
extend Dry::Initializer
option :element, type: ZATCA::Types.Instance(ZATCA::UBL::BaseComponent)
def build(
canonicalized: false,
spaces: 4,
apply_invoice_hacks: false,
remove_root_xml_tag: false
)
@remove_root_xml_tag = remove_root_xml_tag
builder = Nokogiri:... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/invoice_subtype_builder.rb | Ruby | mit | 44 | main | 1,517 | module ZATCA::UBL::InvoiceSubtypeBuilder
extend self
# Builds the invoice subtype code based on the provided parameters.
#
# @param simplified [Boolean] Specifies whether the invoice is a simplified tax invoice.
# @param third_party [Boolean] Specifies whether the invoice is a third-party invoice transaction... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/invoice.rb | Ruby | mit | 44 | main | 16,663 | class ZATCA::UBL::Invoice < ZATCA::UBL::BaseComponent
TYPES = {
invoice: "388",
debit: "383",
credit: "381"
}.freeze
PAYMENT_MEANS = {
cash: "10",
credit: "30",
bank_account: "42",
bank_card: "48"
}.freeze
attr_reader :signed_hash
attr_reader :signed_hash_bytes
attr_reader :p... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/ubl_extensions.rb | Ruby | mit | 44 | main | 291 | class ZATCA::UBL::Signing::UBLExtensions < ZATCA::UBL::BaseComponent
def initialize(signature:)
super()
@signature = signature
end
def name
"ext:UBLExtensions"
end
def elements
[
ZATCA::UBL::Signing::UBLExtension.new(signature: @signature)
]
end
end |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/invoice_signed_data_reference.rb | Ruby | mit | 44 | main | 1,392 | class ZATCA::UBL::Signing::InvoiceSignedDataReference < ZATCA::UBL::BaseComponent
attr_accessor :digest_value
def initialize(digest_value:)
super()
@digest_value = digest_value
end
def name
"ds:Reference"
end
def attributes
{
"Id" => "invoiceSignedData",
"URI" => ""
}
en... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/signed_properties.rb | Ruby | mit | 44 | main | 3,502 | class ZATCA::UBL::Signing::SignedProperties < ZATCA::UBL::BaseComponent
def initialize(
signing_time:,
cert_digest_value:,
cert_issuer_name:,
cert_serial_number:
)
super()
@signing_time = signing_time
@cert_digest_value = cert_digest_value
@cert_issuer_name = cert_issuer_name
@c... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/ubl_document_signatures.rb | Ruby | mit | 44 | main | 643 | class ZATCA::UBL::Signing::UBLDocumentSignatures < ZATCA::UBL::BaseComponent
def initialize(signature:)
super()
@signature = signature
end
def name
"sig:UBLDocumentSignatures"
end
def attributes
{
"xmlns:sig" => "urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/signed_signature_properties.rb | Ruby | mit | 44 | main | 780 | class ZATCA::UBL::Signing::SignedSignatureProperties < ZATCA::UBL::BaseComponent
def initialize(signing_time:, cert_digest_value:, cert_issuer_name:, cert_serial_number:)
super()
@signing_time = signing_time
@cert_digest_value = cert_digest_value
@cert_issuer_name = cert_issuer_name
@cert_serial_... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/object.rb | Ruby | mit | 44 | main | 605 | class ZATCA::UBL::Signing::Object < ZATCA::UBL::BaseComponent
def initialize(signing_time:, cert_digest_value:, cert_issuer_name:, cert_serial_number:)
super()
@signing_time = signing_time
@cert_digest_value = cert_digest_value
@cert_issuer_name = cert_issuer_name
@cert_serial_number = cert_seria... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/key_info.rb | Ruby | mit | 44 | main | 1,869 | class ZATCA::UBL::Signing::KeyInfo < ZATCA::UBL::BaseComponent
# <ds:KeyInfo>
# <ds:X509Data>
# <ds:X509Certificate>MIID9jCCA5ugAwIBAgITbwAAeCy9aKcLA99HrAABAAB4LDAKBggqhkjOPQQDAjBjMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRwwGgYDVQQDExNUU1pFSU5WT0lDRS1TdWJD... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/cert.rb | Ruby | mit | 44 | main | 1,602 | class ZATCA::UBL::Signing::Cert < ZATCA::UBL::BaseComponent
# <xades:Cert>
# <xades:CertDigest>
# <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
# <ds:DigestValue>NjlhOTVmYzIzN2I0MjcxNGRjNDQ1N2EzM2I5NGNjNDUyZmQ5ZjExMDUwNGM2ODNjNDAxMTQ0ZDk1NDQ4OTRmYg==</ds:DigestValue>
# </x... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/qualifying_properties.rb | Ruby | mit | 44 | main | 758 | class ZATCA::UBL::Signing::QualifyingProperties < ZATCA::UBL::BaseComponent
def initialize(signing_time:, cert_digest_value:, cert_issuer_name:, cert_serial_number:)
super()
@signing_time = signing_time
@cert_digest_value = cert_digest_value
@cert_issuer_name = cert_issuer_name
@cert_serial_numbe... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/signed_info.rb | Ruby | mit | 44 | main | 789 | class ZATCA::UBL::Signing::SignedInfo < ZATCA::UBL::BaseComponent
def initialize(invoice_digest:, signed_properties_hash:)
super()
@invoice_digest = invoice_digest
@signed_properties_hash = signed_properties_hash
end
def name
"ds:SignedInfo"
end
def elements
[
ZATCA::UBL::BaseComp... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/signature.rb | Ruby | mit | 44 | main | 1,399 | class ZATCA::UBL::Signing::Signature < ZATCA::UBL::BaseComponent
attr_reader :signing_time, :cert_digest_value, :cert_issuer_name, :cert_serial_number
def initialize(
invoice_hash:, signed_properties_hash:, signature_value:,
certificate:, signing_time:, cert_digest_value:, cert_issuer_name:,
cert_seria... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/signature_information.rb | Ruby | mit | 44 | main | 498 | class ZATCA::UBL::Signing::SignatureInformation < ZATCA::UBL::BaseComponent
def initialize(signature:)
super()
@signature = signature
end
def name
"sac:SignatureInformation"
end
def elements
[
ZATCA::UBL::BaseComponent.new(name: "cbc:ID", value: "urn:oasis:names:specification:ubl:sign... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/signature_properties_reference.rb | Ruby | mit | 44 | main | 638 | class ZATCA::UBL::Signing::SignaturePropertiesReference < ZATCA::UBL::BaseComponent
attr_accessor :digest_value
def initialize(digest_value:)
super()
@digest_value = digest_value
end
def name
"ds:Reference"
end
def attributes
{
"Type" => "http://www.w3.org/2000/09/xmldsig#SignatureP... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/signing/ubl_extension.rb | Ruby | mit | 44 | main | 526 | class ZATCA::UBL::Signing::UBLExtension < ZATCA::UBL::BaseComponent
def initialize(signature:)
super()
@signature = signature
end
def name
"ext:UBLExtension"
end
def elements
[
ZATCA::UBL::BaseComponent.new(name: "ext:ExtensionURI", value: "urn:oasis:names:specification:ubl:dsig:envel... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/party.rb | Ruby | mit | 44 | main | 633 | class ZATCA::UBL::CommonAggregateComponents::Party < ZATCA::UBL::BaseComponent
# Has:
# PartyIdentification
# PostalAddress
# PartyTaxScheme
# PartyLegalEntity
def initialize(party_identification:, postal_address:, party_tax_scheme:, party_legal_entity:)
super()
@party_identification = party_identi... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/classified_tax_category.rb | Ruby | mit | 44 | main | 667 | class ZATCA::UBL::CommonAggregateComponents::ClassifiedTaxCategory < ZATCA::UBL::BaseComponent
attr_reader :scheme_id, :id
def initialize(id: "S", percent: "15.00", tax_scheme_id: "VAT")
super()
@id = id
@percent = percent
@tax_scheme_id = tax_scheme_id
end
def name
"cac:ClassifiedTaxCate... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/invoice_line.rb | Ruby | mit | 44 | main | 2,138 | class ZATCA::UBL::CommonAggregateComponents::InvoiceLine < ZATCA::UBL::BaseComponent
# <cac:InvoiceLine>
# <cbc:ID>1</cbc:ID>
# <cbc:InvoicedQuantity unitCode="PCE">44.000000</cbc:InvoicedQuantity>
# <cbc:LineExtensionAmount currencyID="SAR">966.00</cbc:LineExtensionAmount>
# <cac:TaxTotal>
# <cbc:TaxAm... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/price.rb | Ruby | mit | 44 | main | 498 | class ZATCA::UBL::CommonAggregateComponents::Price < ZATCA::UBL::BaseComponent
def initialize(price_amount:, allowance_charge: nil, currency_id: "SAR")
super()
@price_amount = price_amount
@allowance_charge = allowance_charge
@currency_id = currency_id
end
def name
"cac:Price"
end
def e... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/tax_category.rb | Ruby | mit | 44 | main | 1,940 | class ZATCA::UBL::CommonAggregateComponents::TaxCategory < ZATCA::UBL::BaseComponent
attr_reader :id, :percent
# <cac:TaxCategory>
# <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5305">S</cbc:ID>
# <cbc:Percent>15.00</cbc:Percent>
# <cac:TaxScheme>
# <cbc:ID schemeAgen... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/allowance_charge.rb | Ruby | mit | 44 | main | 1,995 | class ZATCA::UBL::CommonAggregateComponents::AllowanceCharge < ZATCA::UBL::BaseComponent
attr_accessor :id, :charge_indicator, :allowance_charge_reason, :amount
# <cac:AllowanceCharge>
# <cbc:ID>1</cbc:ID>
# <cbc:ChargeIndicator>false</cbc:ChargeIndicator>
# <cbc:AllowanceChargeReason>discount</cbc:A... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/party_identification.rb | Ruby | mit | 44 | main | 528 | class ZATCA::UBL::CommonAggregateComponents::PartyIdentification < ZATCA::UBL::BaseComponent
attr_reader :scheme_id, :id
SCHEMA = Dry::Schema.Params do
required(:id).filled(:string)
required(:scheme_id).filled(:string)
end
def initialize(id:, scheme_id: "CRN")
super()
@id = id
@scheme_id ... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/party_legal_entity.rb | Ruby | mit | 44 | main | 398 | class ZATCA::UBL::CommonAggregateComponents::PartyLegalEntity < ZATCA::UBL::BaseComponent
attr_reader :scheme_id, :id
def initialize(registration_name:)
super()
@registration_name = registration_name
end
def name
"cac:PartyLegalEntity"
end
def elements
[
ZATCA::UBL::BaseComponent.b... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/delivery.rb | Ruby | mit | 44 | main | 690 | class ZATCA::UBL::CommonAggregateComponents::Delivery < ZATCA::UBL::BaseComponent
attr_reader :scheme_id, :id
def initialize(actual_delivery_date:, latest_delivery_date: nil)
super()
@latest_delivery_date = latest_delivery_date
@actual_delivery_date = actual_delivery_date
end
def name
"cac:De... |
github | mrsool/zatca | https://github.com/mrsool/zatca | lib/zatca/ubl/common_aggregate_components/party_tax_scheme.rb | Ruby | mit | 44 | main | 650 | class ZATCA::UBL::CommonAggregateComponents::PartyTaxScheme < ZATCA::UBL::BaseComponent
def initialize(
company_id: nil,
tax_scheme_id: "VAT"
)
super()
@company_id = company_id
@tax_scheme_id = tax_scheme_id
end
def name
"cac:PartyTaxScheme"
end
def company_id_element
return n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.