ruby-fedora 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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-03-31
2
+
3
+ * very alpha enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,58 @@
1
+ Copyright (c) 2008 Matt Zumwalt <matt.zumwalt@yourmediashelf.com>
2
+
3
+ You can redistribute it and/or modify it under either the terms of the GPL
4
+ or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) rename any non-standard executables so the names do not conflict
22
+ with standard executables, which must also be provided.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or executable
27
+ form, provided that you do at least ONE of the following:
28
+
29
+ a) distribute the executables and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c) give non-standard executables non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under this terms.
44
+
45
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
46
+ files under the ./missing directory. See each file for the copying
47
+ condition.
48
+
49
+ 5. The scripts and library files supplied as input to or produced as
50
+ output from the software do not automatically fall under the
51
+ copyright of the software, but belong to whomever generated them,
52
+ and may be sold commercially, and may be aggregated with this
53
+ software.
54
+
55
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
56
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
57
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58
+ PURPOSE.
data/Manifest.txt ADDED
@@ -0,0 +1,34 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/ruby-fedora.rb
9
+ lib/fedora/base_object.rb
10
+ lib/fedora/connection.rb
11
+ lib/fedora/datastream.rb
12
+ lib/fedora/fedora_object.rb
13
+ lib/fedora/formats.rb
14
+ lib/fedora/repository.rb
15
+ lib/active-fedora.rb
16
+ lib/active_fedora/base.rb
17
+ lib/ambition/adapters/active_fedora.rb
18
+ lib/ambition/adapters/active_fedora/base.rb
19
+ lib/ambition/adapters/active_fedora/query.rb
20
+ lib/ambition/adapters/active_fedora/select.rb
21
+ lib/ambition/adapters/active_fedora/slice.rb
22
+ lib/ambition/adapters/active_fedora/sort.rb
23
+ script/destroy
24
+ script/generate
25
+ script/txt2html
26
+ setup.rb
27
+ tasks/deployment.rake
28
+ tasks/environment.rake
29
+ tasks/website.rake
30
+ website/index.html
31
+ website/index.txt
32
+ website/javascripts/rounded_corners_lite.inc.js
33
+ website/stylesheets/screen.css
34
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,19 @@
1
+ This should describe how this stuff can be built, tested and used...
2
+
3
+ == Installation
4
+
5
+ Required gems:
6
+ - facets
7
+ - activeresource
8
+
9
+ - syntax
10
+ - ParseTree
11
+ - ambition
12
+
13
+ == TODO
14
+
15
+ - specify gem dependencies in hoe.rb
16
+ - implement finders with Ambition
17
+ - implement ActiveFedora::Base.establish_connection to read from repository.yml (or fedora.yml)
18
+ - remove dependencies on activeresource gem
19
+ - remove anything in test/* that are no longer relevant
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
5
+
data/config/hoe.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'ruby-fedora'
2
+
3
+ AUTHOR = 'Matt Zumwalt' # can also be an array of Authors
4
+ EMAIL = 'matt.zumwalt@yourmediashelf.com>'
5
+ DESCRIPTION = "Ruby API for Fedora"
6
+ GEM_NAME = 'ruby-fedora' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'rubyfedora' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = RubyFedora::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'RubyFedora documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+ p.extra_deps = [['activeresource'], ['facets']]
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+ end
65
+
66
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
67
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
68
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
69
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'ruby-fedora'
@@ -0,0 +1 @@
1
+ require 'active_fedora/base'
@@ -0,0 +1,22 @@
1
+ module ActiveFedora
2
+ class Base
3
+ def self.establish_connection(spec)
4
+ end
5
+
6
+ def initialize(attrs = nil)
7
+ end
8
+
9
+ def self.find_objects(*args)
10
+ puts args.inspect
11
+ end
12
+
13
+ def create
14
+ end
15
+
16
+ def update
17
+ end
18
+
19
+ def save
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'ambition'
2
+ require 'active-fedora'
3
+ require 'ambition/adapters/active_fedora/base'
4
+ require 'ambition/adapters/active_fedora/query'
5
+ require 'ambition/adapters/active_fedora/select'
6
+ require 'ambition/adapters/active_fedora/slice'
7
+ require 'ambition/adapters/active_fedora/sort'
8
+
9
+ ActiveFedora::Base.extend Ambition::API
10
+ ActiveFedora::Base.ambition_adapter = Ambition::Adapters::ActiveFedora
@@ -0,0 +1,14 @@
1
+ module Ambition
2
+ module Adapters
3
+ module ActiveFedora
4
+ class Base
5
+ def encode(value)
6
+ case value
7
+ when String then value.include?(' ') ? %Q('#{value}') : value
8
+ else value.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ =begin
2
+
3
+ These methods are king:
4
+
5
+ - owner
6
+ - clauses
7
+ - stash
8
+
9
+ +owner+ is the class from which the request was generated.
10
+
11
+ User.select { |u| u.name == 'Pork' }
12
+ # => owner == User
13
+
14
+ +clauses+ is the hash of translated arrays, keyed by processors
15
+
16
+ User.select { |u| u.name == 'Pork' }
17
+ # => clauses == { :select => [ "users.name = 'Pork'" ] }
18
+
19
+ +stash+ is your personal private stash. A hash you can use for
20
+ keeping stuff around.
21
+
22
+ User.select { |u| u.profile.name == 'Pork' }
23
+ # => stash == { :include => [ :profile ] }
24
+
25
+ The above is totally arbitrary. It's basically a way for your
26
+ translators to talk to each other and, more importantly, to the Query
27
+ object.
28
+
29
+ =end
30
+ module Ambition
31
+ module Adapters
32
+ module ActiveFedora
33
+ class Query < Base
34
+ def kick
35
+ owner.find_objects(to_s)
36
+ end
37
+
38
+ def size
39
+ raise "Not Implemented"
40
+ end
41
+
42
+ def to_s
43
+ clauses[:select].to_s
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,104 @@
1
+ ##
2
+ # The format of the documentation herein is:
3
+ #
4
+ # >> method with block
5
+ # => methods on this class called by Ambition (with arguments)
6
+ #
7
+ module Ambition
8
+ module Adapters
9
+ module ActiveFedora
10
+ class Select < Base
11
+ # >> select { |u| u.name == 'chris' }
12
+ # => #call(:name)
13
+ def call(method)
14
+ method
15
+ end
16
+
17
+ # >> select { |u| u.name.downcase == 'chris' }
18
+ # => #call(:name, :downcase)
19
+ def chained_call(*methods)
20
+ # An idiom here is to call the chained method and pass it
21
+ # the first method.
22
+ #
23
+ # if respond_to? methods[1]
24
+ # send(methods[1], methods[0])
25
+ # end
26
+ #
27
+ # In the above example, this translates to calling:
28
+ #
29
+ # #downcase(:name)
30
+ #
31
+ if respond_to? methods[1]
32
+ send(methods[1], methods[0])
33
+ else
34
+ raise "I don't understand: #{methods.inspect}"
35
+ end
36
+ end
37
+
38
+ # &&
39
+ # >> select { |u| u.name == 'chris' && u.age == 22 }
40
+ # => #both( processed left side, processed right side )
41
+ def both(left, right)
42
+ "#{left} #{right}"
43
+ end
44
+
45
+ # ||
46
+ # >> select { |u| u.name == 'chris' || u.age == 22 }
47
+ # => #either( processed left side, processed right side )
48
+ def either(left, right)
49
+ raise "Not implemented."
50
+ end
51
+
52
+ # >> select { |u| u.name == 'chris' }
53
+ # => #==( call(:name), 'chris' )
54
+ def ==(left, right)
55
+ "#{left}=#{encode(right)}"
56
+ end
57
+
58
+ # !=
59
+ # >> select { |u| u.name != 'chris' }
60
+ # => #not_equal( call(:name), 'chris' )
61
+ def not_equal(left, right)
62
+ "#{left}!=#{encode(right)}"
63
+ end
64
+
65
+ # >> select { |u| u.name =~ 'chris' }
66
+ # => #=~( call(:name), 'chris' )
67
+ def =~(left, right)
68
+ "#{left}~#{encode(right)}"
69
+ end
70
+
71
+ # !~
72
+ # >> select { |u| u.name !~ 'chris' }
73
+ # => #not_regexp( call(:name), 'chris' )
74
+ def not_regexp(left, right)
75
+ raise "Not implemented."
76
+ end
77
+
78
+ ##
79
+ # Etc.
80
+ def <(left, right)
81
+ "#{left}<#{encode(right)}"
82
+ end
83
+
84
+ def >(left, right)
85
+ "#{left}>#{encode(right)}"
86
+ end
87
+
88
+ def >=(left, right)
89
+ "#{left}>=#{encode(right)}"
90
+ end
91
+
92
+ def <=(left, right)
93
+ "#{left}<=#{encode(right)}"
94
+ end
95
+
96
+ # >> select { |u| [1, 2, 3].include? u.id }
97
+ # => #include?( [1, 2, 3], call(:id) )
98
+ def include?(left, right)
99
+ raise "Not implemented."
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,19 @@
1
+ module Ambition
2
+ module Adapters
3
+ module ActiveFedora
4
+ class Slice < Base
5
+ # >> User.first(5)
6
+ # => #slice(0, 5)
7
+ #
8
+ # >> User.first
9
+ # => #slice(0, 1)
10
+ #
11
+ # >> User[10, 20]
12
+ # => #slice(10, 20)
13
+ def slice(start, length)
14
+ raise "Not implemented."
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end