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
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/date_coercer.rb
Ruby
mit
20
main
829
# typed: strict require "date" module Typed module Coercion class DateCoercer < Coercer extend T::Generic Target = type_member { {fixed: Date} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) T::Utils.coerce(type) == T::Utils.coe...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/date_time_coercer.rb
Ruby
mit
20
main
857
# typed: strict require "date" module Typed module Coercion class DateTimeCoercer < Coercer extend T::Generic Target = type_member { {fixed: DateTime} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) T::Utils.coerce(type) == T::U...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/coercer_registry.rb
Ruby
mit
20
main
1,112
# typed: strict require "singleton" module Typed module Coercion class CoercerRegistry extend T::Sig include Singleton Registry = T.type_alias { T::Array[T.class_of(Coercer)] } DEFAULT_COERCERS = T.let( [ StringCoercer, SymbolCoercer, BooleanCoerc...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/float_coercer.rb
Ruby
mit
20
main
759
# typed: strict module Typed module Coercion class FloatCoercer < Coercer extend T::Generic Target = type_member { {fixed: Float} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) T::Utils.coerce(type) == T::Utils.coerce(Float) ...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/string_coercer.rb
Ruby
mit
20
main
626
# typed: strict module Typed module Coercion class StringCoercer < Coercer extend T::Generic Target = type_member { {fixed: String} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) type == T::Utils.coerce(String) end ...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/struct_coercer.rb
Ruby
mit
20
main
1,357
# typed: strict module Typed module Coercion class StructCoercer < Coercer extend T::Generic Target = type_member { {fixed: T::Struct} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) return false unless type.respond_to?(:raw_type...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/typed_hash_coercer.rb
Ruby
mit
20
main
1,634
# typed: strict module Typed module Coercion class TypedHashCoercer < Coercer extend T::Generic Target = type_member { {fixed: T::Hash[T.untyped, T.untyped]} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) type.is_a?(T::Types::Ty...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/typed_array_coercer.rb
Ruby
mit
20
main
1,170
# typed: strict module Typed module Coercion class TypedArrayCoercer < Coercer extend T::Generic Target = type_member { {fixed: T::Array[T.untyped]} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) type.is_a?(T::Types::TypedArray)...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/symbol_coercer.rb
Ruby
mit
20
main
813
# typed: strict module Typed module Coercion class SymbolCoercer < Coercer extend T::Generic Target = type_member { {fixed: Symbol} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) type == T::Utils.coerce(Symbol) end ...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/enum_coercer.rb
Ruby
mit
20
main
863
# typed: strict module Typed module Coercion class EnumCoercer < Coercer extend T::Generic Target = type_member { {fixed: T::Enum} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) return false unless type.respond_to?(:raw_type) ...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/coercer.rb
Ruby
mit
20
main
446
# typed: strict module Typed module Coercion class Coercer extend T::Sig extend T::Generic abstract! Target = type_member(:out) sig { abstract.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) end sig { abstract.params(type: T::Ty...
github
maxveldink/sorbet-schema
https://github.com/maxveldink/sorbet-schema
lib/typed/coercion/boolean_coercer.rb
Ruby
mit
20
main
859
# typed: strict module Typed module Coercion class BooleanCoercer < Coercer extend T::Generic Target = type_member { {fixed: T::Boolean} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def self.used_for_type?(type) type == T::Utils.coerce(T::Boolean) en...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
tram-policy.gemspec
Ruby
mit
19
master
970
Gem::Specification.new do |gem| gem.name = "tram-policy" gem.version = "2.2.0" gem.author = ["Viktor Sokolov (gzigzigzeo)", "Andrew Kozin (nepalez)"] gem.email = "andrew.kozin@gmail.com" gem.homepage = "https://github.com/tram-rb/tram-policy" gem.summary = "Policy Object Pattern" gem.license =...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/spec_helper.rb
Ruby
mit
19
master
642
require "bundler/setup" require "tram/policy" require "tram/policy/rspec" require "rspec/its" require_relative "support/fixtures_helper.rb" RSpec.configure do |config| config.example_status_persistence_file_path = ".rspec_status" config.expect_with :rspec do |c| c.syntax = :expect end config.order = :ran...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/tram/policy_spec.rb
Ruby
mit
19
master
4,332
RSpec.describe Tram::Policy do before do I18n.available_locales = %w[en] I18n.backend.store_translations :en, yaml_fixture_file("en.yml")["en"] load_fixture "user_policy.rb" load_fixture "admin_policy.rb" end let(:policy) { Test::UserPolicy[user] } let(:user) { double :user, name: name, emai...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/tram/policy/validation_error_spec.rb
Ruby
mit
19
master
827
RSpec.describe Tram::Policy::ValidationError do subject(:error) { described_class.new policy, filter } let(:one) { double message: "OMG!", level: "error" } let(:two) { double message: "phew!", level: "warning" } let(:policy) { double :policy, errors: [one, two] } shared_examples :exception_with_messa...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/tram/policy/errors_spec.rb
Ruby
mit
19
master
3,934
RSpec.describe Tram::Policy::Errors do let(:scope) { %w[tram-policy] } let(:errors) { described_class.new(scope: scope) } describe ".new" do subject { errors } it { is_expected.to be_kind_of Enumerable } it { is_expected.to respond_to :empty? } it { is_expected.to be_empty } its(:scope) { i...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/tram/policy/error_spec.rb
Ruby
mit
19
master
1,211
RSpec.describe Tram::Policy::Error do subject(:error) { described_class.new :bad, **options } let(:scope) { %w[tram-policy] } let(:options) { { level: "warning", scope: scope } } describe "#item" do subject { error.item } it { is_expected.to eq [:bad, level: "warning", scope: scope] } end descr...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/tram/policy/rspec_spec.rb
Ruby
mit
19
master
2,138
RSpec.describe "RSpec support:" do subject { Test::CustomerPolicy[name: nil] } before do I18n.available_locales = %i[en] I18n.backend.store_translations :en, yaml_fixture_file("en.yml")["en"] load_fixture "customer_policy.rb" end describe "to be_invalid_at" do it "passes when some translated e...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/tram/policy/inflector_spec.rb
Ruby
mit
19
master
397
RSpec.describe Tram::Policy::Inflector do let(:snake) { "test/admin2_user_new_policy" } let(:camel) { "Test::Admin2UserNewPolicy" } describe "#underscore" do subject { described_class.underscore "Test::Admin2USERNew-Policy" } it { is_expected.to eq snake } end describe "#camelize" do subject { d...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
spec/support/fixtures_helper.rb
Ruby
mit
19
master
233
def fixture_file_path(filename) File.expand_path "spec/fixtures/#{filename}" end def yaml_fixture_file(filename) YAML.load_file(fixture_file_path(filename)) end def load_fixture(filename) load fixture_file_path(filename) end
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy.rb
Ruby
mit
19
master
2,862
require "dry-initializer" require "i18n" # Top-level scope for Tram collection of gems module Tram # Base class for policy objects with composable validation errors class Policy require_relative "policy/validation_error" require_relative "policy/inflector" require_relative "policy/error" require_re...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/validator.rb
Ruby
mit
19
master
787
class Tram::Policy # @private class Validator attr_reader :name, :block, :stop_on_failure def ==(other) other.is_a?(self.class) && name && other.name == name end def check(object) name ? object.__send__(name) : object.instance_exec(&block) end private def initialize(name,...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/validation_error.rb
Ruby
mit
19
master
473
class Tram::Policy # An exception to be risen by [Tram::Policy#validate!] class ValidationError < RuntimeError # Policy object whose validation has caused the exception # # @return [Tram::Policy] # attr_reader :policy private def initialize(policy, filter) @policy = policy ...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/inflector.rb
Ruby
mit
19
master
724
class Tram::Policy if Object.const_defined? "ActiveSupport::Inflector" # @private Inflector = ActiveSupport::Inflector elsif Object.const_defined? "Inflecto" # @private Inflector = ::Inflecto else # @private module Inflector def self.underscore(name) name&.dup&.tap do |n| ...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/dsl.rb
Ruby
mit
19
master
1,663
class Tram::Policy # Class-level DSL for policy objects module DSL # @!method validate(name, opts) # Registers a validator # # @param [#to_sym, nil] name (nil) # @option opts [Boolean] :stop_on_failure # @return [self] # def validate(name = nil, **opts, &block) local_validator...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/generator.rb
Ruby
mit
19
master
3,781
require "thor/group" require "i18n" module Tram class Policy require_relative "inflector" # @private class Generator < Thor::Group include Thor::Actions desc "Generates new policy class along with its specification" argument :name, desc: "policy class name", type: :string class_...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/rspec.rb
Ruby
mit
19
master
2,038
require "rspec" RSpec::Matchers.define :be_invalid_at do |**tags| def locales @locales ||= I18n.available_locales end def check(policy, tags) @errors ||= policy.errors.filter(**tags).map do |error| { item: error.item }.tap do |obj| locales.each { |l| obj[l] = I18n.with_locale(l) { error.me...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/errors.rb
Ruby
mit
19
master
3,004
class Tram::Policy # # Enumerable collection of unique unordered validation errors # # Notice: A collection is context-dependent; # it knows about a scope of policy it belongs to, # and how to translate error messages in that scope. # class Errors include Enumerable # @!attribut...
github
tram-rb/tram-policy
https://github.com/tram-rb/tram-policy
lib/tram/policy/error.rb
Ruby
mit
19
master
2,774
class Tram::Policy # Validation error with message and assigned tags # # Notice: an error is context-independent; it knows nothing about # a collection it is placed to; it can be safely moved # from one collection of [Tram::Policy::Errors] to another. # class Error # @!method self.new(...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
normalizy.gemspec
Ruby
mit
19
master
1,066
# frozen_string_literal: true require_relative 'lib/normalizy/version' Gem::Specification.new do |spec| spec.author = 'Washington Botelho' spec.description = 'Attribute normalizer for Rails.' spec.email = 'wbotelhos@gmail.com' spec.extra_rdoc_files = Dir['CHANGELOG.md', 'LICENSE', 'R...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy.rb
Ruby
mit
19
master
338
# frozen_string_literal: true module Normalizy class << self def config @config ||= Config.new end def configure yield config end end end require 'active_record' require 'normalizy/config' require 'normalizy/extensions' require 'normalizy/rspec/matcher' ActiveRecord::Base.include Nor...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/config.rb
Ruby
mit
19
master
767
# frozen_string_literal: true require 'normalizy/filters' module Normalizy class Config attr_accessor :default_filters attr_reader :filters, :normalizy_aliases def add(name, value) @filters[name] = value self end def alias(name, to) @normalizy_aliases[name] = to self ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/extensions.rb
Ruby
mit
19
master
3,040
# frozen_string_literal: true module Normalizy module Extension extend ActiveSupport::Concern included do private def extract_filter(rule, rule_options, attribute, filters: Normalizy.config.filters) options = rule_options.merge(attribute: attribute, object: self) return [filter...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/number.rb
Ruby
mit
19
master
372
# frozen_string_literal: true module Normalizy module Filters module Number def self.call(input, options = {}) return input unless input.is_a?(String) value = input.gsub(/\D/, '') return nil if value.blank? return value.send(options[:cast]) if option...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/strip.rb
Ruby
mit
19
master
384
# frozen_string_literal: true module Normalizy module Filters module Strip def self.call(input, options = {}) return input unless input.is_a?(String) regex = { both: '\A\s*|\s*\z', left: '\A\s*', right: '\s*\z', }[options[:side] || :both] in...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/money.rb
Ruby
mit
19
master
1,130
# frozen_string_literal: true module Normalizy module Filters module Money class << self def call(input, options = {}) return input unless input.is_a?(String) value = input.gsub(/[^[0-9-]#{separator(options)}]/, '') return nil if value.blank? if cents?(opt...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/percent.rb
Ruby
mit
19
master
1,135
# frozen_string_literal: true module Normalizy module Filters module Percent class << self def call(input, options = {}) return input unless input.is_a?(String) value = input.gsub(/[^[0-9]#{separator(options)}]/, '') return nil if value.blank? if cents?(op...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/date.rb
Ruby
mit
19
master
1,177
# frozen_string_literal: true module Normalizy module Filters module Date class << self def call(input, options = {}) if input.is_a?(String) return input if input.blank? Time.use_zone(time_zone(options)) do input = Time.zone.strptime(input, format(op...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/truncate.rb
Ruby
mit
19
master
314
# frozen_string_literal: true module Normalizy module Filters module Truncate module_function def call(input, options = {}) return input unless options[:limit].is_a?(Integer) return input unless input.is_a?(String) input[0, options[:limit]] end end end end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/filters/slug.rb
Ruby
mit
19
master
260
# frozen_string_literal: true module Normalizy module Filters module Slug class << self def call(input, _options = {}) return input unless input.is_a?(String) input.parameterize end end end end end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/normalizy/rspec/matcher.rb
Ruby
mit
19
master
2,589
# frozen_string_literal: true module Normalizy module RSpec def normalizy(attribute) Matcher.new attribute end class Matcher def initialize(attribute) @attribute = attribute end def description return "normalizy #{@attribute} with #{with_expected}" if @with.prese...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
lib/generators/normalizy/install_generator.rb
Ruby
mit
19
master
320
# frozen_string_literal: true module Normalizy class InstallGenerator < Rails::Generators::Base source_root File.expand_path('templates', __dir__) desc 'creates an initializer' def copy_initializer copy_file 'config/initializers/normalizy.rb', 'config/initializers/normalizy.rb' end end end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/common_helper.rb
Ruby
mit
19
master
277
# frozen_string_literal: true ENV['RAILS_ENV'] ||= 'test' require 'support/coverage' require 'normalizy' require 'debug' require 'support/db/schema' require 'support/filters/blacklist' require 'support/filters/block' require 'support/filters/info' require 'support/models'
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/rspec/matcher/matches_spec.rb
Ruby
mit
19
master
2,328
# frozen_string_literal: true RSpec.describe Normalizy::RSpec::Matcher, '.matches?' do let!(:object) { Match.new } it do matcher = described_class.new(:alone) matcher.matches?(object) expect(matcher.instance_variable_get(:@subject)).to eq object end context 'when .with is called' do it do ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/rspec/matcher/to_spec.rb
Ruby
mit
19
master
364
# frozen_string_literal: true RSpec.describe Normalizy::RSpec::Matcher, '.to' do it 'caches the value' do matcher = described_class.new(:downcase) matcher.to :to expect(matcher.instance_variable_get(:@to)).to eq :to end it 'returns it self' do matcher = described_class.new(:downcase) expe...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/rspec/matcher/description_spec.rb
Ruby
mit
19
master
541
# frozen_string_literal: true RSpec.describe Normalizy::RSpec::Matcher, '.description' do let!(:matcher) { described_class.new :name } context 'with no :with expectation' do it do matcher.from :from matcher.to :to expect(matcher.description).to eq 'normalizy name from "from" to "to"' ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/rspec/matcher/from_spec.rb
Ruby
mit
19
master
390
# frozen_string_literal: true RSpec.describe Normalizy::RSpec::Matcher, '.from' do it 'caches the value' do matcher = described_class.new(:downcase_field) matcher.from :from expect(matcher.instance_variable_get(:@from)).to eq :from end it 'returns it self' do matcher = described_class.new(:dow...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/rspec/matcher/failure_message_spec.rb
Ruby
mit
19
master
1,115
# frozen_string_literal: true RSpec.describe Normalizy::RSpec::Matcher, '.failure_message' do let!(:model) { Match } context 'with no :with expectation' do it do matcher = described_class.new(:downcase_field) matcher.from :from matcher.to :to matcher.matches? model.new expect(m...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/rspec/matcher/failure_message_when_negated_spec.rb
Ruby
mit
19
master
735
# frozen_string_literal: true RSpec.describe Normalizy::RSpec::Matcher, '.failure_message_when_negated' do let!(:model) { Match } context 'with no :with expectation' do it do matcher = described_class.new(:downcase_field) matcher.from 'from' matcher.to 'from' matcher.matches? model....
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/normalizy/configure_spec.rb
Ruby
mit
19
master
224
# frozen_string_literal: true RSpec.describe Normalizy, '#configure' do it 'yields the default config' do described_class.configure do |conf| expect(conf).to be_a_instance_of Normalizy::Config end end end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/model_spec.rb
Ruby
mit
19
master
2,585
# frozen_string_literal: true RSpec.describe '#apply_normalizy' do context 'when object has no normalizy' do it do expect(Model.create(none: ' Botelho ').none).to eq ' Botelho ' end end context 'when object has normalizy' do it do Normalizy.configure do |config| config.defaul...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/normalizy_rules_spec.rb
Ruby
mit
19
master
5,813
# frozen_string_literal: true RSpec.describe Normalizy::Extension, ':normalizy_rules' do let!(:model) { Rule } before { model.normalizy_rules = {} } context 'with default' do before do Normalizy.configure do |config| config.default_filters = :squish end end it do model.no...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/filters/strip_spec.rb
Ruby
mit
19
master
522
# frozen_string_literal: true RSpec.describe ModelStrip, 'filters:strip' do it do expect(described_class.create(strip: ' Botelho ').strip).to eq 'Botelho' end it do expect(described_class.create(strip_side_left: ' Botelho ').strip_side_left).to eq 'Botelho ' end it do expect(described_clas...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/filters/date_spec.rb
Ruby
mit
19
master
873
# frozen_string_literal: true RSpec.describe ModelDate, 'filters:date' do it { expect(described_class.create(date: '1984-10-23').date).to eq(Time.new(1984, 10, 23, 0, 0, 0, 0)) } it { expect(described_class.create(date_format: '84/10/23').date_format).to eq(Time.new(1984, 10, 23, 0, 0, 0, 0)) } it do hours ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/filters/slug_spec.rb
Ruby
mit
19
master
338
# frozen_string_literal: true RSpec.describe ModelSlug, 'filters:slug' do from = 'The Títle' to = 'the-title' it { expect(described_class.create(permalink: from).permalink).to eq to } it { expect(described_class.create(title: from).slug).to eq to } it { expect(described_class.create(title: from).title)....
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/filters/money_spec.rb
Ruby
mit
19
master
1,384
# frozen_string_literal: true RSpec.describe ModelMoney, 'filters:money' do it do expect(described_class.create(text: '$ 42.00').text).to eq '42.00' expect(described_class.create(text: '$ 42.10').text).to eq '42.10' expect(described_class.create(text: '$ -42.00').text).to eq '-42.00' expect(describe...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/extensions/filters/percent_spec.rb
Ruby
mit
19
master
769
# frozen_string_literal: true RSpec.describe ModelPercent, 'filters:percent' do it do expect(described_class.create(text: '42.00 %').text).to eq '42.00' expect(described_class.create(text: '42.10 %').text).to eq '42.10' end it do expect(described_class.create(cents_type: '42.33 %').cents_type).to eq...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/slug_spec.rb
Ruby
mit
19
master
736
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Slug do describe 'default options' do it { expect(subject.call(nil)).to be(nil) } it { expect(subject.call('')).to eq '' } it { expect(subject.call('The Title')).to eq 'the-title' } end describe 'to' do it { expect(subject.call(n...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/number_spec.rb
Ruby
mit
19
master
1,922
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Number do context 'with no cast' do it { expect(subject.call('abcdefghijklmnopkrstuvxyz')).to be(nil) } it { expect(subject.call('ABCDEFGHIJKLMNOPKRSTUVXYZ')).to be(nil) } it { expect(subject.call('áéíóúàâêôãõ')).to be(nil) } ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/date_spec.rb
Ruby
mit
19
master
2,390
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Date do it { expect(subject.call('')).to eq '' } it { expect(subject.call('1984-10-23')).to eq Time.new(1984, 10, 23, 0, 0, 0, 0) } it { expect(subject.call('84/10/23', format: '%y/%m/%d')).to eq Time.new(1984, 10, 23, 0, 0, 0, 0) } it { expec...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/money_spec.rb
Ruby
mit
19
master
14,788
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Money do describe 'default options' do it { expect(subject.call('')).to be(nil) } it { expect(subject.call(1)).to be 1 } it { expect(subject.call(1.70)).to be 1.70 } it { expect(subject.call(103.70)).to be 103.70 } ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/percent_spec.rb
Ruby
mit
19
master
7,895
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Percent do describe 'default options' do it { expect(subject.call('')).to be(nil) } it { expect(subject.call(1)).to be 1 } it { expect(subject.call(1.70)).to be 1.70 } it { expect(subject.call(103.70)).to be 103.70 } i...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/strip_spec.rb
Ruby
mit
19
master
622
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Strip do it { expect(subject.call(' Some Text ')).to eq 'Some Text' } it { expect(subject.call(' Some Text ', side: :left)).to eq 'Some Text ' } it { expect(subject.call(' Some Text ', side: :right)).to eq ' Some Text' ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/filters/truncate_spec.rb
Ruby
mit
19
master
542
# frozen_string_literal: true RSpec.describe Normalizy::Filters::Truncate do context 'when :limit options is not given' do it { expect(subject.call('miss')).to eq 'miss' } end context 'when :limit options is not a number' do it { expect(subject.call('miss', limit: 'wrong')).to eq 'miss' } end conte...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/config/alias_spec.rb
Ruby
mit
19
master
699
# frozen_string_literal: true RSpec.describe Normalizy::Config, '#alias' do it 'accepts alias' do Normalizy.configure do |config| config.alias :email, :downcase end expect(Alias.create(email: 'Botelho').email).to eq 'botelho' end it 'accepts alias with options' do Normalizy.configure do |...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/config/default_filters_spec.rb
Ruby
mit
19
master
386
# frozen_string_literal: true RSpec.describe Normalizy::Config, 'default_filters' do context 'when get' do it 'returns the default filters' do expect(subject.default_filters).to eq({}) end end context 'when set' do before { subject.default_filters = :blank } it 'keeps the original' do ...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/config/initialize_spec.rb
Ruby
mit
19
master
456
# frozen_string_literal: true RSpec.describe Normalizy::Config, 'filters' do it 'loads some filters' do expect(subject.filters).to eq( date: Normalizy::Filters::Date, money: Normalizy::Filters::Money, number: Normalizy::Filters::Number, percent: Normalizy::Filters::Percent, sl...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/normalizy/config/add_spec.rb
Ruby
mit
19
master
621
# frozen_string_literal: true RSpec.describe Normalizy::Config, '#add' do it 'adds filters to the built-in filters' do Normalizy.configure do |config| config.add :blacklist, :blacklist_filter end expect(Normalizy.config.filters).to eq( blacklist: :blacklist_filter, date: Normalizy...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models.rb
Ruby
mit
19
master
377
# frozen_string_literal: true require 'support/models/alias' require 'support/models/match' require 'support/models/model' require 'support/models/model_date' require 'support/models/model_money' require 'support/models/model_number' require 'support/models/model_percent' require 'support/models/model_slug' require 's...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/coverage.rb
Ruby
mit
19
master
368
# frozen_string_literal: true if ENV['COVERAGE'] == 'true' require 'simplecov' require 'codecov' SimpleCov.formatter = SimpleCov::Formatter::Codecov SimpleCov.minimum_coverage(ENV.fetch('MINIMUM_COVERAGE', 80).to_i) SimpleCov.start('rails') do add_filter [ '/lib/generators', '/lib/normaliz...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/model_percent.rb
Ruby
mit
19
master
464
# frozen_string_literal: true class ModelPercent < ActiveRecord::Base normalizy :text, with: :percent normalizy :cents_type, with: { percent: { type: :cents } } normalizy :cast_to_i, with: { percent: { cast: :to_i } } normalizy :cast_to_d, with: { percent: { cast: :to_d } } normalizy :cents_type_and_cast_to_...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/alias.rb
Ruby
mit
19
master
225
# frozen_string_literal: true class Alias < ActiveRecord::Base normalizy :email, with: :email normalizy :with_arg_field, with: :with_arg normalizy :with_inline_arg_field, with: { with_inline_arg: { side: :left } } end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/model.rb
Ruby
mit
19
master
1,013
# frozen_string_literal: true class Model < ActiveRecord::Base normalizy :default normalizy :block, with: ->(value) { value.upcase } normalizy :symbol, with: :squish normalizy :array_symbol, with: [:squish] normalizy :array_symbols, with: %i[downcase squish] normalizy :hash_no_args, with: { squish: { igno...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/match.rb
Ruby
mit
19
master
315
# frozen_string_literal: true class Match < ActiveRecord::Base normalizy :alone normalizy :downcase_field, with: :downcase normalizy :trim_side_left, with: { trim: { side: :left } } normalizy :trim_side_left_array, with: [{ trim: { side: :left } }] normalizy :downcase_field_array, with: [:downcase] end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/model_strip.rb
Ruby
mit
19
master
297
# frozen_string_literal: true class ModelStrip < ActiveRecord::Base normalizy :strip, with: :strip normalizy :strip_side_both, with: { strip: { side: :both } } normalizy :strip_side_left, with: { strip: { side: :left } } normalizy :strip_side_right, with: { strip: { side: :right } } end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/model_money.rb
Ruby
mit
19
master
450
# frozen_string_literal: true class ModelMoney < ActiveRecord::Base normalizy :text, with: :money normalizy :cents_type, with: { money: { type: :cents } } normalizy :cast_to_i, with: { money: { cast: :to_i } } normalizy :cast_to_d, with: { money: { cast: :to_d } } normalizy :cents_type_and_cast_to_f, with: {...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/models/model_date.rb
Ruby
mit
19
master
383
# frozen_string_literal: true class ModelDate < ActiveRecord::Base normalizy :date, with: :date normalizy :date_format, with: { date: { format: '%y/%m/%d' } } normalizy :date_time_begin, with: { date: { adjust: :begin } } normalizy :date_time_end, with: { date: { adjust: :end } } normalizy :...
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/filters/info.rb
Ruby
mit
19
master
221
# frozen_string_literal: true module Normalizy module Filters module Info def self.call(input, options = {}) [options[:attribute], input, options[:object].class].join ', ' end end end end
github
wbotelhos/normalizy
https://github.com/wbotelhos/normalizy
spec/support/db/schema.rb
Ruby
mit
19
master
1,882
# frozen_string_literal: true ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:' ActiveRecord::Schema.define(version: 0) do create_table :aliases do |t| t.string :email t.string :with_arg_field t.string :with_inline_arg_field end create_table :matches do |t| t.strin...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
Gemfile
Ruby
mit
19
master
323
source 'https://rubygems.org' # Cocoapods gem "motion-cocoapods", '1.3.0.rc1' gem "cocoapods" # RubyMotion gem 'bubble-wrap', :require => ['bubble-wrap/core', 'bubble-wrap/http', 'bubble-wrap/reactor'] gem 'ProMotion', :path => "../ProMotion/" # Rubygems gem "rake", '>= 0.9.4' # Development gem 'awesome_print_motio...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
Rakefile
Ruby
mit
19
master
1,570
# -*- coding: utf-8 -*- $:.unshift("/Library/RubyMotion/lib") require 'motion/project/template/ios' require 'bundler' Bundler.setup Bundler.require Motion::Project::App.setup do |app| app.name = "W-S Crime" app.identifier = "com.mohawkapps.Winston-Salem-Crime" app.frameworks += %w(CoreLocation MapKit QuartzCore ...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/app_delegate.rb
Ruby
mit
19
master
786
class AppDelegate < ProMotion::Delegate tint_color "#0F5D14".to_color def on_load(app, options) unless Device.simulator? NSSetUncaughtExceptionHandler("uncaughtExceptionHandler") Flurry.startSession("VNHHFKB2GK8BT22TPQRK") end Appirater.setAppId NSBundle.mainBundle.objectForInfoDictionary...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/class_extensions/UIWebView.rb
Ruby
mit
19
master
724
class UIWebView def removeShadow # Remove that dang shadow.from the UIWebView self.subviews.each do |web_scroll_view| if web_scroll_view.is_a?(UIScrollView) web_scroll_view.subviews.each do |scrollview_subview| if scrollview_subview.is_a?(UIImageView) scrollview_subview.image = nil if ...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/controllers/portraitnavigationcontroller.rb
Ruby
mit
19
master
651
# UINavigationController subclass to to help handle orientation changes, etc. class PortraitNavigationController < UINavigationController def supportedInterfaceOrientations # Only allow landscape if they're on an iPad if Device.iphone? UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortr...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/controllers/uiviewcontroller.rb
Ruby
mit
19
master
3,006
class UIViewController def setTitle(title, subtitle:subtitle) # standard title if subtitle.nil? self.title = title return end # FIXME: restart from scratch self.navigationItem.titleView = nil # FIXME: fixed color created = false titleView = self.navigationItem.title...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/screens/about_screen.rb
Ruby
mit
19
master
680
class AboutScreen < PM::WebScreen title "About" def content "AboutView.html" end def will_appear Flurry.logEvent "AboutScreen" unless Device.simulator? App::Persistence["seenAbout"] = "yes" @view_loaded ||= begin self.navigationController.navigationBar.barStyle = UIBarStyleBlack if Dev...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/screens/calendar_screen.rb
Ruby
mit
19
master
524
class CalendarScreen < ProMotion::Screen title "Select a Date:" def will_appear Flurry.logEvent "CalendarScreen" unless Device.simulator? @view_setup ||= begin set_nav_bar_right_button "Cancel", action: :close, type: UIBarButtonItemStyleDone self.navigationController.navigationBar.barStyle = UIBarStyl...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/screens/detail_screen.rb
Ruby
mit
19
master
2,735
class DetailScreen < PM::TableScreen attr_accessor :container, :data, :date def on_load @data.sort! {|a,b| a.sort_by <=> b.sort_by } end def will_appear Flurry.logEvent "DetailScreen" unless Device.simulator? @view_setup ||= begin self.setTitle("Details", subtitle:"for #{@date}") self...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/screens/map_screen.rb
Ruby
mit
19
master
8,062
class MapScreen < PM::MapScreen include BW::Reactor start_position latitude: 36.10, longitude: -80.26, radius: 4 title "Map" def on_load #Init instance values @theDate = NSDate.date #Set the application title self.setTitle("Crime Map", subtitle:"Winston-Salem, NC") #Setup the toolbar an...
github
OTGApps/WSCrime
https://github.com/OTGApps/WSCrime
app/models/crime_api.rb
Ruby
mit
19
master
406
class CrimeAPI APIURL = "http://crimestats.mohawkapps.com/nc/winston-salem/?date=" def self.dataForDate(date, &block) BW::HTTP.get(APIURL + date) do |response| json = nil error = nil if response.ok? json = BW::JSON.parse(response.body.to_str) else error = ...
github
bdainton/camptweet
https://github.com/bdainton/camptweet
Rakefile
Ruby
mit
19
master
609
# -*- ruby -*- require 'rubygems' require 'rake/testtask' require 'echoe' Echoe.new('camptweet') do |p| p.author = "Brian Dainton" p.summary = "A simple daemon that polls for updated Twitter statuses, Summize search results, and RSS/Atom feed items and posts them to a Campfire room." p.url = "http://g...
github
bdainton/camptweet
https://github.com/bdainton/camptweet
lib/camptweet.rb
Ruby
mit
19
master
284
require 'rubygems' require 'active_support' require 'time' require 'twitter' require 'tinder' require 'simple-rss' require 'open-uri' Dir[File.join(File.dirname(__FILE__), 'camptweet/**/*.rb')].sort.each { |lib| require lib } module Camptweet class Error < StandardError; end end
github
futurechimp/skinny_daemon_example
https://github.com/futurechimp/skinny_daemon_example
skinny_daemon_example.gemspec
Ruby
mit
19
master
2,028
# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{skinny_daemon_example} s.version = "0.0.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_t...
github
futurechimp/skinny_daemon_example
https://github.com/futurechimp/skinny_daemon_example
Rakefile
Ruby
mit
19
master
1,558
require 'rubygems' require 'rake' begin require 'jeweler' Jeweler::Tasks.new do |gem| gem.name = "skinny_daemon_example" gem.summary = %Q{An example of a skinny daemon } gem.description = %Q{Process daemonization with thin!} gem.email = "dave@netbook" gem.homepage = "http://github.com/futurechi...
github
futurechimp/skinny_daemon_example
https://github.com/futurechimp/skinny_daemon_example
test/helper.rb
Ruby
mit
19
master
232
require 'rubygems' require 'test/unit' require 'shoulda' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'skinny_daemon_example' class Test::Unit::TestCase end
github
futurechimp/skinny_daemon_example
https://github.com/futurechimp/skinny_daemon_example
test/test_skinny_daemon_example.rb
Ruby
mit
19
master
235
require 'helper' class TestSkinnyDaemonExample < Test::Unit::TestCase should "probably rename this file and start testing for real" do flunk "hey buddy, you should probably rename this file and start testing for real" end end
github
futurechimp/skinny_daemon_example
https://github.com/futurechimp/skinny_daemon_example
lib/skinny_daemon_example.rb
Ruby
mit
19
master
236
require 'rubygems' require 'sinatra/base' class SkinnyDaemonExample < Sinatra::Base get "/" do "Your skinny daemon is up and running." end post "/do-something/:great" do # something great could happen here end end
github
nodai2hITC/eturem
https://github.com/nodai2hITC/eturem
eturem.gemspec
Ruby
mit
19
main
1,206
require_relative 'lib/eturem/version' Gem::Specification.new do |spec| spec.name = "eturem" spec.version = Eturem::VERSION spec.authors = ["nodai2hITC"] spec.email = ["nodai2h.itc@gmail.com"] spec.summary = %q{Easy To Understand Ruby Error Message.} spec.description = ...
github
nodai2hITC/eturem
https://github.com/nodai2hITC/eturem
Rakefile
Ruby
mit
19
main
218
require "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new(:test) do |t| t.libs << "test" t.libs << "lib" t.test_files = FileList["test/**/*_test.rb"] t.warning = false end task :default => :test