hydramata-works 0.0.1.prerelease
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.hound.yml +818 -0
- data/.rspec +2 -0
- data/.travis.yml +20 -0
- data/CONTRIBUTING.md +220 -0
- data/Gemfile +36 -0
- data/Guardfile +36 -0
- data/LICENSE +15 -0
- data/README.md +36 -0
- data/Rakefile +47 -0
- data/TODO.md +74 -0
- data/VISION.md +19 -0
- data/app/forms/hydramata/works/entity_form.rb +92 -0
- data/app/forms/hydramata/works/validation_service.rb +78 -0
- data/app/models/hydramata/works/data_definition.rb +57 -0
- data/app/models/hydramata/works/entities.rb +11 -0
- data/app/models/hydramata/works/entity.rb +75 -0
- data/app/models/hydramata/works/predicate.rb +35 -0
- data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
- data/app/models/hydramata/works/predicate_set.rb +44 -0
- data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
- data/app/models/hydramata/works/predicates.rb +14 -0
- data/app/models/hydramata/works/predicates/storage.rb +33 -0
- data/app/models/hydramata/works/presentation_structure.rb +29 -0
- data/app/models/hydramata/works/property.rb +72 -0
- data/app/models/hydramata/works/property_set.rb +89 -0
- data/app/models/hydramata/works/validations.rb +6 -0
- data/app/models/hydramata/works/value.rb +34 -0
- data/app/models/hydramata/works/work_type.rb +49 -0
- data/app/models/hydramata/works/work_types.rb +14 -0
- data/app/models/hydramata/works/work_types/storage.rb +42 -0
- data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
- data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
- data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
- data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
- data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
- data/app/parsers/hydramata/works/validations_parser.rb +22 -0
- data/app/parsers/hydramata/works/value_parser.rb +26 -0
- data/app/parsers/hydramata/works/value_parsers.rb +27 -0
- data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
- data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
- data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
- data/app/presenters/hydramata/works/base_presenter.rb +146 -0
- data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
- data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
- data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
- data/app/presenters/hydramata/works/property_presenter.rb +51 -0
- data/app/presenters/hydramata/works/value_presenter.rb +60 -0
- data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
- data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
- data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
- data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
- data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
- data/app/views/hydramata/works/properties/_show.html.erb +3 -0
- data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
- data/app/views/hydramata/works/works/_edit.html.erb +8 -0
- data/app/views/hydramata/works/works/_new.html.erb +8 -0
- data/app/views/hydramata/works/works/_show.html.erb +3 -0
- data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
- data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
- data/bin/rails +12 -0
- data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
- data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
- data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
- data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
- data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
- data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
- data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
- data/db/seeds.rb +36 -0
- data/documents/administrative-set-strawperson.md +45 -0
- data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
- data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
- data/documents/diagrams/hydramata-work-architecture.dot +129 -0
- data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
- data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
- data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
- data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
- data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
- data/documents/diagrams/work-rendering.dot +53 -0
- data/documents/diagrams/work-structure.dot +32 -0
- data/documents/handling-work.md +224 -0
- data/documents/high-level-stories.md +105 -0
- data/documents/hydramata-components.md +82 -0
- data/documents/interface-between-work-and-permissions.md +131 -0
- data/documents/interface-between-work-and-workflow.md +6 -0
- data/documents/timeline.md +75 -0
- data/fs +3 -0
- data/gemfiles/rails4.1.gemfile +12 -0
- data/gemfiles/rails4.gemfile +13 -0
- data/hydramata-works.gemspec +43 -0
- data/lib/hydramata-works.rb +23 -0
- data/lib/hydramata/works/conversions.rb +21 -0
- data/lib/hydramata/works/conversions/exceptions.rb +18 -0
- data/lib/hydramata/works/conversions/predicate.rb +22 -0
- data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
- data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
- data/lib/hydramata/works/conversions/presenter.rb +13 -0
- data/lib/hydramata/works/conversions/property.rb +31 -0
- data/lib/hydramata/works/conversions/property_set.rb +23 -0
- data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
- data/lib/hydramata/works/conversions/value.rb +20 -0
- data/lib/hydramata/works/conversions/work_type.rb +26 -0
- data/lib/hydramata/works/engine.rb +31 -0
- data/lib/hydramata/works/linters.rb +99 -0
- data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
- data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
- data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
- data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
- data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
- data/lib/hydramata/works/translator.rb +67 -0
- data/lib/hydramata/works/version.rb +5 -0
- data/lib/hydramata_works.rb +2 -0
- data/lib/tasks/hydramata_work_tasks.rake +4 -0
- data/run_each_spec_in_isolation +16 -0
- data/run_each_spec_in_isolation.txt +110 -0
- data/script/analyzer.rb +124 -0
- data/script/fast_specs +22 -0
- data/spec/features/fedora_to_in_memory_spec.rb +60 -0
- data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
- data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
- data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
- data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
- data/spec/features/translation_services_spec.rb +107 -0
- data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
- data/spec/fixtures/cassettes/fedora-object.yml +299 -0
- data/spec/fixtures/translations.yml +20 -0
- data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
- data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
- data/spec/lib/hydramata-work_spec.rb +14 -0
- data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
- data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
- data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
- data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
- data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
- data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
- data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
- data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
- data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
- data/spec/lib/hydramata/works/translator_spec.rb +81 -0
- data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
- data/spec/models/hydramata/works/entity_spec.rb +50 -0
- data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
- data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
- data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
- data/spec/models/hydramata/works/predicate_spec.rb +16 -0
- data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
- data/spec/models/hydramata/works/predicates_spec.rb +18 -0
- data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
- data/spec/models/hydramata/works/property_set_spec.rb +135 -0
- data/spec/models/hydramata/works/property_spec.rb +74 -0
- data/spec/models/hydramata/works/value_spec.rb +61 -0
- data/spec/models/hydramata/works/work_type_spec.rb +45 -0
- data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
- data/spec/models/hydramata/works/work_types_spec.rb +16 -0
- data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
- data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
- data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
- data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
- data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
- data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
- data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
- data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
- data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
- data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
- data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
- data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
- data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
- data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
- data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
- data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
- data/spec/spec_active_record_helper.rb +30 -0
- data/spec/spec_fast_helper.rb +12 -0
- data/spec/spec_slow_helper.rb +56 -0
- data/spec/spec_view_helper.rb +14 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
- data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
- data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
- data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
- data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
- data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
- data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
- data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
- data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
- metadata +466 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'active_support/core_ext/array/wrap'
|
2
|
+
|
3
|
+
module Hydramata
|
4
|
+
module Works
|
5
|
+
# Responsible for handling the translation via diminishing specificity
|
6
|
+
class Translator
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def translate(key, options = {})
|
10
|
+
new(options).translate(key, options)
|
11
|
+
end
|
12
|
+
alias_method :t, :translate
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :base_scope, :translation_service, :translation_service_error
|
16
|
+
def initialize(options = {})
|
17
|
+
self.base_scope = options.fetch(:base_scope) { default_base_scope }
|
18
|
+
@translation_service = options.fetch(:translation_service) { default_translation_service }
|
19
|
+
@translation_service_error = options.fetch(:translation_service_error) { default_translation_service_error }
|
20
|
+
end
|
21
|
+
|
22
|
+
def translate(key, options = {})
|
23
|
+
translate_key_for_specific_scopes(key, options) || translate_key_for_general_case(key, options)
|
24
|
+
end
|
25
|
+
alias_method :t, :translate
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def translate_key_for_specific_scopes(key, options = {})
|
30
|
+
return nil unless scopes = options[:scopes]
|
31
|
+
returning_value = nil
|
32
|
+
Array.wrap(scopes).each do |scope|
|
33
|
+
begin
|
34
|
+
returning_value = translation_service.translate(key, scope: base_scope + Array.wrap(scope),raise: true)
|
35
|
+
break
|
36
|
+
rescue *translation_service_error
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
returning_value
|
41
|
+
end
|
42
|
+
|
43
|
+
def translate_key_for_general_case(key, options = {})
|
44
|
+
options[:scope] = base_scope
|
45
|
+
translation_service.translate(key, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def base_scope=(values)
|
49
|
+
@base_scope = Array.wrap(values)
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_base_scope
|
53
|
+
['hydramata', 'work']
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_translation_service_error
|
57
|
+
require 'i18n/exceptions'
|
58
|
+
I18n::ArgumentError
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_translation_service
|
62
|
+
require 'i18n'
|
63
|
+
I18n
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
require 'time'
|
3
|
+
require 'rake'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
File.open("run_each_spec_in_isolation.txt", 'w+') do |file|
|
7
|
+
file.puts "Using Benchmark.measure.real\n"
|
8
|
+
FileList['spec/**/*_spec.rb'].sort.select do |fn|
|
9
|
+
puts "rspec #{fn}"
|
10
|
+
measurement = Benchmark.measure { system "rspec #{fn}" }
|
11
|
+
file.puts format("%#.1f\t%s", (measurement.real), fn)
|
12
|
+
file.puts ''
|
13
|
+
end
|
14
|
+
measurement = Benchmark.measure { system('rspec') }
|
15
|
+
file.puts format("%#.1f\t%s", (measurement.real), "total-time-for-specs-run-together")
|
16
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
Using Benchmark.measure.real
|
2
|
+
6.5 spec/features/fedora_to_in_memory_spec.rb
|
3
|
+
|
4
|
+
5.1 spec/features/format_and_view_path_overrides_spec.rb
|
5
|
+
|
6
|
+
9.7 spec/features/in_memory_to_output_buffer_spec.rb
|
7
|
+
|
8
|
+
2.6 spec/features/new_user_input_to_in_memory_spec.rb
|
9
|
+
|
10
|
+
2.4 spec/features/translation_services_spec.rb
|
11
|
+
|
12
|
+
3.1 spec/forms/hydramata/works/entity_form_spec.rb
|
13
|
+
|
14
|
+
2.4 spec/forms/hydramata/works/validation_service_spec.rb
|
15
|
+
|
16
|
+
1.6 spec/lib/hydramata-work_spec.rb
|
17
|
+
|
18
|
+
2.2 spec/lib/hydramata/works/conversions/predicate_set_spec.rb
|
19
|
+
|
20
|
+
2.6 spec/lib/hydramata/works/conversions/predicate_spec.rb
|
21
|
+
|
22
|
+
2.4 spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb
|
23
|
+
|
24
|
+
2.5 spec/lib/hydramata/works/conversions/property_set_spec.rb
|
25
|
+
|
26
|
+
2.3 spec/lib/hydramata/works/conversions/property_spec.rb
|
27
|
+
|
28
|
+
1.8 spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb
|
29
|
+
|
30
|
+
2.0 spec/lib/hydramata/works/conversions/value_spec.rb
|
31
|
+
|
32
|
+
2.4 spec/lib/hydramata/works/conversions/work_type_spec.rb
|
33
|
+
|
34
|
+
1.6 spec/lib/hydramata/works/translator_spec.rb
|
35
|
+
|
36
|
+
1.6 spec/models/hydramata/works/data_definition_spec.rb
|
37
|
+
|
38
|
+
1.7 spec/models/hydramata/works/entities_spec.rb
|
39
|
+
|
40
|
+
2.4 spec/models/hydramata/works/entity_spec.rb
|
41
|
+
|
42
|
+
2.4 spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb
|
43
|
+
|
44
|
+
2.3 spec/models/hydramata/works/predicate_set_spec.rb
|
45
|
+
|
46
|
+
2.3 spec/models/hydramata/works/predicate_sets/storage_spec.rb
|
47
|
+
|
48
|
+
2.2 spec/models/hydramata/works/predicate_spec.rb
|
49
|
+
|
50
|
+
2.3 spec/models/hydramata/works/predicates/storage_spec.rb
|
51
|
+
|
52
|
+
2.2 spec/models/hydramata/works/predicates_spec.rb
|
53
|
+
|
54
|
+
1.5 spec/models/hydramata/works/presentation_structure_spec.rb
|
55
|
+
|
56
|
+
2.2 spec/models/hydramata/works/property_set_spec.rb
|
57
|
+
|
58
|
+
2.4 spec/models/hydramata/works/property_spec.rb
|
59
|
+
|
60
|
+
1.5 spec/models/hydramata/works/value_spec.rb
|
61
|
+
|
62
|
+
2.2 spec/models/hydramata/works/work_type_spec.rb
|
63
|
+
|
64
|
+
2.3 spec/models/hydramata/works/work_types/storage_spec.rb
|
65
|
+
|
66
|
+
4.7 spec/models/hydramata/works/work_types_spec.rb
|
67
|
+
|
68
|
+
2.7 spec/parsers/hydramata/works/datastream_parser_spec.rb
|
69
|
+
|
70
|
+
3.3 spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb
|
71
|
+
|
72
|
+
1.6 spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb
|
73
|
+
|
74
|
+
1.7 spec/parsers/hydramata/works/predicate_parser_spec.rb
|
75
|
+
|
76
|
+
1.6 spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb
|
77
|
+
|
78
|
+
1.5 spec/parsers/hydramata/works/value_parser_spec.rb
|
79
|
+
|
80
|
+
1.5 spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb
|
81
|
+
|
82
|
+
1.6 spec/parsers/hydramata/works/value_parsers_spec.rb
|
83
|
+
|
84
|
+
1.7 spec/presenters/hydramata/works/base_presenter_spec.rb
|
85
|
+
|
86
|
+
2.3 spec/presenters/hydramata/works/entity_presenter_spec.rb
|
87
|
+
|
88
|
+
1.6 spec/presenters/hydramata/works/fieldset_presenter_spec.rb
|
89
|
+
|
90
|
+
1.5 spec/presenters/hydramata/works/property_presenter_spec.rb
|
91
|
+
|
92
|
+
1.5 spec/renderers/hydramata/works/entity_renderer_spec.rb
|
93
|
+
|
94
|
+
2.4 spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb
|
95
|
+
|
96
|
+
2.4 spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb
|
97
|
+
|
98
|
+
2.4 spec/views/hydramata/works/properties/_edit.html.erb_spec.rb
|
99
|
+
|
100
|
+
2.4 spec/views/hydramata/works/properties/_show.html.erb_spec.rb
|
101
|
+
|
102
|
+
2.4 spec/views/hydramata/works/works/_edit.html.erb_spec.rb
|
103
|
+
|
104
|
+
2.4 spec/views/hydramata/works/works/_new.html.erb_spec.rb
|
105
|
+
|
106
|
+
2.4 spec/views/hydramata/works/works/_show.html.erb_spec.rb
|
107
|
+
|
108
|
+
1.5 spec/wranglers/hydramata/works/fedora_wrangler_spec.rb
|
109
|
+
|
110
|
+
7.5 total-time-for-specs-run-together
|
data/script/analyzer.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
require 'sexp_processor'
|
5
|
+
require 'ruby_parser'
|
6
|
+
require 'byebug'
|
7
|
+
require 'rake'
|
8
|
+
require 'set'
|
9
|
+
|
10
|
+
class Collector
|
11
|
+
attr_reader :namespace
|
12
|
+
def initialize(namespace)
|
13
|
+
@namespace = namespace
|
14
|
+
@storage = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def push(class_stack, collaborator)
|
18
|
+
klass = register(class_stack)
|
19
|
+
@storage[klass] << collaborator
|
20
|
+
end
|
21
|
+
|
22
|
+
def register(class_stack)
|
23
|
+
klass = class_stack.reverse[0..-1].collect(&:to_s).join('::')
|
24
|
+
@storage[klass] ||= Set.new
|
25
|
+
klass
|
26
|
+
end
|
27
|
+
|
28
|
+
def render
|
29
|
+
puts %(digraph "G" {)
|
30
|
+
puts %( label="#{namespace}") if namespace
|
31
|
+
@storage.each do |klass, collaborators|
|
32
|
+
if klass.strip != '' || collaborators.any? {|c| c =~ /\A#{namespace}/ }
|
33
|
+
puts render_node(klass)
|
34
|
+
collaborators.each do |collaborator|
|
35
|
+
if @storage.detect do |some_class, _|
|
36
|
+
if some_class =~ /\A#{namespace}(::\w+)*::#{collaborator}\Z/
|
37
|
+
render_node(some_class)
|
38
|
+
render_edge(klass, some_class)
|
39
|
+
true
|
40
|
+
else
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
if collaborator =~ /\A#{namespace}/
|
46
|
+
render_node(collaborator)
|
47
|
+
render_edge(klass, collaborator)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
puts %(})
|
54
|
+
end
|
55
|
+
|
56
|
+
def render_node(klass)
|
57
|
+
puts %( #{to_dot_name(klass)}[label="#{klass}"])
|
58
|
+
end
|
59
|
+
|
60
|
+
def render_edge(from, to)
|
61
|
+
puts %( #{to_dot_name(from)} -> #{to_dot_name(to)})
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_dot_name(str)
|
65
|
+
str.gsub(/[\W:]+/,'_')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class DependencyAnalyzer < MethodBasedSexpProcessor
|
70
|
+
|
71
|
+
attr_reader :collector
|
72
|
+
|
73
|
+
def initialize(collector = Collector.new)
|
74
|
+
super()
|
75
|
+
@collector = collector
|
76
|
+
end
|
77
|
+
|
78
|
+
def process_colon2(exp)
|
79
|
+
klass = classify_colon2(exp).join("::")
|
80
|
+
collector.push(class_stack, klass)
|
81
|
+
return exp
|
82
|
+
end
|
83
|
+
|
84
|
+
def process_module(exp)
|
85
|
+
super(exp)
|
86
|
+
collector.register(class_stack)
|
87
|
+
return exp
|
88
|
+
end
|
89
|
+
|
90
|
+
def process_dfn(exp)
|
91
|
+
collector.register(class_stack)
|
92
|
+
return exp
|
93
|
+
end
|
94
|
+
|
95
|
+
def process_const(exp)
|
96
|
+
collaborator = exp[1]
|
97
|
+
collector.push(class_stack, collaborator.to_s)
|
98
|
+
return s(:const, collaborator)
|
99
|
+
end
|
100
|
+
|
101
|
+
def classify_colon2(exp, returning = [])
|
102
|
+
returning.unshift(exp[2]) if exp[2]
|
103
|
+
if exp[1].is_a?(Sexp)
|
104
|
+
classify_colon2(exp[1], returning)
|
105
|
+
else
|
106
|
+
returning.unshift(exp[1])
|
107
|
+
end
|
108
|
+
return returning
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
if __FILE__ == $0
|
114
|
+
collaborator = Collector.new('Hydramata::Works')
|
115
|
+
analyzer = DependencyAnalyzer.new(collaborator)
|
116
|
+
FileList['app/**/*.rb', 'lib/**/*.rb'].each do |filename|
|
117
|
+
# filename = '/Users/jfriesen/Repositories/hydramata-work/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb'
|
118
|
+
file_content = File.read(filename)
|
119
|
+
parsed_file = RubyParser.for_current_ruby.parse(file_content)
|
120
|
+
# break
|
121
|
+
analyzer.process(parsed_file)
|
122
|
+
end
|
123
|
+
collaborator.render
|
124
|
+
end
|
data/script/fast_specs
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
# A helper function for answering: Does this spec run fast?
|
6
|
+
module Fast
|
7
|
+
module_function
|
8
|
+
def spec?(fn)
|
9
|
+
open(fn) { |f| f.gets =~ /spec_fast_helper/ }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
fast_specs = FileList['spec/**/*_spec.rb'].select do |fn|
|
14
|
+
Fast.spec?(fn)
|
15
|
+
end
|
16
|
+
|
17
|
+
if fast_specs.any?
|
18
|
+
system "rspec #{fast_specs}"
|
19
|
+
else
|
20
|
+
puts 'Unable to find any fast specs'
|
21
|
+
exit(-1)
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_slow_helper'
|
2
|
+
require 'hydramata/works/fedora_wrangler'
|
3
|
+
|
4
|
+
require 'vcr'
|
5
|
+
require 'webmock'
|
6
|
+
|
7
|
+
VCR.configure do |config|
|
8
|
+
config.cassette_library_dir = 'spec/fixtures/cassettes'
|
9
|
+
config.hook_into :webmock
|
10
|
+
end
|
11
|
+
|
12
|
+
# Because of Rubydora this is required
|
13
|
+
def logger
|
14
|
+
@logger ||= Logger.new("/dev/null")
|
15
|
+
end
|
16
|
+
|
17
|
+
module Hydramata
|
18
|
+
module Works
|
19
|
+
|
20
|
+
describe 'An in Fedora object is loaded into an in memory work' do
|
21
|
+
let(:pid) { 'und:f4752f8687n' }
|
22
|
+
let(:work_wrangler) { FedoraWrangler.new(entity: entity) }
|
23
|
+
let(:entity) { Entity.new }
|
24
|
+
|
25
|
+
it 'should parse the Fedora object and assign the predicates' do
|
26
|
+
seed_predicates!
|
27
|
+
VCR.use_cassette('fedora-object', record: :none) do
|
28
|
+
work_wrangler.call(pid, with_datastreams: true)
|
29
|
+
expect { |b| entity.properties.each(&b) }.
|
30
|
+
to yield_successive_args(
|
31
|
+
Property.new(predicate: 'depositor', value: 'username-1'),
|
32
|
+
Property.new(predicate: 'http://purl.org/dc/terms/created', value: Date.new(2014, 6, 2)),
|
33
|
+
Property.new(predicate: 'http://purl.org/dc/terms/language', value: 'English'),
|
34
|
+
Property.new(predicate: 'http://purl.org/dc/terms/publisher', value: 'University of Notre Dame'),
|
35
|
+
Property.new(predicate: 'http://purl.org/dc/terms/title', value: 'Title 1'),
|
36
|
+
Property.new(predicate: 'http://purl.org/dc/terms/dateSubmitted', value: Date.new(2014, 6, 4)),
|
37
|
+
Property.new(predicate: 'http://purl.org/dc/terms/modified', value: Date.new(2014, 6, 3)),
|
38
|
+
Property.new(predicate: 'http://purl.org/dc/terms/rights', value: 'Attribution 3.0 United States'),
|
39
|
+
Property.new(predicate: 'http://purl.org/dc/terms/creator', value: 'Creator Name1'),
|
40
|
+
Property.new(predicate: 'http://purl.org/dc/terms/description', value: 'Hello World!')
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def seed_predicates!
|
46
|
+
Predicates::Storage.delete_all
|
47
|
+
Predicates::Storage.create!(identity: 'depositor')
|
48
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/created', value_parser_name: 'DateParser')
|
49
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/language', value_parser_name: 'InterrogationParser' )
|
50
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/publisher', value_parser_name: 'InterrogationParser')
|
51
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/title', value_parser_name: 'InterrogationParser')
|
52
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/dateSubmitted', value_parser_name: 'DateParser')
|
53
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/modified', value_parser_name: 'DateParser')
|
54
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/rights', value_parser_name: 'InterrogationParser')
|
55
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/creator', value_parser_name: 'InterrogationParser')
|
56
|
+
Predicates::Storage.create!(identity: 'http://purl.org/dc/terms/description', value_parser_name: 'InterrogationParser')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_slow_helper'
|
2
|
+
|
3
|
+
# This spec verifies that the Entity -> Fieldset -> Properties render chain
|
4
|
+
# uses the same presentation context for the entire render process.
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
describe 'An entity and presentation structure' do
|
8
|
+
context 'with view_path override and format' do
|
9
|
+
it 'uses the found views instead of the defaults' do
|
10
|
+
rendered_output = renderer.render
|
11
|
+
expect(rendered_output.strip).to eq("ENTITY article\nFIELDSET required\nPROPERTY title")
|
12
|
+
end
|
13
|
+
|
14
|
+
around do |example|
|
15
|
+
begin
|
16
|
+
generate_template(
|
17
|
+
'works',
|
18
|
+
"ENTITY <%= #{presentation_context}.t(:work_type)%>",
|
19
|
+
"<% #{presentation_context}.fieldsets.each do |f|%><%= f.render(template: self) %><% end %>"
|
20
|
+
)
|
21
|
+
generate_template(
|
22
|
+
'fieldsets',
|
23
|
+
"FIELDSET <%= #{presentation_context}.t(:name)%>",
|
24
|
+
"<% #{presentation_context}.each do |f|%><%= f.render(template: self) %><% end %>"
|
25
|
+
)
|
26
|
+
generate_template('properties', "PROPERTY <%= #{presentation_context}.t(:name) %>")
|
27
|
+
example.run
|
28
|
+
ensure
|
29
|
+
cleanup_template('works')
|
30
|
+
cleanup_template('fieldsets')
|
31
|
+
cleanup_template('properties')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_template(name, *lines)
|
38
|
+
path = File.expand_path("../../../#{view_path}/hydramata/works/#{name}/_#{presentation_context}.#{format}.erb", __FILE__)
|
39
|
+
FileUtils.mkdir_p(File.dirname(path))
|
40
|
+
File.open(path, 'w+') { |f| f.puts lines.join("\n") }
|
41
|
+
end
|
42
|
+
|
43
|
+
def cleanup_template(name)
|
44
|
+
path = File.expand_path("../../../#{view_path}/hydramata/works/#{name}/_#{presentation_context}.#{format}.erb", __FILE__)
|
45
|
+
File.unlink(path) if File.exist?(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:entity) do
|
49
|
+
Entity.new do |entity|
|
50
|
+
entity.work_type = 'article'
|
51
|
+
entity.properties << { predicate: :title, value: 'Hello' }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:presentation_structure) do
|
56
|
+
PresentationStructure.new.tap do |struct|
|
57
|
+
struct.fieldsets << [:required, [:title]]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
let(:presentation_context) { :nonsense }
|
62
|
+
let(:view_path) { 'app/views/articles' }
|
63
|
+
let(:format) { :elvis }
|
64
|
+
|
65
|
+
let(:entity_presenter) do
|
66
|
+
EntityPresenter.new(entity: entity, presentation_structure: presentation_structure, presentation_context: presentation_context)
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:renderer) { EntityRenderer.new(entity: entity_presenter, format: format, view_path: view_path) }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|