active_fedora-datastreams 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1bd06d5a97b4fd602e01da55dabd0eb63223606b
4
+ data.tar.gz: 5e7b41bf053c7fdd2021af984ce0a31207bdb77c
5
+ SHA512:
6
+ metadata.gz: 51cb0a96ba7c135ce6454cf0b8a65b91849e8ecf0b040613a40a69628ab6c44b0cd9f4d2b14229fcb71667b4fbcc363fc7e21177cd7449073175e1f3db971062
7
+ data.tar.gz: 98d586bf304ed09a8c546157a44cfffb1d2db256349a97fdcc042c477f8537b95d0c5f691c6f7588a22604e5c20fe24f1dfb4dcd421220d771d74cd46da45644
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /fcrepo4-test-data/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,140 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+ DisplayCopNames: true
4
+ Include:
5
+ - '**/Rakefile'
6
+ Exclude:
7
+ - 'script/**/*'
8
+ - 'vendor/**/*'
9
+
10
+ Lint/HandleExceptions:
11
+ Exclude:
12
+ - 'spec/unit/**/*'
13
+ - 'spec/integration/**/*'
14
+
15
+ Lint/AssignmentInCondition:
16
+ Enabled: false
17
+
18
+ Metrics/LineLength:
19
+ Enabled: false
20
+
21
+ Metrics/AbcSize:
22
+ Enabled: false
23
+
24
+ Metrics/CyclomaticComplexity:
25
+ Exclude:
26
+ - 'lib/active_fedora/datastreams/nokogiri_datastreams.rb'
27
+
28
+ Metrics/PerceivedComplexity:
29
+ Exclude:
30
+ - 'lib/active_fedora/datastreams/nokogiri_datastreams.rb'
31
+
32
+ Metrics/ClassLength:
33
+ Exclude:
34
+ - 'lib/active_fedora/rdf/rdf_datastream.rb'
35
+ - 'lib/active_fedora/qualified_dublin_core_datastream.rb'
36
+ - 'spec/samples/hydra-mods_article_datastream.rb'
37
+
38
+ Metrics/MethodLength:
39
+ Enabled: false
40
+
41
+ Style/PredicateName:
42
+ Exclude:
43
+ - 'lib/active_fedora/om_datastream.rb'
44
+
45
+ Style/BlockDelimiters:
46
+ Exclude:
47
+ - 'spec/**/*'
48
+
49
+ Style/BlockEndNewline:
50
+ Exclude:
51
+ - 'spec/**/*'
52
+
53
+ Style/MultilineBlockLayout:
54
+ Exclude:
55
+ - 'spec/**/*'
56
+
57
+ Style/Semicolon:
58
+ Exclude:
59
+ - 'spec/**/*'
60
+
61
+ Style/Lambda:
62
+ Exclude:
63
+ - 'spec/**/*'
64
+
65
+ Style/FileName:
66
+ Exclude:
67
+ - 'spec/samples/hydra-mods_article_datastream.rb'
68
+
69
+ Style/IndentationConsistency:
70
+ EnforcedStyle: rails
71
+
72
+ Style/CollectionMethods:
73
+ PreferredMethods:
74
+ collect: 'map'
75
+ collect!: 'map!'
76
+ inject: 'reduce'
77
+ detect: 'find'
78
+ find_all: 'select'
79
+
80
+ Style/WordArray:
81
+ Enabled: false
82
+
83
+ Style/RegexpLiteral:
84
+ Enabled: false
85
+
86
+ Style/StringLiterals:
87
+ Enabled: false
88
+
89
+ Style/ClassAndModuleChildren:
90
+ Enabled: false
91
+
92
+ Style/Documentation:
93
+ Enabled: false
94
+
95
+ Style/GlobalVars:
96
+ Exclude:
97
+ - 'spec/**/*'
98
+
99
+ Style/SingleLineBlockParams:
100
+ Enabled: false
101
+
102
+ Style/SignalException:
103
+ Enabled: false
104
+
105
+ Rails:
106
+ Enabled: true
107
+
108
+ Rails/Date:
109
+ Enabled: false
110
+
111
+ Rails/TimeZone:
112
+ Enabled: false
113
+
114
+ RSpec/AnyInstance:
115
+ Enabled: false
116
+
117
+ RSpec/ExampleWording:
118
+ CustomTransform:
119
+ be: is
120
+ have: has
121
+ not: does not
122
+ NOT: does NOT
123
+ IgnoredWords:
124
+ - only
125
+
126
+ RSpec/FilePath:
127
+ Enabled: false
128
+
129
+ RSpec/InstanceVariable:
130
+ Enabled: false
131
+
132
+ RSpec/DescribeClass:
133
+ Exclude:
134
+ - 'spec/integration/**/*'
135
+
136
+ RSpec/NotToNot:
137
+ Enabled: false
138
+
139
+ RSpec/ExampleLength:
140
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jcoyne@justincoyne.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_fedora-datastreams.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # ActiveFedora::Datastreams
2
+
3
+ Datastreams support for ActiveFedora 11. This functionality previously was a part of ActiveFedora, but has been moved here as it is not required functionality.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'active_fedora-datastreams'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install active_fedora-datastreams
20
+
21
+ ## Usage
22
+
23
+ To create a XML datastream extend `ActiveFedora::OmDatastream`. To create an RDF::Datastream, extend `ActiveFedora::NtriplesRDFDatastream`.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_fedora-datastreams. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ require 'solr_wrapper'
5
+ require 'fcrepo_wrapper'
6
+ require 'active_fedora/rake_support'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: [:ci]
11
+
12
+ desc "CI build"
13
+ task :ci do
14
+ ENV['environment'] = "test"
15
+ Rake::Task['rubocop'].invoke unless ENV['NO_RUBOCOP']
16
+
17
+ with_test_server do
18
+ Rake::Task['spec'].invoke
19
+ end
20
+ end
21
+
22
+ require 'rubocop/rake_task'
23
+ desc 'Run style checker'
24
+ RuboCop::RakeTask.new(:rubocop) do |task|
25
+ task.requires << 'rubocop-rspec'
26
+ task.fail_on_error = true
27
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_fedora/datastreams/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_fedora-datastreams"
8
+ spec.version = ActiveFedora::Datastreams::VERSION
9
+ spec.authors = ["Justin Coyne"]
10
+ spec.email = ["jcoyne@justincoyne.com"]
11
+
12
+ spec.summary = %q{Datastreams for ActiveFedora}
13
+ spec.description = %q{XML and RDF datastreams for ActiveFedora}
14
+ spec.homepage = "https://github.com/projecthydra-labs/active_fedora-datastreams"
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "active-fedora", ">= 11.0.0.pre", "< 12"
21
+ spec.add_dependency "om", "~> 3.1"
22
+ spec.add_dependency "nom-xml", ">= 0.5.1"
23
+ spec.add_dependency "rdf-rdfxml", '~> 2.0'
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "solr_wrapper", "~> 0.4"
28
+ spec.add_development_dependency 'fcrepo_wrapper', '~> 0.2'
29
+ spec.add_development_dependency "rubocop", '~> 0.42'
30
+ spec.add_development_dependency "rubocop-rspec", '~> 1.4'
31
+ spec.add_development_dependency "equivalent-xml"
32
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_fedora/datastreams"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/fedora.yml ADDED
@@ -0,0 +1,14 @@
1
+ development:
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || 8984 %>/rest
5
+ base_path: /dev
6
+ test:
7
+ user: fedoraAdmin
8
+ password: fedoraAdmin
9
+ url: http://localhost:<%= ENV['FCREPO_TEST_PORT'] || 8986 %>/rest
10
+ base_path: /test
11
+ production:
12
+ user: fedoraAdmin
13
+ password: fedoraAdmin
14
+ url: http://127.0.0.1:8983/fedora/rest
data/config/solr.yml ADDED
@@ -0,0 +1,15 @@
1
+ development:
2
+ default:
3
+ url: http://127.0.0.1:<%= ENV['SOLR_TEST_PORT'] || 8983 %>/solr/hydra-development
4
+ full_text:
5
+ url: http://localhost:8983/solr/development
6
+ test:
7
+ default:
8
+ url: http://localhost:<%= ENV['SOLR_TEST_PORT'] || 8985 %>/solr/hydra-test
9
+ full_text:
10
+ url: http://localhost:<%= ENV['SOLR_TEST_PORT'] || 8985 %>/solr/test
11
+ production:
12
+ default:
13
+ url: http://localhost:8080/solr/production
14
+ full_text:
15
+ url: http://localhost:8080/solr/production
@@ -0,0 +1,21 @@
1
+ require "active_fedora/datastreams/version"
2
+ require 'active_fedora'
3
+
4
+ module ActiveFedora
5
+ autoload :NomDatastream, 'active_fedora/nom_datastream'
6
+ autoload :OmDatastream, 'active_fedora/om_datastream'
7
+ autoload :QualifiedDublinCoreDatastream, 'active_fedora/qualified_dublin_core_datastream'
8
+
9
+ module Datastreams
10
+ extend ActiveSupport::Autoload
11
+ autoload :NokogiriDatastreams, 'active_fedora/datastreams/nokogiri_datastreams'
12
+ end
13
+
14
+ module RDF
15
+ autoload :DatastreamIndexing, 'active_fedora/rdf/datastream_indexing'
16
+ end
17
+
18
+ autoload :NtriplesRDFDatastream, 'active_fedora/rdf/ntriples_rdf_datastream'
19
+ autoload :RDFDatastream, 'active_fedora/rdf/rdf_datastream'
20
+ autoload :RDFXMLDatastream, 'active_fedora/rdf/rdfxml_datastream'
21
+ end
@@ -0,0 +1,119 @@
1
+ module ActiveFedora
2
+ module Datastreams
3
+ module NokogiriDatastreams
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def xml_template
8
+ Nokogiri::XML::Document.parse("<xml/>")
9
+ end
10
+
11
+ def decorate_ng_xml(xml)
12
+ xml
13
+ end
14
+ end
15
+
16
+ def ng_xml
17
+ @ng_xml ||= begin
18
+ xml = if new_record?
19
+ ## Load up the template
20
+ self.class.xml_template
21
+ else
22
+ Nokogiri::XML::Document.parse(remote_content)
23
+ end
24
+ self.class.decorate_ng_xml xml
25
+ end
26
+ end
27
+
28
+ def ng_xml=(new_xml)
29
+ # before we set ng_xml, we load the datastream so we know if the new value differs.
30
+ # TODO reinstate this
31
+ # local_or_remote_content(true)
32
+
33
+ case new_xml
34
+ when Nokogiri::XML::Document
35
+ self.content = new_xml.to_xml
36
+ when Nokogiri::XML::Node
37
+ ## Cast a fragment to a document
38
+ self.content = new_xml.to_s
39
+ when String
40
+ self.content = new_xml
41
+ else
42
+ raise TypeError, "You passed a #{new_xml.class} into the ng_xml of the #{dsid} datastream. OmDatastream.ng_xml= only accepts Nokogiri::XML::Document, Nokogiri::XML::Element, Nokogiri::XML::Node, or raw XML (String) as inputs."
43
+ end
44
+ end
45
+
46
+ def refresh_attributes
47
+ changed_attributes.clear
48
+ @ng_xml = nil
49
+ end
50
+
51
+ # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods
52
+ def ng_xml_will_change!
53
+ changed_attributes['ng_xml'] = nil
54
+ end
55
+
56
+ def ng_xml_doesnt_change!
57
+ changed_attributes.delete('ng_xml')
58
+ end
59
+
60
+ # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods
61
+ def ng_xml_changed?
62
+ changed_attributes.key? 'ng_xml'
63
+ end
64
+
65
+ def remote_content
66
+ @ds_content ||= Nokogiri::XML(super).to_xml(&:no_declaration).strip
67
+ end
68
+
69
+ def content=(new_content)
70
+ if remote_content != new_content.to_s
71
+ ng_xml_will_change!
72
+ @ng_xml = Nokogiri::XML::Document.parse(new_content)
73
+ super(@ng_xml.to_s.strip)
74
+ end
75
+ self.class.decorate_ng_xml @ng_xml
76
+ end
77
+
78
+ def content_changed?
79
+ return true if autocreate? && new_record?
80
+ return false unless xml_loaded
81
+ ng_xml_changed?
82
+ end
83
+
84
+ def to_xml(xml = nil)
85
+ xml = ng_xml if xml.nil?
86
+ ng_xml = self.ng_xml
87
+ if ng_xml.respond_to?(:root) && ng_xml.root.nil? && self.class.respond_to?(:root_property_ref) && !self.class.root_property_ref.nil?
88
+ ng_xml = self.class.generate(self.class.root_property_ref, "")
89
+ xml = ng_xml if xml.root.nil?
90
+ end
91
+
92
+ unless xml == ng_xml || ng_xml.root.nil?
93
+ if xml.is_a?(Nokogiri::XML::Document)
94
+ xml.root.add_child(ng_xml.root)
95
+ elsif xml.is_a?(Nokogiri::XML::Node)
96
+ xml.add_child(ng_xml.root)
97
+ else
98
+ raise "You can only pass instances of Nokogiri::XML::Node into this method. You passed in #{xml}"
99
+ end
100
+ end
101
+
102
+ xml.to_xml.strip
103
+ end
104
+
105
+ def content
106
+ @content = to_xml if ng_xml_changed? || autocreate?
107
+ super
108
+ end
109
+
110
+ def autocreate?
111
+ changed_attributes.key? :profile
112
+ end
113
+
114
+ def xml_loaded
115
+ instance_variable_defined? :@ng_xml
116
+ end
117
+ end
118
+ end
119
+ end