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
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/pagination_generator_spec.rb
Ruby
mit
48
master
460
require 'spec_helper' describe Nazrin::PaginationGenerator do describe 'generate' do let(:paginated_array) do described_class.generate( [1, 2, 3], current_page: 1, per_page: 1, total_count: 3) end context 'nazrin' do it { expect(paginated_array.class).to eq Nazrin::PaginatedA...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/paginated_array_spec.rb
Ruby
mit
48
master
480
require 'spec_helper' describe Nazrin::PaginatedArray do let(:paginated_array) do described_class.new( [1, 2, 3], 1, 1, 3) end it { expect(paginated_array.first_page?).to eq true } it { expect(paginated_array.last_page?).to eq false } it { expect(paginated_array.total_pages).to eq 3 } it { expec...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/search_client_spec.rb
Ruby
mit
48
master
2,955
require 'spec_helper' describe Nazrin::SearchClient do let(:search_client) { described_class.new } before { search_client.data_accessor = Nazrin::DataAccessor::ActiveRecord.new(Post, {}) } it { expect(search_client).to be_respond_to :client } it { expect(search_client).to be_respond_to :parameters } it { e...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/data_accessor_spec.rb
Ruby
mit
48
master
270
require 'spec_helper' describe Nazrin::DataAccessor do describe 'register_accessor' do it { expect(described_class.register_accessor(Post)).to eq(Nazrin::DataAccessor::ActiveRecord) } it { expect(described_class.register_accessor(Hash)).to be_nil } end end
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/nazrin_spec.rb
Ruby
mit
48
master
572
require 'spec_helper' describe Nazrin do describe 'configure' do let(:config) { Nazrin.config } it { expect(config.debug_mode).to be false } it { expect(config.mode).to eq 'sandbox' } it { expect(config.search_endpoint).to eq 'http://search.com' } it { expect(config.document_endpoint).to eq 'http...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/active_record/searchable_spec.rb
Ruby
mit
48
master
4,340
require 'spec_helper' describe Nazrin::Searchable do let!(:post) { Post.create(content: 'content', created_at: Time.now) } it { expect(Post).to be_respond_to :search } it { expect(Post).to be_respond_to :fields } it { expect(Post).to be_respond_to :field } it { expect(post).to be_respond_to :add_to_index } ...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/struct/searchable_spec.rb
Ruby
mit
48
master
5,927
require 'spec_helper' require 'nazrin/data_accessor/struct/attribute_transformer' describe Nazrin::Searchable do let(:clazz) do Class.new do def self.name; 'CustomStruct'; end include Nazrin::Searchable attr_reader :attributes searchable_configure do |config| config.domain_name ...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/data_accessor/struct_spec.rb
Ruby
mit
48
master
532
require 'spec_helper' describe 'Nazrin::DataAccessor::Struct' do let(:clazz) do Class.new do def self.name; 'CustomStruct'; end include Nazrin::Searchable attr_reader :attributes searchable_configure do |config| config.domain_name = 'my-domain-name' end def initiali...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/data_accessor/mongoid_spec.rb
Ruby
mit
48
master
1,002
require 'spec_helper' describe 'Nazrin::DataAccessor::Mongoid' do let!(:user) { User.create(email: 'example@example.com', created_at: Time.now) } it { expect(User).to be_respond_to :search } describe '#search' do let(:response) { FakeResponse.new(user._id.to_s) } before do allow_any_instance_of(...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/nazrin/data_accessor/struct/attribute_transformer_spec.rb
Ruby
mit
48
master
2,307
require 'spec_helper' describe 'Nazrin::DataAccessor::Struct::AttributeTransformer' do let(:config) do Nazrin::Searchable::Configuration.new end let(:transformer) do Nazrin::DataAccessor::Struct::AttributeTransformer.new(config) end before do config.domain_name = 'my-domain-name' end descri...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
spec/db/migrate/0_create_posts.rb
Ruby
mit
48
master
226
class CreatePosts < ActiveRecord::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[5.0] : ActiveRecord::Migration def change create_table :posts do |t| t.string :content t.datetime :created_at end end end
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin.rb
Ruby
mit
48
master
315
require 'aws-sdk-cloudsearchdomain' require 'nazrin/searchable' require 'nazrin/searchable/config' require 'nazrin/data_accessor' require 'nazrin/config' require 'nazrin/search_client' require 'nazrin/document_client' require 'nazrin/pagination_generator' require 'nazrin/paginated_array' require 'nazrin/version'
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/generators/nazrin/config_generator.rb
Ruby
mit
48
master
329
module Nazrin module Generators class ConfigGenerator < Rails::Generators::Base source_root File.expand_path( File.join(File.dirname(__FILE__), 'templates')) desc 'Generate config' def config template 'nazrin_config.rb', 'config/initializers/nazrin_config.rb' end end ...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/generators/nazrin/templates/nazrin_config.rb
Ruby
mit
48
master
268
Nazrin.configure do |config| config.mode = :production # or sandbox (It does nothing with any requests to CloudSearch) config.search_endpoint = '' config.document_endpoint = '' config.region = '' config.access_key_id = '' config.secret_access_key = '' end
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/pagination_generator.rb
Ruby
mit
48
master
298
module Nazrin module PaginationGenerator class << self def generate(collection, options = {}) Nazrin::PaginatedArray.new( collection, options[:current_page], options[:per_page], options[:total_count] ) end end end end
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/searchable.rb
Ruby
mit
48
master
3,991
require 'active_support/concern' module Nazrin module Searchable class InvalidBatchOperationError < StandardError; end extend ActiveSupport::Concern included do alias_method :delete_from_index, :nazrin_delete_from_index unless method_defined? :delete_from_index alias_method :add_to_index, :...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/document_client.rb
Ruby
mit
48
master
2,292
module Nazrin class DocumentClient class InvalidBatchOperationError < StandardError; end attr_reader :client def initialize(config=Nazrin.config) @client = Aws::CloudSearchDomain::Client.new( endpoint: config.document_endpoint, region: config.region, access_key_id: config.a...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/search_client.rb
Ruby
mit
48
master
3,583
module Nazrin class SearchClientError < StandardError; end class SearchClient CLOUD_SEARCH_MAX_LIMIT = 10_000 attr_accessor :data_accessor attr_reader :client attr_reader :parameters def initialize(config=Nazrin.config) # @see http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudSearchDom...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/paginated_array.rb
Ruby
mit
48
master
947
module Nazrin class PaginatedArray < Array attr_reader :current_page, :per_page, :total_count def initialize(collection, page, per_page, total_count) @current_page = page @per_page = per_page @total_count = total_count replace collection end # first page of the collections? ...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/config.rb
Ruby
mit
48
master
517
require 'active_support/configurable' module Nazrin def self.config @config ||= Nazrin::Configuration.new end def self.configure yield config if block_given? end class Configuration include ActiveSupport::Configurable config_accessor :debug_mode config_accessor :mode config_accessor...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/data_accessor.rb
Ruby
mit
48
master
2,698
require 'nazrin/result' module Nazrin class DataAccessor class NoAccessorError < StandardError; end class << self def for(clazz) accessor = registered_accessor_for(clazz) || register_accessor(clazz) return accessor if accessor raise NoAccessorError, "No accessor for #{clazz.nam...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/data_accessor/struct.rb
Ruby
mit
48
master
1,088
require 'nazrin/data_accessor/struct/attribute_transformer' module Nazrin class DataAccessor class Struct < Nazrin::DataAccessor class MissingDomainNameConfigError < StandardError; end class << self attr_reader :config def [](config) Class.new(self).tap do |clazz| ...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/data_accessor/mongoid.rb
Ruby
mit
48
master
550
module Nazrin class DataAccessor class Mongoid < Nazrin::DataAccessor def load_all(ids) documents_table = {} relation = options.reduce(model) do |rel, send_args| rel.send(*send_args.compact) end relation.where('_id' => { '$in' => ids }).each do |document| ...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/data_accessor/active_record.rb
Ruby
mit
48
master
538
module Nazrin class DataAccessor class ActiveRecord < Nazrin::DataAccessor # load from activerecord def load_all(ids) records_table = {} relation = options.reduce(model) do |rel, (k, v)| rel.send(k, v) end relation.where(id: ids).each do |record| r...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/data_accessor/struct/attribute_transformer.rb
Ruby
mit
48
master
1,338
require 'aws-sdk-cloudsearch' module Nazrin class DataAccessor class Struct < Nazrin::DataAccessor class AttributeTransformer attr_reader :config, :cloudsearch_client private :config, :cloudsearch_client def initialize(config) @config = config @cloudsearch_clien...
github
tsuwatch/nazrin
https://github.com/tsuwatch/nazrin
lib/nazrin/searchable/config.rb
Ruby
mit
48
master
517
module Nazrin module Searchable class Configuration attr_accessor :domain_name, :attribute_transformer %i( search_endpoint document_endpoint region access_key_id secret_access_key logger ).each do |attr| class_eval <<-CODE, __FILE__, __LIN...
github
avdi/ivar
https://github.com/avdi/ivar
Gemfile
Ruby
mit
48
main
226
# frozen_string_literal: true source "https://rubygems.org" # Specify your gem's dependencies in ivar.gemspec gemspec gem "rake", "~> 13.0" gem "minitest", "~> 5.0" gem "standard", "~> 1.3" gem "solargraph", "~> 0.54.2"
github
avdi/ivar
https://github.com/avdi/ivar
ivar.gemspec
Ruby
mit
48
main
1,341
# frozen_string_literal: true require_relative "lib/ivar/version" Gem::Specification.new do |spec| spec.name = "ivar" spec.version = Ivar::VERSION spec.authors = ["Avdi Grimm"] spec.email = ["avdi@avdi.codes"] spec.summary = "A Ruby gem that automatically checks for typos in instance variables." spec.des...
github
avdi/ivar
https://github.com/avdi/ivar
Rakefile
Ruby
mit
48
main
293
# frozen_string_literal: true 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"].exclude("test/fixtures/**/*") end require "standard/rake" task default: %i[test standard]
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_with_kwarg_init.rb
Ruby
mit
48
main
6,551
# frozen_string_literal: true require_relative "test_helper" class TestIvarWithKwargInit < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache # Capture stderr to prevent warnings from appearing in test output @original_stderr = $stderr $stderr = StringIO...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_checked.rb
Ruby
mit
48
main
5,988
# frozen_string_literal: true require_relative "test_helper" class TestChecked < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_automatic_check_ivars # Create a class with a typo in an instance variable klass = Class.new do include...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_with_kwarg_init_inheritance.rb
Ruby
mit
48
main
4,192
# frozen_string_literal: true require "test_helper" class TestIvarWithKwargInitInheritance < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_ivar_with_kwarg_init_inheritance_defaults_and_overrides # Parent class with kwarg initialization and ...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_validation.rb
Ruby
mit
48
main
2,309
# frozen_string_literal: true require_relative "test_helper" require_relative "fixtures/sandwich_with_validation" class TestValidation < Minitest::Test def test_check_ivars_warns_about_unknown_variables # Capture stderr output warnings = capture_stderr do # Create a sandwich with validation which shou...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_project_root.rb
Ruby
mit
48
main
2,522
# frozen_string_literal: true require_relative "test_helper" require "fileutils" require "tmpdir" class TestProjectRoot < Minitest::Test def setup Ivar.project_root = nil # Create a temporary directory structure for testing @temp_dir = Dir.mktmpdir("ivar_test") # Create a nested directory structure...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_class_level_ivars.rb
Ruby
mit
48
main
5,565
# frozen_string_literal: true require_relative "test_helper" class TestClassLevelIvars < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_class_level_ivars_in_class_methods_do_not_trigger_warnings # Create a class with class-level instance var...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_warn_once_policy.rb
Ruby
mit
48
main
6,951
# frozen_string_literal: true require_relative "test_helper" class TestWarnOncePolicy < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_check_ivars_once_warns_on_first_call # Create a class with a typo in an instance variable klass = Clas...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_with_positional_init.rb
Ruby
mit
48
main
8,272
# frozen_string_literal: true require_relative "test_helper" class TestIvarWithPositionalInit < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_ivar_with_positional_init # Create a class with the ivar macro and init: :positional klass = C...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_checked_once_integration.rb
Ruby
mit
48
main
913
# frozen_string_literal: true require_relative "test_helper" require_relative "fixtures/sandwich_with_checked_once" class TestCheckedOnceIntegration < Minitest::Test def setup Ivar.clear_analysis_cache end def test_sandwich_with_checked_once warnings = capture_stderr do SandwichWithCheckedOnce.ne...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_with_positional_init_inheritance.rb
Ruby
mit
48
main
13,466
# frozen_string_literal: true require_relative "test_helper" class TestIvarWithPositionalInitInheritance < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_ivar_with_positional_init_inheritance # Create a parent class with positional initializ...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_helper.rb
Ruby
mit
48
main
334
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "ivar" require "stringio" require "minitest/autorun" # Helper method to capture stderr during a block def capture_stderr original_stderr = $stderr $stderr = StringIO.new yield $stderr.string ensure $stderr = origin...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_policies.rb
Ruby
mit
48
main
10,995
# frozen_string_literal: true require_relative "test_helper" require "logger" class TestPolicies < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_warn_policy # Create a class with a typo in an instance variable klass = Class.new do ...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_with_initial_values.rb
Ruby
mit
48
main
12,463
# frozen_string_literal: true require_relative "test_helper" class TestIvarWithInitialValues < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache # Capture stderr to prevent warnings from appearing in test output @original_stderr = $stderr $stderr = Stri...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar.rb
Ruby
mit
48
main
5,360
# frozen_string_literal: true require_relative "test_helper" require_relative "fixtures/sandwich" require_relative "fixtures/split_class" require_relative "fixtures/sandwich_with_validation" # These fixtures will be uncommented when the corresponding modules are implemented require_relative "fixtures/sandwich_with_ch...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_check_all.rb
Ruby
mit
48
main
2,319
# frozen_string_literal: true require "test_helper" require "open3" class TestCheckAll < Minitest::Test FIXTURES_PATH = File.expand_path("fixtures/check_all_project", __dir__) def setup Ivar.send(:disable_check_all) Ivar.clear_analysis_cache end def teardown Ivar.send(:disable_check_all) Iva...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_checked_integration.rb
Ruby
mit
48
main
2,013
# frozen_string_literal: true require_relative "test_helper" require_relative "fixtures/sandwich_with_checked_ivars" require_relative "fixtures/parent_with_checked_ivars" require_relative "fixtures/child_with_checked_ivars" class TestCheckedIntegration < Minitest::Test def setup # Clear the cache to ensure a cl...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_attr_methods.rb
Ruby
mit
48
main
3,869
# frozen_string_literal: true require_relative "test_helper" class TestIvarAttrMethods < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache # Capture stderr to prevent warnings from appearing in test output @original_stderr = $stderr $stderr = StringIO.n...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_class_method_ivars.rb
Ruby
mit
48
main
3,668
# frozen_string_literal: true require_relative "test_helper" class TestClassMethodIvars < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_class_method_ivars_do_not_trigger_warnings # Create a class with class methods that reference class-leve...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_macros.rb
Ruby
mit
48
main
4,788
# frozen_string_literal: true require_relative "test_helper" class TestMacros < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache # Capture stderr to prevent warnings from appearing in test output @original_stderr = $stderr $stderr = StringIO.new end ...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_inheritance.rb
Ruby
mit
48
main
9,458
# frozen_string_literal: true require_relative "test_helper" class TestInheritance < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_validation_inheritance capture_stderr do # Create a parent class with Validation parent_klass = C...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_targeted_prism_analysis.rb
Ruby
mit
48
main
4,106
# frozen_string_literal: true require_relative "test_helper" require_relative "../lib/ivar/targeted_prism_analysis" require_relative "fixtures/targeted_analysis/split_target_class" require_relative "fixtures/targeted_analysis/multi_class_file" require_relative "fixtures/targeted_analysis/mixed_methods_class" class Te...
github
avdi/ivar
https://github.com/avdi/ivar
test/test_ivar_with_positional_init_ordering.rb
Ruby
mit
48
main
10,346
# frozen_string_literal: true require_relative "test_helper" class TestIvarWithPositionalInitOrdering < Minitest::Test def setup # Clear the cache to ensure a clean test Ivar.clear_analysis_cache end def test_positional_args_ordering_within_class # Create a class with ivars declared in a specific o...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar.rb
Ruby
mit
48
main
6,407
# frozen_string_literal: true require_relative "ivar/version" require_relative "ivar/policies" require_relative "ivar/validation" require_relative "ivar/macros" require_relative "ivar/project_root" require_relative "ivar/check_all_manager" require_relative "ivar/check_policy" require_relative "ivar/checked" require_re...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/manifest.rb
Ruby
mit
48
main
4,306
# frozen_string_literal: true require_relative "declaration" require_relative "explicit_declaration" require_relative "explicit_keyword_declaration" require_relative "explicit_positional_declaration" module Ivar # Represents a manifest of instance variable declarations for a class/module class Manifest # @ret...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/checked.rb
Ruby
mit
48
main
1,197
# frozen_string_literal: true require_relative "validation" require_relative "macros" require_relative "check_policy" require_relative "checked/class_methods" require_relative "checked/instance_methods" module Ivar # Provides automatic validation for instance variables. # When included in a class, this module: ...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/policies.rb
Ruby
mit
48
main
6,520
# frozen_string_literal: true require "logger" module Ivar # Base class for all ivar checking policies class Policy # Handle unknown instance variables # @param unknown_refs [Array<Hash>] References to unknown instance variables # @param klass [Class] The class being checked # @param allowed_ivars...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/macros.rb
Ruby
mit
48
main
2,864
# frozen_string_literal: true module Ivar # Provides macros for working with instance variables module Macros # Special flag object to detect when a parameter is not provided UNSET = Object.new.freeze # When this module is extended, it adds class methods to the extending class def self.extended(ba...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/explicit_declaration.rb
Ruby
mit
48
main
1,912
# frozen_string_literal: true require_relative "declaration" require_relative "macros" module Ivar # Represents an explicit declaration from the ivar macro class ExplicitDeclaration < Declaration # Initialize a new explicit declaration # @param name [Symbol, String] The name of the instance variable #...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/project_root.rb
Ruby
mit
48
main
1,566
# frozen_string_literal: true require "pathname" module Ivar # Handles project root detection and caching class ProjectRoot # Project root indicator files, in order of precedence INDICATORS = %w[Gemfile .git .ruby-version Rakefile].freeze def initialize @cache = {} @mutex = Mutex.new ...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/targeted_prism_analysis.rb
Ruby
mit
48
main
4,238
# frozen_string_literal: true require "prism" module Ivar # Analyzes a class to find instance variable references in specific instance methods # Unlike PrismAnalysis, this targets only the class's own methods (not inherited) # and precisely locates instance variable references within each method definition cl...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/check_all_manager.rb
Ruby
mit
48
main
2,050
# frozen_string_literal: true require "pathname" module Ivar # Manages automatic inclusion of Ivar::Checked in classes and modules class CheckAllManager def initialize @trace_point = nil @mutex = Mutex.new end # Enables automatic inclusion of Ivar::Checked in all classes and modules #...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/declaration.rb
Ruby
mit
48
main
901
# frozen_string_literal: true module Ivar # Base class for all declarations class Declaration # @return [Symbol] The name of the instance variable attr_reader :name, :manifest # Initialize a new declaration # @param name [Symbol, String] The name of the instance variable def initialize(name, m...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/validation.rb
Ruby
mit
48
main
1,240
# frozen_string_literal: true require "did_you_mean" module Ivar # Provides validation for instance variables module Validation # Checks instance variables against class analysis # @param add [Array<Symbol>] Additional instance variables to allow # @param policy [Symbol, Policy] The policy to use for ...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/explicit_positional_declaration.rb
Ruby
mit
48
main
587
# frozen_string_literal: true require_relative "explicit_declaration" module Ivar # Represents an explicit declaration that initializes from positional arguments class ExplicitPositionalDeclaration < ExplicitDeclaration # Called before object initialization # @param instance [Object] The object being init...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/explicit_keyword_declaration.rb
Ruby
mit
48
main
843
# frozen_string_literal: true require_relative "explicit_declaration" module Ivar # Represents an explicit declaration that initializes from keyword arguments class ExplicitKeywordDeclaration < ExplicitDeclaration # Check if this declaration uses keyword argument initialization # @return [Boolean] Whether...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/check_policy.rb
Ruby
mit
48
main
1,155
# frozen_string_literal: true module Ivar # Module for adding instance variable check policy configuration to classes. # This module provides a way to set and inherit check policies for instance variables. # When extended in a class, it allows setting a class-specific policy that overrides # the global Ivar po...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/checked/class_methods.rb
Ruby
mit
48
main
582
# frozen_string_literal: true require_relative "instance_methods" module Ivar module Checked # Class methods added to the including class. # These methods ensure proper inheritance of Checked functionality. module ClassMethods # Ensure subclasses inherit the Checked functionality # This meth...
github
avdi/ivar
https://github.com/avdi/ivar
lib/ivar/checked/instance_methods.rb
Ruby
mit
48
main
1,329
# frozen_string_literal: true module Ivar module Checked # Instance methods that will be prepended to the including class. # These methods provide the core functionality for automatic instance variable validation. module InstanceMethods # The semantics of prepend are such that the super method beco...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_inheritance.rb
Ruby
mit
48
main
650
# frozen_string_literal: true require "ivar" class BaseSandwich include Ivar::Checked def initialize @bread = "wheat" @cheese = "muenster" end def base_to_s "A #{@bread} sandwich with #{@cheese}" end end class SpecialtySandwich < BaseSandwich def initialize super @condiments = ["may...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_shared_values.rb
Ruby
mit
48
main
1,596
# frozen_string_literal: true require "ivar" class SandwichWithSharedValues include Ivar::Checked # Declare multiple condiments with the same initial value (true) ivar :@mayo, :@mustard, :@ketchup, value: true # Declare bread and cheese with individual values ivar "@bread": "wheat", "@cheese": "cheddar" ...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_checked.rb
Ruby
mit
48
main
464
# frozen_string_literal: true require "ivar" class SandwichWithChecked include Ivar::Checked def initialize @bread = "wheat" @cheese = "muenster" @condiments = ["mayo", "mustard"] end def to_s result = "A #{@bread} sandwich with #{@chese} and #{@condiments.join(", ")}" result += " and a ...
github
avdi/ivar
https://github.com/avdi/ivar
examples/require_check_all_example.rb
Ruby
mit
48
main
565
# frozen_string_literal: true # Add lib directory to load path $LOAD_PATH.unshift File.expand_path("../lib", __dir__) # This automatically enables Ivar.check_all require "ivar/check_all" # Now all classes and modules defined in the project will have Ivar::Checked included class Sandwich def initialize @bread =...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_block_values.rb
Ruby
mit
48
main
1,670
# frozen_string_literal: true require "ivar" class SandwichWithBlockValues include Ivar::Checked # Declare condiments with a block that generates default values based on the variable name ivar(:@mayo, :@mustard, :@ketchup) { |varname| !varname.include?("mayo") } # Declare bread and cheese with individual va...
github
avdi/ivar
https://github.com/avdi/ivar
examples/check_all_example.rb
Ruby
mit
48
main
999
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "ivar" # Enable checking for all classes and modules defined in the project Ivar.check_all # Now any class or module defined in the project will have Ivar::Checked included class Sandwich # No need to include Ivar::Checked...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_ivar_macro.rb
Ruby
mit
48
main
907
# frozen_string_literal: true require "ivar" class SandwichWithIvarMacro include Ivar::Checked # Declare instance variables that might be referenced before being set # You don't need to include variables that are always set in initialize ivar :@side def initialize @bread = "wheat" @cheese = "muens...
github
avdi/ivar
https://github.com/avdi/ivar
examples/mixed_positional_and_kwarg_init.rb
Ruby
mit
48
main
4,618
# frozen_string_literal: true require "ivar" class Recipe include Ivar::Checked # Declare instance variables with positional initialization ivar :@name, init: :positional, value: "Unnamed Recipe" ivar :@servings, init: :positional, value: 4 # Declare instance variables with keyword initialization ivar :...
github
avdi/ivar
https://github.com/avdi/ivar
examples/check_all_block_example.rb
Ruby
mit
48
main
1,826
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "ivar" # Define a class before enabling check_all class BeforeClass def initialize @name = "before" end def to_s "Name: #{@naem}" # Intentional typo to demonstrate lack of checking end end # Define classes ...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_accessors.rb
Ruby
mit
48
main
2,100
# frozen_string_literal: true require "ivar" class SandwichWithAccessors include Ivar::Checked # Declare instance variables with accessors ivar :@bread, :@cheese, accessor: true, value: "default" # Declare condiments with a reader ivar :@condiments, reader: true, value: ["mayo", "mustard"] # Declare pi...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_kwarg_init.rb
Ruby
mit
48
main
2,784
# frozen_string_literal: true require "ivar" class SandwichWithKwargInit include Ivar::Checked # Declare instance variables with keyword argument initialization # and default values in case they're not provided ivar :@bread, init: :kwarg, value: "wheat" ivar :@cheese, init: :kwarg, value: "cheddar" # De...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_positional_init.rb
Ruby
mit
48
main
1,841
# frozen_string_literal: true require "ivar" class SandwichWithPositionalInit include Ivar::Checked # Declare instance variables with positional argument initialization # and default values in case they're not provided ivar :@bread, init: :positional, value: "wheat" ivar :@cheese, init: :positional, value:...
github
avdi/ivar
https://github.com/avdi/ivar
examples/inheritance_with_kwarg_init.rb
Ruby
mit
48
main
4,442
# frozen_string_literal: true require "ivar" # Base class for all food items class Food include Ivar::Checked # Declare common properties with keyword initialization and defaults ivar :@name, init: :kwarg, value: "Unknown Food" ivar :@calories, init: :kwarg, value: 0 ivar :@vegetarian, init: :kwarg, value:...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_checked_once.rb
Ruby
mit
48
main
661
# frozen_string_literal: true require "ivar" class SandwichWithCheckedOnce include Ivar::Checked ivar_check_policy :warn_once def initialize @bread = "wheat" @cheese = "muenster" @condiments = %w[mayo mustard] end def to_s result = "A #{@bread} sandwich with #{@chese} and #{@condiments.joi...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_ivar_block.rb
Ruby
mit
48
main
878
# frozen_string_literal: true require "ivar" class SandwichWithIvarBlock include Ivar::Checked # Declare instance variables ivar :@side def initialize @bread = "wheat" @cheese = "muenster" @pickles = true @condiments = [] @condiments << "mayo" if !@pickles @condiments << "mustard" ...
github
avdi/ivar
https://github.com/avdi/ivar
examples/inheritance_with_positional_init.rb
Ruby
mit
48
main
4,442
# frozen_string_literal: true require "ivar" # Base class for all food items class Food include Ivar::Checked # Declare common properties with positional initialization and defaults ivar :@name, init: :positional, value: "Unknown Food" ivar :@calories, init: :positional, value: 0 ivar :@vegetarian, init: :...
github
avdi/ivar
https://github.com/avdi/ivar
examples/sandwich_with_initial_values.rb
Ruby
mit
48
main
1,498
# frozen_string_literal: true require "ivar" class SandwichWithInitialValues include Ivar::Checked # Declare instance variables with initial values ivar "@bread": "wheat", "@cheese": "muenster", "@condiments": ["mayo", "mustard"], "@pickles": true # Declare a variable without an initial value ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
Gemfile
Ruby
mit
48
main
392
source "https://rubygems.org" # Specify your gem's dependencies in rails-assessment.gemspec. gemspec gem "puma" gem "sqlite3" gem "propshaft" # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] gem "rubocop-rails-omakase", require: false # Testing gem "webmock" gem "mocha" # Start debugger w...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
rails-assessment.gemspec
Ruby
mit
48
main
949
require_relative "lib/rails/assessment/version" Gem::Specification.new do |spec| spec.name = "rails-assessment" spec.version = Rails::Assessment::VERSION spec.authors = [ "Hamed M" ] spec.email = [ "hamed.mon+gems@gmail.com" ] spec.homepage = "https://github.com/hmontazeri/rails-asses...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
db/migrate/20250215000000_add_uuid_to_rails_assessment_responses.rb
Ruby
mit
48
main
804
class AddUuidToRailsAssessmentResponses < ActiveRecord::Migration[7.1] def up add_column :rails_assessment_responses, :uuid, :string add_index :rails_assessment_responses, :uuid, unique: true say_with_time "Backfilling response UUIDs" do require "securerandom" response_model = Class.new(Acti...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
db/migrate/20250101000000_create_rails_assessment_responses.rb
Ruby
mit
48
main
502
class CreateRailsAssessmentResponses < ActiveRecord::Migration[7.1] def change create_table :rails_assessment_responses do |t| t.string :assessment_slug, null: false json_column = connection.adapter_name.to_s.downcase.include?("postgres") ? :jsonb : :json t.send(json_column, :answers, default: ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment.rb
Ruby
mit
48
main
1,912
require "active_support" require "active_support/core_ext/module/delegation" require "active_support/core_ext/hash/deep_merge" require "active_support/core_ext/object/try" require "active_support/core_ext/string/inflections" require "rails/assessment/version" require "rails/assessment/configuration" require "rails/ass...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/logic_engine.rb
Ruby
mit
48
main
895
module Rails module Assessment class LogicEngine class << self def evaluate(selected_tags, result_rules, score: nil, fallback_text: nil) rules = Array(result_rules) tags = normalize_tags(selected_tags) matching_rule = rules.find { |rule| rule.match?(tags, score: score)...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/definition.rb
Ruby
mit
48
main
8,229
module Rails module Assessment class Definition attr_accessor :title, :slug, :hook, :description, :questions, :result_rules, :theme, :metadata, :estimated_time, :show_start_screen, :logo, :show_question_count, :capture_email, :capture_name, :capture_notes, :notification_email, :webhook_url def initia...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/response_builder.rb
Ruby
mit
48
main
2,338
module Rails module Assessment class ResponseBuilder def initialize(definition) @definition = definition end def build(params) answers = {} definition.questions.each do |question| selected = selected_options(question, params) next if selected.empty? ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/configuration.rb
Ruby
mit
48
main
4,635
require "pathname" module Rails module Assessment class Configuration attr_accessor :theme, :themes, :theme_strategy, :theme_param_key, :theme_proc, :assessments_paths, :cache_enabled, ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/engine.rb
Ruby
mit
48
main
1,192
module Rails module Assessment class Engine < ::Rails::Engine isolate_namespace Rails::Assessment initializer "rails_assessment.asset_paths" do |app| app.config.assets.paths << root.join("app", "assets", "javascripts") app.config.assets.paths << root.join("app", "assets", "stylesheets...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/theme/resolver.rb
Ruby
mit
48
main
412
module Rails module Assessment module Theme class Resolver def initialize(configuration: Rails::Assessment.configuration) @configuration = configuration end def resolve(request: nil, overrides: nil) configuration.theme_for(request: request, override: overrides) ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/theme/helpers.rb
Ruby
mit
48
main
4,108
module Rails module Assessment module Theme module Helpers def current_assessment_theme(overrides: nil) @_rails_assessment_theme_cache ||= {} cache_key = overrides ? overrides.hash : :default @_rails_assessment_theme_cache[cache_key] ||= resolver.resolve( re...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/dsl/loader.rb
Ruby
mit
48
main
1,695
require "date" require "yaml" module Rails module Assessment module DSL class Loader class << self def load_all! Rails::Assessment.registry.reset load_yaml_definitions load_ruby_definitions end def load_yaml_definitions ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
lib/rails/assessment/dsl/builder.rb
Ruby
mit
48
main
4,826
module Rails module Assessment module DSL class Builder attr_reader :definition def initialize(slug, **attributes, &block) @definition = Rails::Assessment::Definition.new( slug: slug, title: attributes[:title], hook: attributes[:hook], ...
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
config/routes.rb
Ruby
mit
48
main
272
Rails::Assessment::Engine.routes.draw do resources :assessments, only: [ :show ], param: :slug, path: "/" do resource :response, only: :create, controller: "responses" end get "/:slug/result/:response_uuid", to: "assessments#result", as: :assessment_result end
github
hmontazeri/rails-assessment
https://github.com/hmontazeri/rails-assessment
config/initializers/rails_assessment.rb
Ruby
mit
48
main
1,401
Rails::Assessment.configure do |config| config.assessments_paths = [ Rails.root.join("config", "assessments") ] config.theme = { colors: { primary: "#2563EB", neutral: { 50 => "#F8FAFC", 900 => "#0F172A" }, accent: "#FACC15" }, typography: { font_sans: "'Inter', system-ui,...