fixlr-dspace-ruby 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nathan Fixler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,12 @@
1
+ = dspace-ruby
2
+
3
+ Dspace::Config class that can be used to parse the data from a
4
+ DSpace (www.dspace.org) configuration file to be used within a Ruby script
5
+ so that you do not have to duplicate server configuration values outside the
6
+ main configuration file.
7
+
8
+ See example file(s) and specs for usage.
9
+
10
+ == Copyright
11
+
12
+ Copyright (c) 2009 Nathan Fixler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dspace-ruby"
8
+ gem.summary = %Q{Collection of tools for working with a DSpace repository in Ruby.}
9
+ gem.email = "nathan@fixler.org"
10
+ gem.homepage = "http://github.com/fixlr/dspace-ruby"
11
+ gem.authors = ["Nathan Fixler"]
12
+
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "dspace-ruby #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
@@ -0,0 +1,17 @@
1
+ # Far, far from a complete ActiveRecord configuration for DSpace.
2
+
3
+ require 'active_record'
4
+
5
+ # Override the save methods because I don't want to
6
+ # accidentally overwrite something in the DSpace DB.
7
+ class ActiveRecord::Base
8
+ def save
9
+ false
10
+ end
11
+ def save!
12
+ false
13
+ end
14
+ end
15
+ ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
16
+
17
+ Dir.glob(File.join(File.dirname(__FILE__), 'active_record', '*.rb')).each {|f| require f }
@@ -0,0 +1,23 @@
1
+ class Collection < ActiveRecord::Base
2
+ set_table_name "collection"
3
+ has_and_belongs_to_many :items,
4
+ :class_name => "Item",
5
+ :join_table => "collection2item",
6
+ :association_foreign_key => "item_id",
7
+ :foreign_key => "collection_id"
8
+
9
+ has_and_belongs_to_many :parent_community,
10
+ :class_name => "Community",
11
+ :join_table => "community2collection",
12
+ :association_foreign_key => "community_id",
13
+ :foreign_key => "collection_id"
14
+
15
+ has_many :items,
16
+ :class_name => "Item",
17
+ :foreign_key => "owning_collection"
18
+
19
+ has_one :handle,
20
+ :class_name => "Handle",
21
+ :foreign_key => "resource_id",
22
+ :conditions => "resource_type_id = 3"
23
+ end
@@ -0,0 +1,33 @@
1
+ class Community < ActiveRecord::Base
2
+ set_table_name "community"
3
+ has_and_belongs_to_many :items,
4
+ :class_name => "Item",
5
+ :join_table => "community2item",
6
+ :association_foreign_key => "item_id",
7
+ :foreign_key => "community_id"
8
+
9
+ has_and_belongs_to_many :sub_communities,
10
+ :class_name => "Community",
11
+ :join_table => "community2community",
12
+ :association_foreign_key => "child_comm_id",
13
+ :foreign_key => "parent_comm_id"
14
+
15
+ has_and_belongs_to_many :parent_community,
16
+ :class_name => "Community",
17
+ :join_table => "community2community",
18
+ :association_foreign_key => "parent_comm_id",
19
+ :foreign_key => "child_comm_id"
20
+
21
+ has_one :handle,
22
+ :class_name => "Handle",
23
+ :foreign_key => "resource_id",
24
+ :conditions => "resource_type_id = 4"
25
+
26
+ def self.find_all_top_level
27
+ Community.find_by_sql("SELECT community.* FROM community WHERE community_id NOT IN (SELECT child_comm_id FROM community2community)")
28
+ end
29
+
30
+ def self.find_all_sub_communities
31
+ Community.find_by_sql("SELECT community.* FROM community WHERE community_id IN (SELECT child_comm_id FROM community2community)")
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ class Handle < ActiveRecord::Base
2
+ set_table_name "handle"
3
+ has_many :communities,
4
+ :class_name => "Community",
5
+ :foreign_key => "resource_id",
6
+ :conditions => "resource_type_id = 4"
7
+
8
+ def to_s
9
+ self.handle
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ class Item < ActiveRecord::Base
2
+ set_table_name "item"
3
+
4
+ has_and_belongs_to_many :community,
5
+ :class_name => "Community",
6
+ :join_table => "communities2item",
7
+ :association_foreign_key => "community_id",
8
+ :foreign_key => "item_id"
9
+
10
+ has_and_belongs_to_many :communities,
11
+ :class_name => "Community",
12
+ :join_table => "communities2item",
13
+ :association_foreign_key => "community_id",
14
+ :foreign_key => "item_id" do
15
+ def top_level
16
+ find :first, :order => "id DESC"
17
+ end
18
+ end
19
+
20
+ belongs_to :collection,
21
+ :class_name => "Collection",
22
+ :foreign_key => "owning_collection"
23
+ end
@@ -0,0 +1,57 @@
1
+ module Dspace
2
+ class Config
3
+ attr_accessor :opts
4
+
5
+ def initialize
6
+ self.opts = {}
7
+ end
8
+
9
+ def [] (k)
10
+ opts[k]
11
+ end
12
+
13
+ def []= (k, v)
14
+ opts[k] = v
15
+ end
16
+
17
+ def length
18
+ opts.length
19
+ end
20
+
21
+ # def find
22
+
23
+ def self.load(path)
24
+ if File.exist?(path)
25
+ Config.parse File.read(path)
26
+ else
27
+ raise "Configuration file does not exist. #{path}"
28
+ end
29
+ end
30
+
31
+ def self.parse(config)
32
+ retval = Config.new
33
+
34
+ line_stack = []
35
+ config.each do |line|
36
+ line.sub!(/\#(.+?)$/, '') # ignore comments
37
+
38
+ # join multi-line statements
39
+ if line.strip =~ /\\$/
40
+ line_stack.push line.sub(/\\/, '').strip
41
+ next
42
+ elsif line_stack.length != 0
43
+ line = (line_stack + [line]).join(' ')
44
+ line_stack = []
45
+ end
46
+
47
+ l = line.split('=').collect {|i| i.strip}
48
+ if l.length > 1
49
+ key = l.delete_at(0)
50
+ val = l.join(' = ').split(',').collect {|i| i.strip}
51
+ retval[key] = val.length == 1 ? val.first : val
52
+ end
53
+ end
54
+ retval
55
+ end
56
+ end
57
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'dspace', 'config')
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class DspaceConfigTest < Test::Unit::TestCase
4
+ should "set a single key and value from the config file" do
5
+ c = config_parse("foo = bar")
6
+ assert_equal c.length, 1
7
+ assert_equal c['foo'], 'bar'
8
+ end
9
+
10
+ should "set multiple keys and values from the config file" do
11
+ c = config_parse("foo1 = bar1\nfoo2 = bar2")
12
+ assert_equal c.length, 2
13
+ assert_equal c['foo2'], 'bar2'
14
+ end
15
+
16
+ should "ignore full comment lines" do
17
+ c = config_parse('# Comment Line')
18
+ assert_equal c.length, 0
19
+ end
20
+
21
+ should "ignore partial-line comments" do
22
+ c = config_parse('foo = bar # partial line comment')
23
+ assert_equal c.length, 1
24
+ assert_equal c['foo'], 'bar'
25
+ end
26
+
27
+ should "parse multi-line statements as value arrays" do
28
+ c = config_parse(%{foo = bar, \\\nbaz})
29
+ assert_equal c.length, 1
30
+ assert_equal c['foo'], ['bar', 'baz']
31
+ end
32
+
33
+ should "parse multi-line statements beginning with a new line (instead of a value)" do
34
+ c = config_parse(%{foo = \\\nbar})
35
+ assert_equal c.length, 1
36
+ assert_equal c['foo'], 'bar'
37
+ end
38
+
39
+ should "allow '=' characters in a value" do
40
+ c = config_parse('foo = bar = baz')
41
+ assert_equal c.length, 1
42
+ assert_equal c['foo'], 'bar = baz'
43
+ end
44
+
45
+ should "allow '=' characters in multi-line values" do
46
+ c = config_parse(%{foo = \\\n\tbar = baz, \\\n\tbop = bip})
47
+ assert_equal c.length, 1
48
+ assert_equal c['foo'], ['bar = baz', 'bop = bip']
49
+ end
50
+
51
+ def config_parse(c)
52
+ Dspace::Config.parse(c)
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'dspace/config'
8
+ require 'dspace/active_record'
9
+
10
+ class Test::Unit::TestCase
11
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixlr-dspace-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Fixler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-29 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: nathan@fixler.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - lib/dspace/active_record.rb
31
+ - lib/dspace/active_record/collection.rb
32
+ - lib/dspace/active_record/community.rb
33
+ - lib/dspace/active_record/handle.rb
34
+ - lib/dspace/active_record/item.rb
35
+ - lib/dspace/config.rb
36
+ - lib/dspace_ruby.rb
37
+ - test/dspace_config_test.rb
38
+ - test/test_helper.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/fixlr/dspace-ruby
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.2.0
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Collection of tools for working with a DSpace repository in Ruby.
65
+ test_files:
66
+ - test/dspace_config_test.rb
67
+ - test/test_helper.rb