Skip to content

Commit

Permalink
Make cob_index into an executable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkinzer committed Jun 26, 2019
1 parent a4b96fe commit 43c0747
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ PATH
remote: .
specs:
cob_index (0.1.0)
gli (= 2.18.0)
library_stdnums (~> 1.6)
traject (~> 3.1)

GEM
Expand Down Expand Up @@ -89,6 +91,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dot-properties (0.1.3)
erubi (1.8.0)
gli (2.18.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashie (3.6.0)
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ Or install it yourself as:

## Usage

TODO: Write usage instructions here
`cob_index` is an executable. You can use it to ingest files into SOLR_URL with

```
cob_index ingest $path_to_file
```

`$path_file` can also be a URL.


## Development

Expand Down
9 changes: 0 additions & 9 deletions bin/ingest.rb

This file was deleted.

5 changes: 4 additions & 1 deletion cob_index.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/tulibraries/cob_index"
spec.metadata["source_code_uri"] = spec.homepage
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
Expand All @@ -35,9 +35,12 @@ Gem::Specification.new do |spec|
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.executables << "cob_index"
spec.require_paths = ["lib"]

spec.add_dependency "traject", "~> 3.1"
spec.add_dependency "library_stdnums", "~> 1.6"
spec.add_runtime_dependency("gli", "2.18.0")

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
Expand Down
49 changes: 49 additions & 0 deletions exe/cob_index
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "gli"
require "cob_index"

class App
extend GLI::App

program_desc "Wrapper cli app for indexing tul_cob app"

version CobIndex::VERSION

subcommand_option_handling :normal
arguments :strict

desc "Ingest files into solr endpoint using tul_cob traject config"
arg_name "Describe arguments to ingest here"
command :ingest do |c|
c.desc "Ingest files into SOLR_URL using tul_cob traject config"
c.action do |global_options, options, args|

CobIndex::CLI.ingest
end
end

pre do |global, command, options, args|
# Pre logic here
# Return true to proceed; false to abort and not call the
# chosen command
# Use skips_pre before a command to skip this block
# on that command only
true
end

post do |global, command, options, args|
# Post logic here
# Use skips_post before a command to skip this
# block on that command only
end

on_error do |exception|
# Error logic here
# return false to skip default error handling
true
end
end

exit App.run(ARGV)
9 changes: 8 additions & 1 deletion lib/cob_index.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# frozen_string_literal: true

require "cob_index/version"
require "traject"

module CobIndex
# Your code goes here...
module CLI
def self.ingest
indexer = Traject::Indexer::MarcIndexer.new("solr_writer.commit_on_close": true)
indexer.load_config_file("#{File.dirname(__FILE__)}/cob_index/indexer_config.rb")
indexer.process(StringIO.new(open(ARGV[0]).read))
end
end
end
1 change: 1 addition & 0 deletions lib/cob_index/macros/custom.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "bundler/setup"
require "library_stdnums"
require "active_support/core_ext/object/blank"
require "time"
Expand Down

0 comments on commit 43c0747

Please sign in to comment.