{"id":21927024,"url":"https://github.com/rzane/pipey","last_synced_at":"2025-03-22T12:15:14.946Z","repository":{"id":56888140,"uuid":"96848766","full_name":"rzane/pipey","owner":"rzane","description":"Functional pipelines for Ruby","archived":false,"fork":false,"pushed_at":"2017-07-11T14:28:16.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-24T22:33:30.627Z","etag":null,"topics":["chain","functional","pipeline","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rzane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-11T03:55:52.000Z","updated_at":"2017-12-12T20:21:56.000Z","dependencies_parsed_at":"2022-08-21T00:50:47.505Z","dependency_job_id":null,"html_url":"https://github.com/rzane/pipey","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fpipey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fpipey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fpipey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fpipey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rzane","download_url":"https://codeload.github.com/rzane/pipey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244952805,"owners_count":20537474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chain","functional","pipeline","ruby"],"created_at":"2024-11-28T22:13:03.125Z","updated_at":"2025-03-22T12:15:14.920Z","avatar_url":"https://github.com/rzane.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pipey\n\nBuild functional pipelines in Ruby by taking advantage of Ruby's keyword arguments for \"pattern matching.\"\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'pipey'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install pipey\n\n## Usage\n\n### `Pipey::Line`\n\n`Pipey::Line` can be used to work with any object in a pipe-line manner.\n\n```ruby\nclass MyPipe \u003c Pipey::Line\n  extend Pipey::Steps::Scanner[/^run_/]\n\n  def run_foo(num, multiply:, **)\n    num * multiply\n  end\n\n  def run_bar(num, add:, **)\n    num + add\n  end\nend\n\nMyPipe.call(1, multiply: 10, add: 5) #=\u003e 15\n```\n\n### `Pipey::Chain`\n\n`Pipey::Chain` is a slightly fancier way to work with chainable objects like `Array` or `ActiveRecord::Relation`. In the example below, `map` and `select` are automatically delegated to the array.\n\n```ruby\nclass MyPipe \u003c Pipey::Chain\n  extend Pipey::Steps::Scanner[/^run_/]\n\n  def run_foo(multiply:, **)\n    map { |v| v * a }\n  end\n\n  def run_bar(minimum:, **)\n    select { |v| v \u003e minimum }\n  end\nend\n\nMyPipe.call([1, 2, 3], multiply: 5, minimum: 6) #=\u003e [10, 15]\n```\n\n### `Pipey::Steps::Scanner`\n\n`Pipey::Steps::Scanner` takes a `Regexp` as an argument, and it will run the methods that match the regexp.\n\n```ruby\nclass MyPipe \u003c Pipey::Line\n  extend Pipey::Steps::Scanner[/^run_/]\n  \n  def run_something(**); end # this will be called\n  def something(**); end     # this will not be called\nend\n```\n\n### `Pipey::Steps::DSL`\n\nIf you don't like the automatic behavior provided by `Pipey::Steps::Scanner`, you can use `Pipey::Steps::DSL` instead. With it, you can list out your steps.\n\n```ruby\nclass MyPipe \u003c Pipey::Line\n  extend Pipey::Steps::DSL\n\n  step :foo\n  step :bar\n\n  def foo(num, multiply:, **)\n    num * multiply\n  end\n\n  def bar(num, add:, **)\n    num + add\n  end\nend\n\nMyPipe.call(1, multiply: 10, add: 5) #=\u003e 15\n```\n\n### `Pipey::Extensions::RequiredKeys`\n\nThis extension won't call a step if it requires a key that is falsy.\n\n```ruby\nclass MyPipe \u003c Pipey::Line\n  extend Pipey::Steps::Scanner[/^run_/]\n  extend Pipey::Extensions::RequiredKeys\n\n  def run_foo(num, multiply:, **)\n    num * multiply\n  end\n\n  def run_bar(num, add:, **)\n    num + add\n  end\nend\n\nMyPipe.call(1, multiply: 10, add: 5) #=\u003e 15\nMyPipe.call(1, multiply: 10)         #=\u003e 10\nMyPipe.call(1, add: 5)               #=\u003e 6\n```\n\n### `Pipey::Extensions::IgnoreNil`\n\nBy using this extension, any step that returns nil will be ignored.\n\n```ruby\nclass MyPipe \u003c Pipey::Line\n  extend Pipey::Steps::Scanner[/^run_/]\n  extend Pipey::Extensions::IgnoreNil\n\n  def run_foo(num, add:, **)\n    num + add if add \u003e 5\n  end\nend\n\nMyPipe.call(1, add: 5) #=\u003e 1\nMyPipe.call(1, add: 6) #=\u003e 6\n```\n\n### `Pipey::Extensions::Ignore`\n\nThis can be used to create more complicated ignores.\n\nFor example, the implementation of `IgnoreNil` looks like this:\n\n```ruby\nPipey::Extensions::Ignore.new(\u0026:nil?)\n```\n\nIf you wanted to ignore any value equal to 5, you could do this:\n\n```ruby\nclass MyPipe \u003c Pipey::Line\n  extend Pipey::Extensions::Ignore.new { |v| v == 5 }\nend\n```\n\n## TODO\n\n+ [ ] `Pipey::Steps::Scanner` does not guarantee order.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/rzane/pipey.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Fpipey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frzane%2Fpipey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Fpipey/lists"}