This is slighly different in that it installs the gems inside the app directory in yourappname/.bundle and
uses native libxml2 to compile nokogiri.
$ ruby -v # need a 2.3 or later
=> 2.4.0
$ rails -v #
=> 5.0.2
| require 'benchmark' | |
| require 'uri' | |
| require 'solr_ead' | |
| require 'concurrent' | |
| # Make a subclass with all the speed patches | |
| class IndexerWithPatches < SolrEad::Indexer | |
| def additional_component_fields(node, addl_fields = Hash.new) | |
| # Clear or create the cache |
| require "URI" | |
| require 'solr_ead' | |
| class SolrEad::Indexer | |
| def additional_component_fields(node, addl_fields = Hash.new) | |
| p_ids = parent_id_list(node) | |
| p_unittitles = parent_unittitle_list(node) |
| # A simpler example: create an object which takes | |
| # in a file name and allows you to iterate over | |
| # only the comments (lines that start with '#') | |
| # | |
| # Obviously, it'd be pretty easy to do this inline, but it's just an | |
| # example. One could also imagine it returning every set of | |
| # contiguous comment lines as a single comment, or even being smart enough to | |
| # do C-style /* ... */ comments and extract those. | |
| # | |
| # The point is that you've got that all hidden in a class, and the user |
| #!/usr/bin/env ruby | |
| require 'optparse' | |
| ACTIVE_SERVERS = '/l/local/active-servers' | |
| def alltags | |
| alltags = [] | |
| File.open(ACTIVE_SERVERS).each do |line| | |
| tokens = line.split(/\s+/) |
| # encoding: UTF-8 | |
| require 'slim' | |
| require 'marc' | |
| # Get a record somehow. Here, I just nab the marc-in-json from the HT catalog and use that. | |
| require 'json' | |
| require 'open-uri' | |
| rec = MARC::Record.new_from_hash(JSON.parse(open('http://catalog.hathitrust.org/Record/100113248.json').read)) |
| require 'traject' | |
| include Traject::Macros::Marc21 | |
| r = MARC::Record.new | |
| r << MARC::ControlField.new('001', '12345') | |
| r << MARC::DataField.new('245', ' ', ' ', ['a', 'My Title']) | |
| context = Traject::Indexer::Context.new |
| module A | |
| def hello | |
| puts "Hello from A" | |
| end | |
| def goodbye | |
| puts "Goodbye from A" | |
| end | |
| end | |
| class B |
| class A | |
| include Enumerable | |
| def each | |
| (1..10).each do |i| | |
| raise RuntimeError.new("SIX") if i == 6 | |
| yield i | |
| end | |
| end | |
| end |