hydramata-works 0.0.1.prerelease
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.
- 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,28 @@
|
|
1
|
+
require 'hydramata/works/conversions/exceptions'
|
2
|
+
require 'hydramata/works/predicate_set'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
module Conversions
|
7
|
+
private
|
8
|
+
def PredicateSet(input)
|
9
|
+
return input.to_predicate_set if input.respond_to?(:to_predicate_set)
|
10
|
+
case input
|
11
|
+
when PredicateSet then input
|
12
|
+
when Hash then PredicateSet.new(input)
|
13
|
+
when String then PredicateSet.new(identity: input)
|
14
|
+
when Array then
|
15
|
+
case input.size
|
16
|
+
when 0 then raise ConversionError.new(:PredicateSet, input)
|
17
|
+
when 1 then PredicateSet.new(identity: input[0])
|
18
|
+
when 2 then PredicateSet.new(identity: input[0], predicates: input[1])
|
19
|
+
else
|
20
|
+
PredicateSet.new(identity: input[0], predicates: input[1..-1])
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise ConversionError.new(:PredicateSet, input)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'hydramata/works/conversions/property_set'
|
2
|
+
require 'hydramata/works/conversions/predicate_set'
|
3
|
+
require 'hydramata/works/fieldset_presenter'
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
module Conversions
|
7
|
+
def PresentedFieldsets(collaborators)
|
8
|
+
# @TODO - This could be packaged up into a tidier location.
|
9
|
+
# The collaboration with an entity's PropertySet#subset is convoluted.
|
10
|
+
# I also don't know if I need.
|
11
|
+
entity = collaborators.fetch(:entity)
|
12
|
+
presentation_structure = collaborators.fetch(:presentation_structure)
|
13
|
+
presentation_structure.fieldsets.each_with_object([]) do |predicate_set, collector|
|
14
|
+
predicate_set = PredicateSet(predicate_set)
|
15
|
+
predicates = predicate_set.predicates
|
16
|
+
property_set = PropertySet(predicate_set)
|
17
|
+
property_builder = ->(property) {
|
18
|
+
require 'hydramata/works/property_presenter'
|
19
|
+
PropertyPresenter.new(property: property, fieldset: property_set, entity: entity)
|
20
|
+
}
|
21
|
+
entity.properties.subset(predicates, property_set, property_builder)
|
22
|
+
presented_fieldset = FieldsetPresenter.new(entity: entity, fieldset: property_set)
|
23
|
+
collector << presented_fieldset
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'hydramata/works/conversions/exceptions'
|
2
|
+
require 'hydramata/works/property'
|
3
|
+
require 'hydramata/works/conversions/predicate'
|
4
|
+
require 'hydramata/works/predicate'
|
5
|
+
|
6
|
+
module Hydramata
|
7
|
+
module Works
|
8
|
+
module Conversions
|
9
|
+
private
|
10
|
+
def Property(*args)
|
11
|
+
if args.size == 0
|
12
|
+
raise ConversionError.new(:Property, args)
|
13
|
+
else
|
14
|
+
input = args.first
|
15
|
+
property =
|
16
|
+
case input
|
17
|
+
when Property then input
|
18
|
+
when Predicate then Property.new(predicate: input)
|
19
|
+
when Hash then Property.new(input)
|
20
|
+
else
|
21
|
+
predicate = Predicate(input)
|
22
|
+
Property.new(predicate: predicate)
|
23
|
+
end
|
24
|
+
values = args[1..-1]
|
25
|
+
property << values
|
26
|
+
property
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'hydramata/works/conversions/exceptions'
|
2
|
+
require 'hydramata/works/conversions/predicate_set'
|
3
|
+
require 'hydramata/works/predicate_set'
|
4
|
+
require 'hydramata/works/property_set'
|
5
|
+
|
6
|
+
module Hydramata
|
7
|
+
module Works
|
8
|
+
module Conversions
|
9
|
+
private
|
10
|
+
def PropertySet(input)
|
11
|
+
return input.to_property_set if input.respond_to?(:to_property_set)
|
12
|
+
|
13
|
+
case input
|
14
|
+
when PropertySet then input
|
15
|
+
when PredicateSet then PropertySet.new(predicate_set: input)
|
16
|
+
else
|
17
|
+
predicate_set = PredicateSet(input)
|
18
|
+
PropertySet(predicate_set)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'hydramata/works/conversions/exceptions'
|
2
|
+
|
3
|
+
module Hydramata
|
4
|
+
module Works
|
5
|
+
module Conversions
|
6
|
+
private
|
7
|
+
def TranslationKeyFragment(input)
|
8
|
+
return input.to_translation_key_fragment.to_s.downcase.gsub(/\W+/, '_') if input.respond_to?(:to_translation_key_fragment)
|
9
|
+
case input
|
10
|
+
when String, Symbol then input.to_s.downcase.gsub(/\W+/, '_')
|
11
|
+
when Hash then
|
12
|
+
value = input[:to_translation_key_fragment] || input['to_translation_key_fragment']
|
13
|
+
TranslationKeyFragment(value)
|
14
|
+
else
|
15
|
+
raise ConversionError.new(:TranslationKeyFragment, input)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'hydramata/works/conversions/exceptions'
|
2
|
+
require 'hydramata/works/value'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
module Conversions
|
7
|
+
private
|
8
|
+
def Value(input)
|
9
|
+
return input.to_value if input.respond_to?(:to_value)
|
10
|
+
case input
|
11
|
+
when Value then input
|
12
|
+
when Hash then Value.new(input)
|
13
|
+
when String, Symbol then Value.new(value: input)
|
14
|
+
else
|
15
|
+
raise ConversionError.new(:Value, input)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'hydramata/works/conversions/exceptions'
|
2
|
+
require 'hydramata/works/work_type'
|
3
|
+
require 'hydramata/works/work_types'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
module Conversions
|
8
|
+
private
|
9
|
+
def WorkType(input = nil)
|
10
|
+
return input.to_work_type if input.respond_to?(:to_work_type)
|
11
|
+
case input
|
12
|
+
when WorkType then input
|
13
|
+
when String, Symbol then WorkTypes.find(input)
|
14
|
+
when Hash then WorkTypes.find(input.fetch(:identity), input)
|
15
|
+
when NilClass then WorkType.new(identity: 'unknown')
|
16
|
+
else
|
17
|
+
if input.respond_to?(:empty?) && input.empty?
|
18
|
+
WorkType.new(identity: 'unknown')
|
19
|
+
else
|
20
|
+
raise ConversionError.new(:WorkType, input)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
# Hydramata::Works is a [Rails::Engine](http://guides.rubyonrails.org/engines.html)
|
4
|
+
#
|
5
|
+
# These are the pieces necessary for coordinating the Hydramata::Works with
|
6
|
+
# your instance of a Rails application.
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
engine_name 'hydramata_works'
|
9
|
+
|
10
|
+
if config.respond_to?(:eager_load_namespaces)
|
11
|
+
# SimpleForm did this, so I'm thinking that I will do it.
|
12
|
+
config.eager_load_namespaces << Hydramata::Works
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer 'hydramata_works.initializers' do |app|
|
16
|
+
app.config.paths.add 'app/renderers', eager_load: true
|
17
|
+
app.config.paths.add 'app/presenters', eager_load: true
|
18
|
+
app.config.paths.add 'app/forms', eager_load: true
|
19
|
+
app.config.paths.add 'app/parsers', eager_load: true
|
20
|
+
app.config.paths.add 'app/wranglers', eager_load: true
|
21
|
+
app.config.autoload_paths += %W(
|
22
|
+
#{config.root}/app/renderers
|
23
|
+
#{config.root}/app/forms
|
24
|
+
#{config.root}/app/presenters
|
25
|
+
#{config.root}/app/parsers
|
26
|
+
#{config.root}/app/wranglers
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
shared_examples 'a presented entity' do |default_presented_entity_class|
|
2
|
+
let(:presented_entity_class) { (default_presented_entity_class || described_class) }
|
3
|
+
it 'responds to #fieldsets' do
|
4
|
+
expect { presented_entity_class.instance_method(:fieldsets) }.
|
5
|
+
to_not raise_error
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples 'a datastream parser' do |default_parser|
|
10
|
+
let(:parser) { default_parser || described_class }
|
11
|
+
it 'responds to .call' do
|
12
|
+
expect(parser).to respond_to(:call)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'responds to .match?' do
|
16
|
+
expect(parser).to respond_to(:match?)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'its .call method' do
|
20
|
+
it 'has a required first parameter' do
|
21
|
+
expect(parser.method(:call).parameters.first[0]).to eq(:req)
|
22
|
+
end
|
23
|
+
it 'takes a block' do
|
24
|
+
expect(parser.method(:call).parameters.last[1]).to eq(:block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
shared_examples 'a predicate parser' do |default_parser|
|
30
|
+
let(:parser) { default_parser || described_class }
|
31
|
+
it 'responds to #call' do
|
32
|
+
expect(parser).to respond_to(:call)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'its #call method' do
|
36
|
+
it 'has a required first parameter' do
|
37
|
+
expect(parser.method(:call).parameters.first[0]).to eq(:req)
|
38
|
+
end
|
39
|
+
it 'takes a block' do
|
40
|
+
expect(parser.method(:call).parameters.last[1]).to eq(:block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
shared_examples 'a value parser' do |default_parser|
|
46
|
+
let(:parser) { default_parser || described_class }
|
47
|
+
it 'responds to #call' do
|
48
|
+
expect(parser).to respond_to(:call)
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'its #call method' do
|
52
|
+
it 'has a required first parameter' do
|
53
|
+
expect(parser.method(:call).parameters.first[0]).to eq(:req)
|
54
|
+
end
|
55
|
+
it 'takes a block' do
|
56
|
+
expect(parser.method(:call).parameters.last[1]).to eq(:block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
shared_examples_for 'ActiveModel' do
|
62
|
+
# From the ActiveModel::Lint::Test model
|
63
|
+
it 'implements #to_key' do
|
64
|
+
expect(subject).to respond_to(:to_key)
|
65
|
+
def subject.persisted?() false end
|
66
|
+
expect(subject.to_key).to be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'implements #to_param' do
|
70
|
+
expect(subject).to respond_to(:to_param)
|
71
|
+
def subject.to_key() [1] end
|
72
|
+
def subject.persisted?() false end
|
73
|
+
expect(subject.to_param).to be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'implements #to_partial_path' do
|
77
|
+
expect(subject).to respond_to(:to_partial_path)
|
78
|
+
expect(subject.to_partial_path).to be_a_kind_of(String)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'implements #persisted?' do
|
82
|
+
expect(subject).to respond_to(:persisted?)
|
83
|
+
expect([true, false]).to include(subject.persisted?)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'implements .model_naming' do
|
87
|
+
expect(subject.class).to respond_to(:model_name)
|
88
|
+
model_name = subject.class.model_name
|
89
|
+
expect(model_name).to respond_to(:to_str)
|
90
|
+
expect(model_name.human).to respond_to(:to_str)
|
91
|
+
expect(model_name.singular).to respond_to(:to_str)
|
92
|
+
expect(model_name.plural).to respond_to(:to_str)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'implements #errors' do
|
96
|
+
expect(subject).to respond_to(:errors)
|
97
|
+
expect(subject.errors[:hello]).to be_an_instance_of(Array)
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require 'hydramata/works/linters/interface_matcher_builder'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :implement_data_definition_interface do
|
5
|
+
Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
|
6
|
+
self,
|
7
|
+
'DataDefinition',
|
8
|
+
[
|
9
|
+
:identity,
|
10
|
+
:identity=,
|
11
|
+
:name_for_application_usage,
|
12
|
+
'<=>',
|
13
|
+
:to_sym,
|
14
|
+
:name_for_application_usage=
|
15
|
+
]
|
16
|
+
)
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require 'hydramata/works/linters/interface_matcher_builder'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :implement_entity_interface do
|
5
|
+
Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
|
6
|
+
self,
|
7
|
+
'Entity',
|
8
|
+
properties: [:<<, :each, :fetch, :[]],
|
9
|
+
has_property?: [],
|
10
|
+
name_for_application_usage: [],
|
11
|
+
work_type: [],
|
12
|
+
identity: [],
|
13
|
+
to_translation_key_fragment: [],
|
14
|
+
itemtype_schema_dot_org: []
|
15
|
+
)
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require 'hydramata/works/linters/interface_matcher_builder'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :implement_predicate_interface do
|
5
|
+
Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
|
6
|
+
self,
|
7
|
+
'Predicate',
|
8
|
+
identity: [],
|
9
|
+
name_for_application_usage: [],
|
10
|
+
datastream_name: [],
|
11
|
+
value_coercer_name: [],
|
12
|
+
value_parser_name: [],
|
13
|
+
validations: [],
|
14
|
+
indexing_strategy: [],
|
15
|
+
itemprop_schema_dot_org: []
|
16
|
+
)
|
17
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require 'hydramata/works/linters/interface_matcher_builder'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :implement_predicate_set_interface do
|
5
|
+
Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
|
6
|
+
self, 'PredicateSet', [:work_type, :identity, :presentation_sequence, :name_for_application_usage, :predicates]
|
7
|
+
)
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require 'hydramata/works/linters/interface_matcher_builder'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :implement_property_set_interface do
|
5
|
+
Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
|
6
|
+
self, 'PropertySet', [:<<, :[], :predicates, :fetch, :==, :each, :subset]
|
7
|
+
)
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec/matchers'
|
2
|
+
require 'hydramata/works/linters/interface_matcher_builder'
|
3
|
+
|
4
|
+
RSpec::Matchers.define :implement_work_type_interface do
|
5
|
+
Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
|
6
|
+
self,
|
7
|
+
'WorkType',
|
8
|
+
identity: [],
|
9
|
+
name_for_application_usage: [],
|
10
|
+
predicate_sets: [:each],
|
11
|
+
itemtype_schema_dot_org: []
|
12
|
+
)
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
module Linters
|
4
|
+
module InterfaceMatcherBuilder
|
5
|
+
module_function
|
6
|
+
def call(context, input_klass_name, input_method_names)
|
7
|
+
context.instance_exec(input_klass_name, input_method_names) do |klass_name, method_names|
|
8
|
+
match do |subject|
|
9
|
+
returning_value = method_names.all? do |(method_name, second_level_methods)|
|
10
|
+
subject.respond_to?(method_name) &&
|
11
|
+
Array(second_level_methods).all? do |second_level_method|
|
12
|
+
subject.public_send(method_name).respond_to?(second_level_method)
|
13
|
+
end
|
14
|
+
end && method_expectations.all? do |method_name, value|
|
15
|
+
subject.public_send(method_name) == value
|
16
|
+
end
|
17
|
+
returning_value
|
18
|
+
end
|
19
|
+
|
20
|
+
chain :with do |method_name, value|
|
21
|
+
method_expectations[method_name] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
description { "implemenent the #{input_klass_name} interface" }
|
25
|
+
end
|
26
|
+
|
27
|
+
context.module_exec do
|
28
|
+
def method_expectations
|
29
|
+
@method_expectations ||= {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|