cul-fedora 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.8.3
data/cul-fedora.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cul-fedora}
8
- s.version = "0.8.2"
8
+ s.version = "0.8.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Stuart"]
12
- s.date = %q{2011-06-01}
12
+ s.date = %q{2011-06-02}
13
13
  s.description = %q{Columbia-specific Fedora libraries}
14
14
  s.email = %q{tastyhat@jamesstuart.org}
15
15
  s.extra_rdoc_files = [
@@ -3,12 +3,12 @@ require "open3"
3
3
  module Cul
4
4
  module Fedora
5
5
  class Item
6
+
6
7
  attr_reader :server, :pid
7
8
  include Open3
8
9
 
9
10
  URI_TO_PID = 'info:fedora/'
10
11
 
11
-
12
12
  def <=>(other)
13
13
  pid <=> other.pid
14
14
  end
@@ -20,10 +20,15 @@ module Cul
20
20
  def initialize(*args)
21
21
  options = args.extract_options!
22
22
  @server = options[:server] || Server.new(options[:server_config])
23
+ @logger = options[:logger]
23
24
  @pid = options[:pid] || options[:uri] || raise(ArgumentError, "requires uri or pid")
24
25
  @pid = @pid.to_s.sub(URI_TO_PID, "")
25
26
  end
26
27
 
28
+ def logger
29
+ @logger ||= Logger.new
30
+ end
31
+
27
32
  def ==(other)
28
33
  self.server == other.server
29
34
  self.pid == other.pid
@@ -1,20 +1,24 @@
1
1
  module Cul
2
2
  module Fedora
3
3
  class Server
4
+
4
5
  attr_reader :riurl, :riquery
5
6
 
6
7
  def initialize(*args)
7
8
  options = args.extract_options!
8
9
  @riurl = options[:riurl] || raise(ArgumentError, "Must provide riurl argument")
9
10
  @riquery = options[:riquery] || raise(ArgumentError, "Must provide riquery argument")
10
- @hc = options[:http_client]
11
+ @hc = options[:http_client]
12
+ @logger = options[:logger]
11
13
  end
12
14
 
13
- def item(uri)
14
- Item.new(:server => self, :uri => uri)
15
+ def logger
16
+ @logger ||= Logger.new(STDOUT)
15
17
  end
16
18
 
17
-
19
+ def item(uri)
20
+ Item.new(:server => self, :uri => uri, :logger => logger)
21
+ end
18
22
 
19
23
  def request(options= {})
20
24
  http_client.get_content(*request_path(options))
@@ -37,16 +41,13 @@ module Cul
37
41
  return [uri, query]
38
42
  end
39
43
 
40
- def inspect
41
- '#<Cul::Fedora::Server:' + self.object_id.to_s + ' @riurl="' + @riurl + '">'
42
- end
43
-
44
44
  private
45
45
 
46
46
  def http_client
47
47
  @hc ||= HTTPClient.new()
48
48
  @hc
49
49
  end
50
+
50
51
  end
51
52
  end
52
53
  end
@@ -1,10 +1,16 @@
1
1
  module Cul
2
2
  module Fedora
3
3
  class Solr
4
+
4
5
  attr_reader :url
6
+
5
7
  def initialize(config = {})
6
8
  @url = config[:url] || raise(ArgumentError, "must provide url")
9
+ @logger = config[:logger]
10
+ end
7
11
 
12
+ def logger
13
+ @logger ||= Logger.new(STDOUT)
8
14
  end
9
15
 
10
16
  def item_exists?(item)
@@ -25,12 +31,12 @@ module Cul
25
31
  start = 0
26
32
  rows = 500
27
33
  results = rsolr.select({:q => "", :fl => "id", :start => start, :rows => rows})
28
- $stdout.puts "Deleting items removed from Fedora..."
34
+ logger.info "Deleting items removed from Fedora..."
29
35
  while(!results["response"]["docs"].empty?)
30
36
 
31
37
  results["response"]["docs"].each do |doc|
32
38
  if(!fedora_server.item(doc["id"]).exists?)
33
- $stdout.puts "Deleting " + doc["id"] + "..."
39
+ logger.info "Deleting " + doc["id"] + "..."
34
40
  rsolr.delete_by_query("id:" + doc["id"].to_s.gsub(/:/,'\\:'))
35
41
  end
36
42
  end
@@ -77,7 +83,7 @@ module Cul
77
83
  items.each do |i|
78
84
 
79
85
  if(ignore.index(i.pid).nil? == false)
80
- $stdout.puts "Ignoring " + i.pid + "..."
86
+ logger.info "Ignoring " + i.pid + "..."
81
87
  next
82
88
  end
83
89
 
@@ -95,7 +101,7 @@ module Cul
95
101
  end
96
102
 
97
103
 
98
- $stdout.puts "Indexing " + i.pid + "..."
104
+ logger.info "Indexing " + i.pid + "..."
99
105
 
100
106
  result_hash = i.send("index_for_#{format}", options)
101
107
 
@@ -114,7 +120,7 @@ module Cul
114
120
  end
115
121
 
116
122
  if to_add.length >= 500
117
- $stdout.puts "Adding Batch..."
123
+ logger.info "Adding batch to commit queue..."
118
124
  rsolr.add(to_add)
119
125
  to_add.clear
120
126
  end
@@ -122,10 +128,12 @@ module Cul
122
128
  end
123
129
 
124
130
  if to_add.length > 0
125
- $stdout.puts "Adding Batch..."
131
+ logger.info "Adding batch to commit queue..."
126
132
  rsolr.add(to_add)
127
133
  to_add.clear
128
134
  end
135
+
136
+ logger.info "Committing changes to Solr..."
129
137
  rsolr.commit
130
138
 
131
139
  return {:results => results, :errors => errors}
@@ -133,7 +141,5 @@ module Cul
133
141
  end
134
142
 
135
143
  end
136
-
137
-
138
144
  end
139
145
  end
data/lib/cul-fedora.rb CHANGED
@@ -4,7 +4,7 @@ require "activesupport"
4
4
  require "rsolr"
5
5
  require "rsolr-ext"
6
6
  require "open3"
7
-
7
+ require "logger"
8
8
 
9
9
  require "cul-fedora/item"
10
10
  require "cul-fedora/server"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cul-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Stuart
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-01 00:00:00 -04:00
18
+ date: 2011-06-02 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency