README.adoc in relaton-index-0.1.3 vs README.adoc in relaton-index-0.1.4

- old
+ new

@@ -20,22 +20,37 @@ $ gem install relaton-index == Usage +[source,ruby] +---- +require 'relaton/index' + +# Create a new index object. The first argument is the type of dataset (ISO, IEC, IHO, etc.) URL and filename are optional. +Relaton::Index.find_or_create :IHO, url: "https://raw.githubusercontent.com/relaton/relaton-data-iho/master/index.zip", filename: "index-iho.yaml" + +# Find an existing index object (created before). +Relaton::Index.find_or_create :IHO + +# If a new value of URL or filename is specified and has a new value (different from what it was before), the index object will be recreated. +Relaton::Index.find_or_create :IHO, url: nil, filename: "index.yaml" + +# Remove the index from the pool. +Relaton::Index.close :IHO +---- + The aim of this gem is to be used by Relaton libraries in two ways: - indexing documents' files in GitHub repositories - searching a document by a reference when the Relaton library fetches a document === Indexing -In this case, the Relaton library creates an index object and adds documents' files to it. By default, the index object is saved to the `index.yaml` file in the root of the repository. The filename can be changed using the `filename` setting +In this case, the Relaton library creates an index object and adds documents' files to it. By default, the index object is saved to the `index.yaml` file in the root of the repository. The filename can be changed using the `filename` setting. [source,ruby] ---- -require 'relaton/index' - # Create a new index object or fetch an existing one. The first argument is the type of dataset (ISO, IEC, IHO, etc.) URL should not be specified. index = Relaton::Index.find_or_create :IHO # Add a document to the index or update it if it already exists. index.add_or_update id: "B-4 2.19.0", file: "data/b-4_2_19_0.xml" @@ -48,13 +63,11 @@ In this case, the Relaton library should create an index object and search for a document by reference. The gem looks for the `.relaton/[TYPE]/index.yaml` file in the user's home directory. The `[TYPE]` is one of downcased ISO, IEC, IHO, etc. If the file is not found or is older than 24 hours then it will be downloaded from the URL specified in the `find_or_create` method. [source,ruby] ---- -require 'relaton/index' - -# Create a new index object or fetch an existing one. URL should be specified. If the index file is not found or is older than 24 hours, it will be downloaded from the URL. By default, the index file is saved to the `/[HOME]/.relaton/iho/index.yaml` file. +# Create a new index object or fetch an existing one. URL should be specified. If the index file is not found or is older than 24 hours, it will be downloaded from the URL. By default, the index is saved as `index.yaml` file to the `/[HOME]/.relaton/iho/` folder. index = Relaton::Index.find_or_create :IHO, url: "https://raw.githubusercontent.com/relaton/relaton-data-iho/master/index.zip" # Search for a document by reference index.search "B-4" @@ -64,13 +77,10 @@ index.search do |row| # do something with the index row row[:id] == "B-4" end # => [{ id: "B-4 2.19.0", file: "data/b-4_2_19_0.xml" }] - -# Remove the index from the pool. -Relaton::Index.close :IHO ---- === Configuration The gem can be configured by using the `Relaton::Index.config` method. The following settings are available: @@ -84,9 +94,15 @@ Relaton::Index.config do |config| config.filename = "index-new.yaml" config.storage = S3Storage config.storage_dir = "/" end +---- + +It's also possible to redefine file name for a specific type of index: +[source,ruby] +---- +index = Relaton::Index.find_or_create :IHO, filename: "index-iho.yaml" ---- == Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.