ScraperWikiMorph
A simple compatibility layer so that you can use something that looks almost
the same as the ScraperWiki gem - the
only real difference is that it writes to an SQLite database called
data.sqlite (rather than ScraperWiki's default scraperwiki.sqlite) and a
table called data (rather than ScraperWiki's default swdata).
This makes it very easy to transition scraper code from ScraperWiki to morph.io.
Requirements
Ruby 3.2 or later.
Installation
Add this line to your application's Gemfile:
gem 'scraperwiki-morph'And then execute:
$ bundle install
Or install it yourself as:
$ gem install scraperwiki-morph
Usage
Use ScraperWikiMorph exactly as you would use ScraperWiki - every method
is delegated to the scraperwiki gem,
with the database preconfigured for morph.io:
require 'scraperwiki-morph'
# Save a record (upserted on the unique keys) to the "data" table
# in data.sqlite
ScraperWikiMorph.save_sqlite([:id], { id: 1, name: "Alice" })
# Save to a different table
ScraperWikiMorph.save_sqlite([:id], { id: 1, name: "Alice" }, "people")
# Query the data back
ScraperWikiMorph.select("* from data")
# => [{"id" => 1, "name" => "Alice"}]
# Persist scraper state between runs
ScraperWikiMorph.save_var("last_run", "2026-08-12")
ScraperWikiMorph.get_var("last_run")
# Fetch a page
html = ScraperWikiMorph.scrape("https://example.com/")Development
After checking out the repo, install dependencies and run the tests:
$ bundle install
$ bundle exec rspec
The test suite runs with SimpleCov coverage reporting and uses WebMock so it never touches the network.
Releasing a new version
Releases are published to RubyGems.org automatically by the Release workflow using RubyGems trusted publishing (OIDC) - no API keys are stored in the repository.
To release a new version:
- Create a branch (e.g.
release/v0.2.0) and bump the version number inlib/scraperwiki-morph/version.rbfollowing Semantic Versioning - Move the entries under "Unreleased" in
CHANGELOG.mdinto a new section for the version, dated today, and update the comparison links at the bottom - Open a pull request and get it reviewed and merged
- When the version bump lands on
main, the Release workflow builds the gem, pushes thevX.Y.Zgit tag and publishes to RubyGems.org
The workflow checks RubyGems.org first and skips publishing if the version already exists, so re-runs and merges that don't change the version are safe. If it can't get an answer from RubyGems.org the job fails rather than skipping quietly, so a red Release job may mean the check couldn't reach RubyGems.org rather than that publishing failed. Re-run it once the API is reachable again.
One-time trusted publishing setup (gem owners)
Publishing will fail until a gem owner performs this one-time setup:
- On rubygems.org, sign in as an owner of
scraperwiki-morph, go to the gem's Settings → Trusted publishers (see the RubyGems guide) and add a GitHub Actions publisher with:-
Repository owner:
openaustralia -
Repository name:
scraperwiki-morph -
Workflow filename:
release.yml -
Environment:
rubygems
-
Repository owner:
- On GitHub, in this repository go to Settings → Environments and create
an environment named
rubygems. Under Deployment branches and tags, restrict deployments to themainbranch - the workflow also refuses to run offmain, but the environment rule enforces it at the platform level. Optionally add further protection rules (e.g. required reviewers) to control who can trigger a release.
Contributing
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/my-new-feature) - Create new Pull Request
License
The gem is available as open source under the terms of the MIT License.