{"id":17272570,"url":"https://github.com/rubyist/guard-rake","last_synced_at":"2025-04-05T07:05:43.460Z","repository":{"id":56875540,"uuid":"2137700","full_name":"rubyist/guard-rake","owner":"rubyist","description":"guard-rake runs a rake task when files change","archived":false,"fork":false,"pushed_at":"2020-06-16T12:30:38.000Z","size":29,"stargazers_count":94,"open_issues_count":12,"forks_count":32,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T06:06:47.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubyist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-08-01T16:26:56.000Z","updated_at":"2025-02-14T15:49:53.000Z","dependencies_parsed_at":"2022-08-20T22:00:37.722Z","dependency_job_id":null,"html_url":"https://github.com/rubyist/guard-rake","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyist%2Fguard-rake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyist%2Fguard-rake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyist%2Fguard-rake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubyist%2Fguard-rake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubyist","download_url":"https://codeload.github.com/rubyist/guard-rake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299832,"owners_count":20916190,"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":[],"created_at":"2024-10-15T08:48:56.713Z","updated_at":"2025-04-05T07:05:43.441Z","avatar_url":"https://github.com/rubyist.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Guard::Rake\n\nGuard::Rake allows you to automatically run a Rake task when files are\nmodified.\n\n## Install\n\nPlease be sure to have [Guard](https://github.com/guard/guard) installed\nbefore continuing.\n\nInstall the gem:\n```bash\n$ gem install guard-rake\n```\n\nAdd it to your `Gemfile`\n\n```ruby\ngem 'guard-rake'\n```\n\nAdd the default Guard::Rake template to your `Guardfile` by running this\ncommand:\n\n```bash\n$ guard init rake\n```\n\n## Usage\n\nPlease read the [Guard usage documentation](https://github.com/guard/guard#readme).\n\n## Guardfile\n\nGuard::Rake comes with a default template that looks like this:\n\n```ruby\nguard 'rake', :task =\u003e 'doit' do\n  watch(%r{^some_files/.+$})\nend\n```\n\nThis will run the rake task `doit` from your `Rakefile` whenever any of\nthe watched files change.\n\n### List of available options:\n\n```ruby\n:task =\u003e 'doit'              # name of the task to be executed, required\n:run_on_all =\u003e false         # runs when the 'run_all' signal is received from Guard (enter is pressed), default: true\n:run_on_start =\u003e true        # runs when guard is started, default: true\n:task_args =\u003e []             # arguments to pass to Rake::Task#invoke, default: []\n```\n\n### Rake task arguments\nBy default, the changed file paths will be passed into the rake task. Example:\n\n```ruby\ntask :doit, :paths do |t, args|\n  args.paths  # Will contain an array of changed paths\nend\n```\n\nYou may also use this in conjunction with the :task_args options. Anything in :task_args will\nbe passed in first, then the array of changed paths. Example:\n\n```ruby\n# Guardfile\nguard 'rake', :task =\u003e 'doit', :task_args =\u003e ['a', 'b'] do\n  watch(%r{^some_files/.+$})\nend\n\n# Rakefile\ntask :doit, [:first, :second, :paths] do |t, args|\n  args.first  # \"a\"\n  args.second # \"b\"\n  args.paths  # ['changed1.rb', 'changed2.rb']\nend\n```\n\n## Second usage\n\nThis second usage will describe how to create a rake task that generates Guardfile from rake tasks.\n\nFirst, add this to your Gemfile:\n\n```ruby\ngem 'guard-rake'\ngem 'guard-shell'\n```\n\nYou will need some tasks with file dependencies in your Rakefile. I'f you don't have those, try put this code in your Rakefile:\n\n```ruby\nfiles = Rake::FileList.new('*.md')\ndesc \"Create a book\"\ntask 'book' =\u003e files do\n  sh \"cat #{files.join(\" \")} \u003e book.txt\"\nend\n```\n\nNow you are ready to import our rake task, put  Inside your `Rakefile`:\n\n```ruby\nrequire \"guard/rake/task\"\n\nGuard::Rake::Task.new\n```\n\nYou can see you have two new tasks:\n\n```\n$ rake -T\nrake book             # Create a book\nrake guard            # Create Guardfile from rake tasks\n```\n\nAnd the book task have these dependencies:\n\n```\n$ rake -P\nrake book\n    README.md\nrake guard\n```\n\nIf you call the `guard` task it will create `Guardfile`:\n\n```\n$ rake guard\n$ cat Guardfile\nguard :shell do\n\n    watch(%r{^(README.md)$}) do |m|\n      system(\"rake book\")\n    end\n\nend\n```\n\nYou can also add the `Rakefile` dependency:\n\n```\ntask :guard =\u003e ['Rakefile']\n```\n\nAnd using the `guard` task it will produce this `Guardfile`:\n\n```ruby\nguard :shell do\n\n    watch(%r{^(README.md)$}) do |m|\n      system(\"rake book\")\n    end\n\n    watch(%r{^(Rakefile)$}) do |m|\n      system(\"rake guard\")\n    end\n\nend\n```\n\n### Advanced usage\n\nIf you want update your `Guardfile` with other content, it's best to create your own ERB template:\n\n```ruby\nGuard::Rake::Task.new do |t|\n  t.template=File.read('Guardfile.erb')\nend\n```\n\nAnd then create your `Guardfile.erb` as a template:\n\n```ruby\nguard :shell do\n  \u003c% all_tasks.each do |t, files| %\u003e\n    watch(%r{^(\u003c%= files.join('|') %\u003e)$}) do |m|\n      system(\"rake \u003c%= t %\u003e\")\n    end\n  \u003c% end %\u003e\n\n  \u003c%# Add your custom code here %\u003e\nend\n\n\u003c%# Or here %\u003e\n```\n\n## Development\n\n- Source hosted at [GitHub](https://github.com/rubyist/guard-rake)\n- Report issues and feature requests to [GitHub Issues](https://github.com/rubyist/guard-rake/issues)\n\nPull requests welcome!\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2011 Scott Barron\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyist%2Fguard-rake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyist%2Fguard-rake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyist%2Fguard-rake/lists"}