hydramata-works 0.0.1.prerelease

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.hound.yml +818 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +20 -0
  6. data/CONTRIBUTING.md +220 -0
  7. data/Gemfile +36 -0
  8. data/Guardfile +36 -0
  9. data/LICENSE +15 -0
  10. data/README.md +36 -0
  11. data/Rakefile +47 -0
  12. data/TODO.md +74 -0
  13. data/VISION.md +19 -0
  14. data/app/forms/hydramata/works/entity_form.rb +92 -0
  15. data/app/forms/hydramata/works/validation_service.rb +78 -0
  16. data/app/models/hydramata/works/data_definition.rb +57 -0
  17. data/app/models/hydramata/works/entities.rb +11 -0
  18. data/app/models/hydramata/works/entity.rb +75 -0
  19. data/app/models/hydramata/works/predicate.rb +35 -0
  20. data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
  21. data/app/models/hydramata/works/predicate_set.rb +44 -0
  22. data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
  23. data/app/models/hydramata/works/predicates.rb +14 -0
  24. data/app/models/hydramata/works/predicates/storage.rb +33 -0
  25. data/app/models/hydramata/works/presentation_structure.rb +29 -0
  26. data/app/models/hydramata/works/property.rb +72 -0
  27. data/app/models/hydramata/works/property_set.rb +89 -0
  28. data/app/models/hydramata/works/validations.rb +6 -0
  29. data/app/models/hydramata/works/value.rb +34 -0
  30. data/app/models/hydramata/works/work_type.rb +49 -0
  31. data/app/models/hydramata/works/work_types.rb +14 -0
  32. data/app/models/hydramata/works/work_types/storage.rb +42 -0
  33. data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
  34. data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
  35. data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
  36. data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
  37. data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
  38. data/app/parsers/hydramata/works/validations_parser.rb +22 -0
  39. data/app/parsers/hydramata/works/value_parser.rb +26 -0
  40. data/app/parsers/hydramata/works/value_parsers.rb +27 -0
  41. data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
  42. data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
  43. data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
  44. data/app/presenters/hydramata/works/base_presenter.rb +146 -0
  45. data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
  46. data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
  47. data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
  48. data/app/presenters/hydramata/works/property_presenter.rb +51 -0
  49. data/app/presenters/hydramata/works/value_presenter.rb +60 -0
  50. data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
  51. data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
  52. data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
  53. data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
  54. data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
  55. data/app/views/hydramata/works/properties/_show.html.erb +3 -0
  56. data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
  57. data/app/views/hydramata/works/works/_edit.html.erb +8 -0
  58. data/app/views/hydramata/works/works/_new.html.erb +8 -0
  59. data/app/views/hydramata/works/works/_show.html.erb +3 -0
  60. data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
  61. data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
  62. data/bin/rails +12 -0
  63. data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
  64. data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
  65. data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
  66. data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
  67. data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
  68. data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
  69. data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
  70. data/db/seeds.rb +36 -0
  71. data/documents/administrative-set-strawperson.md +45 -0
  72. data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
  73. data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
  74. data/documents/diagrams/hydramata-work-architecture.dot +129 -0
  75. data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
  76. data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
  77. data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
  78. data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
  79. data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
  80. data/documents/diagrams/work-rendering.dot +53 -0
  81. data/documents/diagrams/work-structure.dot +32 -0
  82. data/documents/handling-work.md +224 -0
  83. data/documents/high-level-stories.md +105 -0
  84. data/documents/hydramata-components.md +82 -0
  85. data/documents/interface-between-work-and-permissions.md +131 -0
  86. data/documents/interface-between-work-and-workflow.md +6 -0
  87. data/documents/timeline.md +75 -0
  88. data/fs +3 -0
  89. data/gemfiles/rails4.1.gemfile +12 -0
  90. data/gemfiles/rails4.gemfile +13 -0
  91. data/hydramata-works.gemspec +43 -0
  92. data/lib/hydramata-works.rb +23 -0
  93. data/lib/hydramata/works/conversions.rb +21 -0
  94. data/lib/hydramata/works/conversions/exceptions.rb +18 -0
  95. data/lib/hydramata/works/conversions/predicate.rb +22 -0
  96. data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
  97. data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
  98. data/lib/hydramata/works/conversions/presenter.rb +13 -0
  99. data/lib/hydramata/works/conversions/property.rb +31 -0
  100. data/lib/hydramata/works/conversions/property_set.rb +23 -0
  101. data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
  102. data/lib/hydramata/works/conversions/value.rb +20 -0
  103. data/lib/hydramata/works/conversions/work_type.rb +26 -0
  104. data/lib/hydramata/works/engine.rb +31 -0
  105. data/lib/hydramata/works/linters.rb +99 -0
  106. data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
  107. data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
  108. data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
  109. data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
  110. data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
  111. data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
  112. data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
  113. data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
  114. data/lib/hydramata/works/translator.rb +67 -0
  115. data/lib/hydramata/works/version.rb +5 -0
  116. data/lib/hydramata_works.rb +2 -0
  117. data/lib/tasks/hydramata_work_tasks.rake +4 -0
  118. data/run_each_spec_in_isolation +16 -0
  119. data/run_each_spec_in_isolation.txt +110 -0
  120. data/script/analyzer.rb +124 -0
  121. data/script/fast_specs +22 -0
  122. data/spec/features/fedora_to_in_memory_spec.rb +60 -0
  123. data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
  124. data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
  125. data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
  126. data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
  127. data/spec/features/translation_services_spec.rb +107 -0
  128. data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
  129. data/spec/fixtures/cassettes/fedora-object.yml +299 -0
  130. data/spec/fixtures/translations.yml +20 -0
  131. data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
  132. data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
  133. data/spec/lib/hydramata-work_spec.rb +14 -0
  134. data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
  135. data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
  136. data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
  137. data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
  138. data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
  139. data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
  140. data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
  141. data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
  142. data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
  143. data/spec/lib/hydramata/works/translator_spec.rb +81 -0
  144. data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
  145. data/spec/models/hydramata/works/entity_spec.rb +50 -0
  146. data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
  147. data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
  148. data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
  149. data/spec/models/hydramata/works/predicate_spec.rb +16 -0
  150. data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
  151. data/spec/models/hydramata/works/predicates_spec.rb +18 -0
  152. data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
  153. data/spec/models/hydramata/works/property_set_spec.rb +135 -0
  154. data/spec/models/hydramata/works/property_spec.rb +74 -0
  155. data/spec/models/hydramata/works/value_spec.rb +61 -0
  156. data/spec/models/hydramata/works/work_type_spec.rb +45 -0
  157. data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
  158. data/spec/models/hydramata/works/work_types_spec.rb +16 -0
  159. data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
  160. data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
  161. data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
  162. data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
  163. data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
  164. data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
  165. data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
  166. data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
  167. data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
  168. data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
  169. data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
  170. data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
  171. data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
  172. data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
  173. data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
  174. data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
  175. data/spec/spec_active_record_helper.rb +30 -0
  176. data/spec/spec_fast_helper.rb +12 -0
  177. data/spec/spec_slow_helper.rb +56 -0
  178. data/spec/spec_view_helper.rb +14 -0
  179. data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
  180. data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
  181. data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
  182. data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
  183. data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
  184. data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
  185. data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
  186. data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
  187. data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
  188. 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,13 @@
1
+ require 'hydramata/works/conversions/exceptions'
2
+
3
+ module Hydramata
4
+ module Works
5
+ module Conversions
6
+ private
7
+ def Presenter(input)
8
+ return input.to_presenter if input.respond_to?(:to_presenter)
9
+ input
10
+ end
11
+ end
12
+ end
13
+ 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,8 @@
1
+ require 'rspec/matchers'
2
+ require 'hydramata/works/linters/interface_matcher_builder'
3
+
4
+ RSpec::Matchers.define :implement_value_interface do
5
+ Hydramata::Works::Linters::InterfaceMatcherBuilder.call(
6
+ self, 'Value', [:raw_object]
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