glob-0.2.0/0000755000175100017510000000000014125344020012611 5ustar vivekdebvivekdebglob-0.2.0/lib/0000755000175100017510000000000014125344020013357 5ustar vivekdebvivekdebglob-0.2.0/lib/glob/0000755000175100017510000000000014125344020014302 5ustar vivekdebvivekdebglob-0.2.0/lib/glob/version.rb0000644000175100017510000000010314125344020016306 0ustar vivekdebvivekdeb# frozen_string_literal: true module Glob VERSION = "0.2.0" end glob-0.2.0/lib/glob/symbolize_keys.rb0000644000175100017510000000057614125344020017707 0ustar vivekdebvivekdeb# frozen_string_literal: true module Glob module SymbolizeKeys def self.call(target) case target when Hash target.each_with_object({}) do |(key, value), buffer| buffer[key.to_sym] = SymbolizeKeys.call(value) end when Array target.map {|item| SymbolizeKeys.call(item) } else target end end end end glob-0.2.0/lib/glob/query.rb0000644000175100017510000000222714125344020015777 0ustar vivekdebvivekdeb# frozen_string_literal: true module Glob class Query attr_reader :matchers def initialize(target) @target = target @matchers = [] end def <<(path) matchers << Matcher.new(path) end alias filter << def to_h symbolized_target = SymbolizeKeys.call(@target) paths.each_with_object({}) do |path, buffer| segments = path.split(".").map(&:to_sym) value = symbolized_target.dig(*segments) set_path_value(segments, buffer, value) end end alias to_hash to_h def paths matches = map.map do |path| results = matchers.select {|matcher| matcher.match?(path) } [path, results] end matches .select {|(_, results)| results.compact.last&.include? } .map {|(path)| path } .sort end private def map @map ||= Map.call(@target) end private def set_path_value(segments, target, value) while (segment = segments.shift) if segments.empty? target[segment] = value else target[segment] ||= {} target = target[segment] end end end end end glob-0.2.0/lib/glob/matcher.rb0000644000175100017510000000067214125344020016257 0ustar vivekdebvivekdeb# frozen_string_literal: true module Glob class Matcher attr_reader :path, :regex def initialize(path) @path = path @reject = path.start_with?("!") pattern = Regexp.escape(path.gsub(/^!/, "")).gsub(/\\\*/, "[^.]+") @regex = Regexp.new("^#{pattern}") end def match?(other) other.match?(regex) end def include? !reject? end def reject? @reject end end end glob-0.2.0/lib/glob/map.rb0000644000175100017510000000102114125344020015376 0ustar vivekdebvivekdeb# frozen_string_literal: true module Glob class Map def self.call(target) new(target).call end def initialize(target) @keys = [] @target = target end def call @target .map {|(key, value)| compute(value, key) } .flatten .sort end private def compute(value, path) if value.is_a?(Hash) value.map do |key, other_value| compute(other_value, "#{path}.#{key}") end else path.to_s end end end end glob-0.2.0/lib/glob.rb0000644000175100017510000000052714125344020014633 0ustar vivekdebvivekdeb# frozen_string_literal: true require "glob/map" require "glob/query" require "glob/matcher" require "glob/symbolize_keys" require "glob/version" module Glob def self.filter(target, paths = ["*"]) glob = new(target) paths.each {|path| glob.filter(path) } glob.to_h end def self.new(target) Query.new(target) end end glob-0.2.0/glob.gemspec0000644000175100017510000000247414125344020015110 0ustar vivekdebvivekdeb# frozen_string_literal: true require "./lib/glob/version" Gem::Specification.new do |spec| spec.name = "glob" spec.version = Glob::VERSION spec.authors = ["Nando Vieira"] spec.email = ["me@fnando.com"] spec.summary = [ "Create a list of hash paths that match a given pattern.", "You can also generate a hash with only the matching paths." ].join(" ") spec.description = spec.summary spec.homepage = "https://github.com/fnando/glob" spec.license = "MIT" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/fnando/glob" spec.metadata["changelog_uri"] = "https://github.com/fnando/glob" spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z` .split("\x0") .reject {|f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler" spec.add_development_dependency "minitest" spec.add_development_dependency "minitest-utils" spec.add_development_dependency "rake" spec.add_development_dependency "rubocop" spec.add_development_dependency "rubocop-fnando" spec.add_development_dependency "simplecov" end glob-0.2.0/bin/0000755000175100017510000000000014125344020013361 5ustar vivekdebvivekdebglob-0.2.0/bin/setup0000755000175100017510000000020314125344020014442 0ustar vivekdebvivekdeb#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here glob-0.2.0/bin/console0000755000175100017510000000056114125344020014753 0ustar vivekdebvivekdeb#!/usr/bin/env ruby # frozen_string_literal: true require "bundler/setup" require "glob" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start(__FILE__) glob-0.2.0/Rakefile0000644000175100017510000000034214125344020014255 0ustar vivekdebvivekdeb# 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"] end task default: :test glob-0.2.0/README.md0000644000175100017510000000501014125344020014064 0ustar vivekdebvivekdeb# Glob [![](https://github.com/fnando/glob/workflows/tests/badge.svg)](https://github.com/fnando/glob/actions?query=workflow%3Atests) Create a list of hash paths that match a given pattern. You can also generate a hash with only the matching paths. ## Installation Add this line to your application's Gemfile: ```ruby gem "glob" ``` And then execute: $ bundle Or install it yourself as: $ gem install glob ## Usage There are two types of paths: `include` and `exclude`. - The `include` path adds that node to the new hash. - The `exclude` path is the one started by `!`, and will prevent that path from being added. The latest rules have more precedence; that means that if you have the rule `*.messages.*`, then add a following rule as `!*.messages.bye`, all `*.messages.*` but `*.messages.bye` will be included. ```ruby glob = Glob.new( site: { settings: { name: "Site name", url: "https://example.com" } }, user: { settings: { name: "User name" } } ) glob << "*.settings.*" glob.paths #=> ["site.settings.name", "site.settings.url", "user.settings.name"] glob.to_h #=> { #=> site: { #=> settings: { #=> name: "Site name" #=> } #=> }, #=> user: { #=> settings: { #=> name: "User name" #=> } #=> } #=> } ``` Notice that the return result will have symbolized keys. ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/glob. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in the Glob project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fnando/glob/blob/master/CODE_OF_CONDUCT.md). glob-0.2.0/LICENSE.txt0000644000175100017510000000206714125344020014441 0ustar vivekdebvivekdebThe MIT License (MIT) Copyright (c) 2019 Nando Vieira Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. glob-0.2.0/Gemfile.lock0000644000175100017510000000161514125344020015036 0ustar vivekdebvivekdebPATH remote: . specs: glob (0.1.0) GEM remote: https://rubygems.org/ specs: ast (2.4.0) docile (1.3.2) jaro_winkler (1.5.4) json (2.3.0) minitest (5.13.0) minitest-utils (0.4.6) minitest parallel (1.19.1) parser (2.6.5.0) ast (~> 2.4.0) rainbow (3.0.0) rake (13.0.1) rubocop (0.77.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.6) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) rubocop-fnando (0.0.3) ruby-progressbar (1.10.1) simplecov (0.17.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) unicode-display_width (1.6.0) PLATFORMS ruby DEPENDENCIES bundler glob! minitest minitest-utils rake rubocop rubocop-fnando simplecov BUNDLED WITH 2.0.2 glob-0.2.0/Gemfile0000644000175100017510000000017014125344020014102 0ustar vivekdebvivekdeb# frozen_string_literal: true source "https://rubygems.org" # Specify your gem's dependencies in glob.gemspec gemspec glob-0.2.0/CODE_OF_CONDUCT.md0000644000175100017510000000622514125344020015415 0ustar vivekdebvivekdeb# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at me@fnando.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ glob-0.2.0/CHANGELOG.md0000644000175100017510000000017014125344020014420 0ustar vivekdebvivekdeb# Changelog ## Unreleased - Allow rejecting patterns like `!*.activerecord`. - New API. ## v0.1.0 - Initial release glob-0.2.0/.travis.yml0000644000175100017510000000015214125344020014720 0ustar vivekdebvivekdeb--- sudo: false language: ruby cache: bundler rvm: - 2.6.5 before_install: gem install bundler -v 2.0.2 glob-0.2.0/.rubocop.yml0000644000175100017510000000033014125344020015057 0ustar vivekdebvivekdeb--- inherit_gem: rubocop-fnando: .rubocop.yml AllCops: TargetRubyVersion: 2.6 Metrics/BlockLength: Exclude: - test/**/*_test.rb - glob.gemspec Metrics/ClassLength: Exclude: - test/**/*_test.rb glob-0.2.0/.gitignore0000644000175100017510000000011114125344020014572 0ustar vivekdebvivekdeb/.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ glob-0.2.0/.github/0000755000175100017510000000000014125344020014151 5ustar vivekdebvivekdebglob-0.2.0/.github/workflows/0000755000175100017510000000000014125344020016206 5ustar vivekdebvivekdebglob-0.2.0/.github/workflows/tests.yml0000644000175100017510000000200214125344020020065 0ustar vivekdebvivekdeb--- name: tests on: [push] jobs: build: runs-on: ubuntu-latest steps: - name: Clone repo uses: actions/checkout@v1 - name: Ruby cache uses: actions/cache@v1 id: cache with: path: ~/local/rubies key: ruby-2.6.5 - name: Rubygems cache uses: actions/cache@v1 with: path: vendor/bundle key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }} restore-keys: ${{ runner.os }}-gem- - name: Install ruby uses: clupprich/ruby-build-action@master id: ruby with: ruby-version: 2.6.5 cache-available: ${{ steps.cache.outputs.cache-hit == 'true' }} - name: Bundle install run: | gem install bundler bundle config path vendor/bundle bundle install --jobs 4 --retry 3 - name: Run ruby tests run: | bundle exec rake - name: Run lint run: | bundle exec rubocop glob-0.2.0/.github/FUNDING.yml0000644000175100017510000000006714125344020015771 0ustar vivekdebvivekdeb--- custom: ["https://www.paypal.me/nandovieira/🍕"]