active-fedora 2.3.3 → 2.3.4
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/.gitignore +1 -0
- data/CONSOLE_GETTING_STARTED.textile +2 -2
- data/Gemfile +1 -13
- data/Gemfile.lock +30 -33
- data/History.txt +5 -1
- data/NOKOGIRI_DATASTREAMS.textile +1 -1
- data/README.textile +1 -2
- data/active-fedora.gemspec +8 -5
- data/config/fedora.yml +3 -12
- data/lib/active_fedora.rb +176 -49
- data/lib/active_fedora/active_fedora_configuration_exception.rb +2 -0
- data/lib/active_fedora/base.rb +18 -5
- data/lib/active_fedora/model.rb +0 -2
- data/lib/active_fedora/nokogiri_datastream.rb +3 -2
- data/lib/active_fedora/relationship.rb +7 -4
- data/lib/active_fedora/rels_ext_datastream.rb +10 -4
- data/lib/active_fedora/semantic_node.rb +7 -2
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +24 -9
- data/spec/fixtures/rails_root/config/fake_fedora.yml +7 -0
- data/spec/fixtures/rails_root/config/solr.yml +15 -0
- data/spec/integration/full_featured_model_spec.rb +9 -0
- data/spec/unit/active_fedora_spec.rb +308 -16
- data/spec/unit/base_spec.rb +5 -0
- data/spec/unit/nokogiri_datastream_spec.rb +7 -0
- data/spec/unit/relationship_spec.rb +15 -1
- data/spec/unit/rels_ext_datastream_spec.rb +8 -4
- metadata +128 -75
data/.gitignore
CHANGED
@@ -305,7 +305,7 @@ ActiveFedora::Base.find(:all)
|
|
305
305
|
SpecialThing.find(:all)
|
306
306
|
</pre>
|
307
307
|
|
308
|
-
|
308
|
+
You can also query solr directly like so:
|
309
309
|
|
310
310
|
<pre>
|
311
311
|
solr_result = ActiveFedora::SolrService.instance.conn.query('has_model_s:info\:fedora/afmodel\:SpecialThing')
|
@@ -366,5 +366,5 @@ Notice that properties and DC have been loaded as ActiveFedora::Datastream, RELS
|
|
366
366
|
|
367
367
|
h2. Where to Find More Information
|
368
368
|
|
369
|
-
You can examine the files in lib/active_fedora/samples to learn more about how to define ActiveFedora models and OM-based datastreams. We also suggest you read about "OM-based NokogiriDatastreams":
|
369
|
+
You can examine the files in lib/active_fedora/samples to learn more about how to define ActiveFedora models and OM-based datastreams. We also suggest you read about "OM-based NokogiriDatastreams":http://hudson.projecthydra.org/job/active_fedora/Documentation/file.NOKOGIRI_DATASTREAMS.html to learn about manipulating XML contained in datastreams.
|
370
370
|
|
data/Gemfile
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
gem "jeweler"
|
5
|
-
gem "rspec", "<2.0.0"
|
6
|
-
gem "mocha", ">= 0.9.8"
|
7
|
-
gem "ruby-debug"
|
8
|
-
gem "jettywrapper"
|
9
|
-
gem "rcov"
|
10
|
-
gem "yard"
|
11
|
-
gem "RedCloth"
|
12
|
-
gem "solrizer-fedora"
|
13
|
-
end
|
14
|
-
|
15
|
-
# Bundler will rely on active-fedora.gemspec (which is generated by Jeweler section of Rakefile) for runtime dependency information.
|
3
|
+
# Bundler will rely on active-fedora.gemspec for dependency information.
|
16
4
|
|
17
5
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active-fedora (2.3.
|
4
|
+
active-fedora (2.3.4)
|
5
5
|
activeresource
|
6
6
|
equivalent-xml
|
7
7
|
facets
|
8
8
|
mediashelf-loggable
|
9
9
|
mime-types (>= 1.16)
|
10
|
-
multipart-post
|
10
|
+
multipart-post (= 1.1.2)
|
11
11
|
nokogiri
|
12
12
|
om (>= 1.0)
|
13
13
|
solr-ruby (>= 0.0.6)
|
@@ -18,33 +18,33 @@ GEM
|
|
18
18
|
remote: http://rubygems.org/
|
19
19
|
specs:
|
20
20
|
RedCloth (4.2.7)
|
21
|
-
activeresource (2.3.
|
22
|
-
activesupport (= 2.3.
|
23
|
-
activesupport (2.3.
|
21
|
+
activeresource (2.3.14)
|
22
|
+
activesupport (= 2.3.14)
|
23
|
+
activesupport (2.3.14)
|
24
24
|
builder (3.0.0)
|
25
|
-
columnize (0.3.
|
26
|
-
daemons (1.1.
|
25
|
+
columnize (0.3.4)
|
26
|
+
daemons (1.1.4)
|
27
27
|
equivalent-xml (0.2.7)
|
28
28
|
nokogiri (>= 1.4.3)
|
29
29
|
facets (2.9.1)
|
30
|
-
|
31
|
-
jettywrapper (0.0.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
mediashelf-loggable (0.4.
|
30
|
+
fastercsv (1.5.4)
|
31
|
+
jettywrapper (0.0.10)
|
32
|
+
logger
|
33
|
+
mediashelf-loggable
|
34
|
+
linecache (0.46)
|
35
|
+
rbx-require-relative (> 0.0.4)
|
36
|
+
logger (1.2.8)
|
37
|
+
mediashelf-loggable (0.4.7)
|
38
38
|
mime-types (1.16)
|
39
39
|
mocha (0.9.12)
|
40
40
|
multipart-post (1.1.2)
|
41
|
-
nokogiri (1.
|
42
|
-
om (1.
|
41
|
+
nokogiri (1.5.0)
|
42
|
+
om (1.3.0)
|
43
43
|
nokogiri (>= 1.4.2)
|
44
|
-
|
45
|
-
|
46
|
-
rcov (0.9.
|
47
|
-
rsolr (1.0.
|
44
|
+
rake (0.9.2)
|
45
|
+
rbx-require-relative (0.0.5)
|
46
|
+
rcov (0.9.10)
|
47
|
+
rsolr (1.0.2)
|
48
48
|
builder (>= 2.1.2)
|
49
49
|
rspec (1.3.2)
|
50
50
|
ruby-debug (0.10.4)
|
@@ -53,24 +53,22 @@ GEM
|
|
53
53
|
ruby-debug-base (0.10.4)
|
54
54
|
linecache (>= 0.3)
|
55
55
|
solr-ruby (0.0.8)
|
56
|
-
solrizer (1.0
|
56
|
+
solrizer (1.1.0)
|
57
57
|
daemons
|
58
58
|
mediashelf-loggable
|
59
|
-
mediashelf-loggable
|
60
|
-
nokogiri
|
61
59
|
nokogiri
|
62
|
-
nokogiri
|
63
|
-
om
|
64
60
|
om (>= 1.0.0)
|
65
61
|
stomp
|
66
62
|
xml-simple
|
67
|
-
solrizer-fedora (1.0
|
68
|
-
active-fedora (>= 2.
|
63
|
+
solrizer-fedora (1.1.0)
|
64
|
+
active-fedora (>= 2.3.0)
|
65
|
+
fastercsv
|
69
66
|
rsolr
|
67
|
+
solr-ruby (>= 0.0.6)
|
70
68
|
solrizer (>= 1.0.0)
|
71
|
-
stomp (1.1.
|
72
|
-
xml-simple (1.0
|
73
|
-
yard (0.
|
69
|
+
stomp (1.1.9)
|
70
|
+
xml-simple (1.1.0)
|
71
|
+
yard (0.7.2)
|
74
72
|
|
75
73
|
PLATFORMS
|
76
74
|
ruby
|
@@ -79,11 +77,10 @@ DEPENDENCIES
|
|
79
77
|
RedCloth
|
80
78
|
active-fedora!
|
81
79
|
jettywrapper
|
82
|
-
jeweler
|
83
80
|
mocha (>= 0.9.8)
|
81
|
+
rake
|
84
82
|
rcov
|
85
83
|
rspec (< 2.0.0)
|
86
84
|
ruby-debug
|
87
|
-
solrizer
|
88
85
|
solrizer-fedora
|
89
86
|
yard
|
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
2.3.4
|
2
|
+
moved dirty assignment to NokogiriDatastream#update_values; added test (Benjamin Armintor)
|
3
|
+
Fixed HYDRA-590
|
4
|
+
|
1
5
|
2.1.0
|
2
6
|
|
3
7
|
HYDRUS-151: Base.update_datastream_attributes now relies on update_indexed_attributes instead of update_attributes. This makes it easier to support non-javascript forms (and makes update_datastream_attributes worth using).
|
@@ -176,4 +180,4 @@ Changelog:
|
|
176
180
|
* Feature #284: solr document id should by a config option instead of hard coded as "id"
|
177
181
|
* Feature #307: ActiveFedora::Base should provide a label setter.
|
178
182
|
* Feature #314: Relationship finder should provide a "response_format" option, default to format of "objects"
|
179
|
-
* Feature #327: Option to turn off solr updates (assume that something else will update Solr for you)
|
183
|
+
* Feature #327: Option to turn off solr updates (assume that something else will update Solr for you)
|
@@ -18,7 +18,7 @@ terminology = doc.class.terminology # The terminology is attached to the Documen
|
|
18
18
|
|
19
19
|
h2. Setup
|
20
20
|
|
21
|
-
This tutorial assumes that you've run script/console from the root of ActiveFedora and have imported the hydrangea:fixture_mods_article1 object. If you haven't done that, see "CONSOLE_GETTING_STARTED":
|
21
|
+
This tutorial assumes that you've run script/console from the root of ActiveFedora and have imported the hydrangea:fixture_mods_article1 object. If you haven't done that, see "CONSOLE_GETTING_STARTED":http://hudson.projecthydra.org/job/active_fedora/Documentation/file.CONSOLE_GETTING_STARTED.html for instructions.
|
22
22
|
|
23
23
|
The model definition we're using in this tutorial is {SpecialThing} ( "see the code":https://github.com/mediashelf/active_fedora/blob/master/lib/active_fedora/samples/special_thing.rb )
|
24
24
|
|
data/README.textile
CHANGED
@@ -5,7 +5,6 @@ RubyFedora and ActiveFedora provide a set of Ruby gems for creating and managing
|
|
5
5
|
h2. Getting Help
|
6
6
|
|
7
7
|
* Project Homepage: "http://yourmediashelf.com/activefedora":http://yourmediashelf.com/activefedora
|
8
|
-
* Further documentation is available at "http://projects.mediashelf.us/projects/active-fedora":http://projects.mediashelf.us/projects/active-fedora
|
9
8
|
* Community Discussions & Mailing List are located at "http://groups.google.com/group/active-fedora":http://groups.google.com/group/active-fedora
|
10
9
|
|
11
10
|
h2. Installation
|
@@ -16,7 +15,7 @@ The gem is hosted on gemcutter.
|
|
16
15
|
|
17
16
|
h2. Getting Started
|
18
17
|
|
19
|
-
The "ActiveFedora Console Tour":
|
18
|
+
The "ActiveFedora Console Tour":http://hudson.projecthydra.org/job/active_fedora/Documentation/file.CONSOLE_GETTING_STARTED.html gives you a brief tour through ActiveFedora's features on the command line.
|
20
19
|
|
21
20
|
h2. Testing (this Gem)
|
22
21
|
|
data/active-fedora.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency('solr-ruby', '>= 0.0.6')
|
19
19
|
s.add_dependency('xml-simple', '>= 1.0.12')
|
20
20
|
s.add_dependency('mime-types', '>= 1.16')
|
21
|
-
s.add_dependency('multipart-post')
|
21
|
+
s.add_dependency('multipart-post', "1.1.2")
|
22
22
|
s.add_dependency('nokogiri')
|
23
23
|
s.add_dependency('om', '>= 1.0')
|
24
24
|
s.add_dependency('solrizer', '>1.0.0')
|
@@ -27,12 +27,15 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_dependency("equivalent-xml")
|
28
28
|
s.add_dependency("facets")
|
29
29
|
s.add_development_dependency("yard")
|
30
|
-
s.add_development_dependency("RedCloth")
|
30
|
+
s.add_development_dependency("RedCloth") # for RDoc formatting
|
31
|
+
s.add_development_dependency("rake")
|
31
32
|
s.add_development_dependency("rcov")
|
32
|
-
s.add_development_dependency("solrizer")
|
33
|
-
s.add_development_dependency("solrizer-fedora")
|
33
|
+
s.add_development_dependency("solrizer-fedora") # used by the fixtures rake tasks
|
34
34
|
s.add_development_dependency("jettywrapper")
|
35
|
-
|
35
|
+
s.add_development_dependency("rspec", "<2.0.0")
|
36
|
+
s.add_development_dependency("mocha", ">= 0.9.8")
|
37
|
+
s.add_development_dependency("ruby-debug")
|
38
|
+
|
36
39
|
s.files = `git ls-files`.split("\n")
|
37
40
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
38
41
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/config/fedora.yml
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
development:
|
2
|
-
fedora
|
3
|
-
url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora
|
4
|
-
solr:
|
5
|
-
url: http://127.0.0.1:8983/solr/development
|
2
|
+
url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora
|
6
3
|
test:
|
7
|
-
fedora
|
8
|
-
url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora
|
9
|
-
solr:
|
10
|
-
url: http://127.0.0.1:8983/solr/test
|
4
|
+
url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8983/fedora
|
11
5
|
production:
|
12
|
-
fedora
|
13
|
-
url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora
|
14
|
-
solr:
|
15
|
-
url: http://127.0.0.1:8080/solr
|
6
|
+
url: http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora
|
16
7
|
|
data/lib/active_fedora.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require "bundler/setup"
|
3
|
+
Bundler.require(:default)
|
4
|
+
|
2
5
|
gem 'solr-ruby'
|
3
6
|
require "loggable"
|
4
7
|
|
@@ -32,64 +35,204 @@ module ActiveFedora #:nodoc:
|
|
32
35
|
include Loggable
|
33
36
|
|
34
37
|
class << self
|
35
|
-
attr_accessor :solr_config, :fedora_config, :config_env
|
38
|
+
attr_accessor :solr_config, :fedora_config, :config_env, :fedora_config_path, :solr_config_path
|
39
|
+
attr_reader :config_options
|
36
40
|
end
|
37
41
|
|
38
42
|
# The configuration hash that gets used by RSolr.connect
|
39
43
|
@solr_config ||= {}
|
40
44
|
@fedora_config ||= {}
|
41
45
|
|
42
|
-
# Initializes ActiveFedora's connection to Fedora and Solr based on the info in fedora.yml
|
46
|
+
# Initializes ActiveFedora's connection to Fedora and Solr based on the info in fedora.yml and solr.yml
|
47
|
+
# NOTE: this deprecates the use of a solr url in the fedora.yml
|
48
|
+
#
|
49
|
+
#
|
43
50
|
# If Rails.env is set, it will use that environment. Defaults to "development".
|
44
|
-
# @param [
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
# @param [Hash] options (optional) a list of options for the configuration of active_fedora
|
52
|
+
# @option options [String] :environment The environment within which to run
|
53
|
+
# @option options [String] :fedora_config_path The full path to the fedora.yml config file.
|
54
|
+
# @option options [String] :solr_config_path The full path to the solr.yml config file.
|
55
|
+
#
|
56
|
+
# If :environment is not set, order of preference is
|
57
|
+
# 1. Rails.env
|
58
|
+
# 2. ENV['environment']
|
59
|
+
# 3. RAILS_ENV
|
60
|
+
#
|
61
|
+
# If :fedora_config_path is not set, it will look in
|
62
|
+
# 1. +Rails.root+/config
|
63
|
+
# 2. +current working directory+/config
|
64
|
+
# 3. (default) the fedora.yml shipped with gem
|
65
|
+
#
|
66
|
+
# If :solr_config_path is not set, it will
|
67
|
+
# 1. look in config_options[:fedora_config_path]. If it finds a solr.yml there, it will use it.
|
68
|
+
# 2. If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
|
69
|
+
# 3. If it does not find a solr.yml and the fedora.yml does not contain a solr url, it will look in: +Rails.root+/config, +current working directory+/config, then the solr.yml shipped with gem
|
70
|
+
def self.init( options={} )
|
71
|
+
logger.level = Logger::ERROR
|
72
|
+
# Make config_options into a Hash if nil is passed in as the value
|
73
|
+
options = {} if options.nil?
|
74
|
+
|
75
|
+
# For backwards compatibility, handle cases where config_path (a String) is passed in as the argument rather than a config_options hash
|
76
|
+
# In all other cases, set config_path to config_options[:config_path], which is ok if it's nil
|
77
|
+
if options.is_a? String
|
78
|
+
logger.warn "DEPRECATION WARNING: Calling ActiveFedora.init with a path as an argument is deprecated. Use ActiveFedora.init(:config_path=>#{options})"
|
79
|
+
@config_options = {:fedora_config_path=>options}
|
80
|
+
else
|
81
|
+
@config_options = options
|
55
82
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
83
|
+
|
84
|
+
@config_env = environment
|
85
|
+
@fedora_config_path = get_config_path(:fedora)
|
86
|
+
load_config(:fedora)
|
87
|
+
|
88
|
+
@solr_config_path = get_config_path(:solr)
|
89
|
+
load_config(:solr)
|
90
|
+
|
91
|
+
register_fedora_and_solr
|
92
|
+
|
93
|
+
# Retrieve the valid path for the predicate mappings config file
|
94
|
+
@predicate_config_path = build_predicate_config_path(File.dirname(fedora_config_path))
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.load_configs
|
99
|
+
load_config(:fedora)
|
100
|
+
load_config(:solr)
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.load_config(config_type)
|
104
|
+
config_type = config_type.to_s
|
105
|
+
config_path = self.send("#{config_type}_config_path".to_sym)
|
106
|
+
|
107
|
+
logger.info("#{config_type.upcase}: loading ActiveFedora.#{config_type}_config from #{File.expand_path(config_path)}")
|
108
|
+
config = YAML::load(File.open(config_path))
|
109
|
+
raise "The #{@config_env.to_s} environment settings were not found in the #{config_type}.yml config. If you already have a #{config_type}.yml file defined, make sure it defines settings for the #{@config_env} environment" unless config[@config_env]
|
110
|
+
|
111
|
+
config[:url] = determine_url(config_type,config)
|
112
|
+
|
113
|
+
self.instance_variable_set("@#{config_type}_config", config)
|
114
|
+
config
|
115
|
+
end
|
116
|
+
|
117
|
+
# Determines and sets the fedora_config[:url] or solr_config[:url]
|
118
|
+
# @param [String] config_type Either 'fedora' or 'solr'
|
119
|
+
# @param [Hash] config The config hash
|
120
|
+
# @return [String] the solr or fedora url
|
121
|
+
def self.determine_url(config_type,config)
|
122
|
+
if config_type == "fedora"
|
123
|
+
# support old-style config
|
124
|
+
if config[environment].fetch("fedora",nil)
|
125
|
+
return config[environment]["fedora"]["url"] if config[environment].fetch("fedora",nil)
|
60
126
|
else
|
61
|
-
|
127
|
+
return config[environment]["url"]
|
62
128
|
end
|
129
|
+
else
|
130
|
+
return get_solr_url(config[environment]) if config_type == "solr"
|
63
131
|
end
|
132
|
+
end
|
64
133
|
|
65
|
-
|
66
|
-
|
67
|
-
|
134
|
+
# Given the solr_config that's been loaded for this environment,
|
135
|
+
# determine which solr url to use
|
136
|
+
def self.get_solr_url(solr_config)
|
137
|
+
if @index_full_text == true && solr_config.has_key?('fulltext') && solr_config['fulltext'].has_key?('url')
|
138
|
+
return solr_config['fulltext']['url']
|
139
|
+
elsif solr_config.has_key?('default') && solr_config['default'].has_key?('url')
|
140
|
+
return solr_config['default']['url']
|
141
|
+
elsif solr_config.has_key?('url')
|
142
|
+
return solr_config['url']
|
143
|
+
elsif solr_config.has_key?(:url)
|
144
|
+
return solr_config[:url]
|
145
|
+
else
|
146
|
+
raise URI::InvalidURIError
|
68
147
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
raise "The #{@config_env.to_s} environment settings were not found in the fedora.yml config. If you already have a fedora.yml file defined, make sure it defines settings for the #{@config_env} environment" unless fedora_config[@config_env]
|
73
|
-
|
74
|
-
ActiveFedora.solr_config[:url] = fedora_config[@config_env]['solr']['url']
|
75
|
-
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.register_fedora_and_solr
|
76
151
|
# Register Solr
|
77
152
|
logger.info("FEDORA: initializing ActiveFedora::SolrService with solr_config: #{ActiveFedora.solr_config.inspect}")
|
78
|
-
|
79
153
|
ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
|
80
154
|
logger.info("FEDORA: initialized Solr with ActiveFedora.solr_config: #{ActiveFedora::SolrService.instance.inspect}")
|
81
155
|
|
82
|
-
ActiveFedora.fedora_config[:url] = fedora_config[@config_env]['fedora']['url']
|
83
156
|
logger.info("FEDORA: initializing Fedora with fedora_config: #{ActiveFedora.fedora_config.inspect}")
|
84
|
-
|
85
157
|
Fedora::Repository.register(ActiveFedora.fedora_config[:url])
|
86
158
|
logger.info("FEDORA: initialized Fedora as: #{Fedora::Repository.instance.inspect}")
|
87
159
|
|
88
|
-
|
89
|
-
|
160
|
+
end
|
161
|
+
|
162
|
+
# Determine what environment we're running in. Order of preference is:
|
163
|
+
# 1. config_options[:environment]
|
164
|
+
# 2. Rails.env
|
165
|
+
# 3. ENV['environment']
|
166
|
+
# 4. ENV['RAILS_ENV']
|
167
|
+
# 5. raises an exception if none of these is set
|
168
|
+
# @return [String]
|
169
|
+
# @example
|
170
|
+
# ActiveFedora.init(:environment=>"test")
|
171
|
+
# ActiveFedora.environment => "test"
|
172
|
+
def self.environment
|
173
|
+
if config_options.fetch(:environment,nil)
|
174
|
+
return config_options[:environment]
|
175
|
+
elsif defined?(Rails.env) and !Rails.env.nil?
|
176
|
+
return Rails.env.to_s
|
177
|
+
elsif defined?(ENV['environment']) and !(ENV['environment'].nil?)
|
178
|
+
return ENV['environment']
|
179
|
+
elsif defined?(ENV['RAILS_ENV']) and !(ENV['RAILS_ENV'].nil?)
|
180
|
+
logger.warn("You're depending on RAILS_ENV for setting your environment. This is deprecated in Rails3. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'")
|
181
|
+
ENV['environment'] = ENV['RAILS_ENV']
|
182
|
+
return ENV['environment']
|
183
|
+
else
|
184
|
+
raise "Can't determine what environment to run in!"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Determine the fedora config file to use. Order of preference is:
|
189
|
+
# 1. Use the config_options[:config_path] if it exists
|
190
|
+
# 2. Look in +Rails.root+/config/fedora.yml
|
191
|
+
# 3. Look in +current working directory+/config/fedora.yml
|
192
|
+
# 4. Load the default config that ships with this gem
|
193
|
+
# @param [String] config_type Either ‘fedora’ or ‘solr’
|
194
|
+
# @return [String]
|
195
|
+
def self.get_config_path(config_type)
|
196
|
+
config_type = config_type.to_s
|
197
|
+
if (config_path = config_options.fetch("#{config_type}_config_path".to_sym,nil) )
|
198
|
+
raise ActiveFedoraConfigurationException unless File.file? config_path
|
199
|
+
return config_path
|
200
|
+
end
|
201
|
+
|
202
|
+
# if solr, attempt to use path where fedora.yml is first
|
203
|
+
if config_type == "solr" && (config_path = check_fedora_path_for_solr)
|
204
|
+
return config_path
|
205
|
+
elsif config_type == "solr" && fedora_config[environment].fetch("solr",nil)
|
206
|
+
logger.warn("DEPRECATION WARNING: You appear to be using a deprecated format for your fedora.yml file. The solr url should be stored in a separate solr.yml file in the same directory as the fedora.yml")
|
207
|
+
raise ActiveFedoraConfigurationException
|
208
|
+
end
|
90
209
|
|
210
|
+
if defined?(Rails.root)
|
211
|
+
config_path = "#{Rails.root}/config/#{config_type}.yml"
|
212
|
+
return config_path if File.file? config_path
|
213
|
+
end
|
214
|
+
|
215
|
+
if File.file? "#{Dir.getwd}/config/#{config_type}.yml"
|
216
|
+
return "#{Dir.getwd}/config/#{config_type}.yml"
|
217
|
+
end
|
218
|
+
|
219
|
+
# Last choice, check for the default config file
|
220
|
+
config_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "#{config_type}.yml"))
|
221
|
+
logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type} => '/path/to/#{config_type}.yml) - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
|
222
|
+
return config_path if File.file? config_path
|
223
|
+
raise ActiveFedoraConfigurationException "Couldn't load #{config_type} config file!"
|
91
224
|
end
|
92
225
|
|
226
|
+
# Checks the existing fedora_config_path to see if there is a solr.yml there
|
227
|
+
def self.check_fedora_path_for_solr
|
228
|
+
path = fedora_config_path.split('/')[0..-2].join('/') + "/solr.yml"
|
229
|
+
if File.file? path
|
230
|
+
return path
|
231
|
+
else
|
232
|
+
return nil
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
93
236
|
def self.solr
|
94
237
|
ActiveFedora::SolrService.instance
|
95
238
|
end
|
@@ -130,22 +273,6 @@ module ActiveFedora #:nodoc:
|
|
130
273
|
|
131
274
|
end
|
132
275
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# if ![].respond_to?(:count)
|
138
|
-
# class Array
|
139
|
-
# puts "active_fedora is Adding count method to Array"
|
140
|
-
# def count(&action)
|
141
|
-
# count = 0
|
142
|
-
# self.each { |v| count = count + 1}
|
143
|
-
# # self.each { |v| count = count + 1 if action.call(v) }
|
144
|
-
# return count
|
145
|
-
# end
|
146
|
-
# end
|
147
|
-
# end
|
148
|
-
|
149
276
|
module ActiveFedora
|
150
277
|
class ServerError < Fedora::ServerError; end # :nodoc:
|
151
278
|
class ObjectNotFoundError < RuntimeError; end # :nodoc:
|