locabulary 0.5.0 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c1e85110e906091033981d644e5a147c001eab2
4
- data.tar.gz: 1cf448e30e0d19469afafee922ac3f3a5d01f025
3
+ metadata.gz: d6860e6b46a871aa5f6fa44d61e4a71549fe997d
4
+ data.tar.gz: 8e45a3991ac5fac5b35944094db338ac8d484c0a
5
5
  SHA512:
6
- metadata.gz: 105285fc4f39faa1f49d78a5245a67fbb975c31656f62f430e831d256a0f6adb1810936695a068c015ce16674e5ffa503d8f3745624a97265515e94453201772
7
- data.tar.gz: d0337a83c1248bb28b87494350e59770ddf9834480b4284a39bbb57289d9af24c3389fb831407a258b7d3709b72ce7e9e21ee6d633f0a2a2309c91ec49b306d3
6
+ metadata.gz: d0934da270aa054be0eae9d1dea2db1739d1fdabc79142f6845efe944b0b332816330b0ab74712c4c165f1526747d1f82d563e4e43d0734d0191ca6d0fea4cd8
7
+ data.tar.gz: 4e137b994cc4d406e2a5787ac565e20eeca0b2aa7325707c2bf7d536a5e4543fe353fbdc05f19fcd04eb20dd2575b108dbc8e52bfcb7ce1838448ac7777fc65e
data/README.md CHANGED
@@ -14,3 +14,5 @@ robust options.
14
14
  ## Testing
15
15
 
16
16
  The full test suite is run via `bundle exec rake`.
17
+
18
+ If you are interested in running each file in isolation - a good thing for unit tests - use `./bin/rspec_isolated`.
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ #
3
+ # Run each spec in isolation
4
+ # http://www.andywaite.com/2015/10/11/accidental-rails-coupling/
5
+ find . -name "*_spec.rb" -print | xargs -n 1 bundle exec rspec
@@ -1,6 +1,6 @@
1
1
  require 'set'
2
2
  require 'date'
3
- require 'locabulary/items'
3
+ require 'locabulary/item'
4
4
  require 'locabulary/exceptions'
5
5
 
6
6
  module Locabulary
@@ -1,6 +1,5 @@
1
1
  require 'date'
2
- require 'json'
3
- require 'locabulary/items'
2
+ require 'locabulary/item'
4
3
  require 'locabulary/utility'
5
4
 
6
5
  module Locabulary
@@ -13,9 +13,10 @@ module Locabulary
13
13
  # @since 0.5.0
14
14
  #
15
15
  # @param options [Hash]
16
- # @option predicate_name [String]
17
- # @option faceted_items [Array<#hits, #value>]
18
- # @option faceted_item_hierarchy_delimiter [String]
16
+ # @option options [String] :predicate_name
17
+ # @option options [Array<#hits, #value>] :faceted_items
18
+ # @option options [String] :faceted_item_hierarchy_delimiter
19
+ # For any given item in faceted_items how is the hierarchy encoded in the :value?
19
20
  #
20
21
  # @return [Array<FacetWrapperForItem>]
21
22
  def self.call(options = {})
@@ -26,7 +27,7 @@ module Locabulary
26
27
  @predicate_name = options.fetch(:predicate_name)
27
28
  @faceted_items = options.fetch(:faceted_items)
28
29
  @faceted_item_hierarchy_delimiter = options.fetch(:faceted_item_hierarchy_delimiter)
29
- @builder = Item.builder_for(predicate_name: predicate_name)
30
+ @locabulary_item_class = Item.class_to_instantiate(predicate_name: predicate_name)
30
31
  end
31
32
 
32
33
  def call
@@ -45,7 +46,7 @@ module Locabulary
45
46
 
46
47
  private
47
48
 
48
- attr_reader :builder, :predicate_name, :faceted_items, :faceted_item_hierarchy_delimiter
49
+ attr_reader :locabulary_item_class, :predicate_name, :faceted_items, :faceted_item_hierarchy_delimiter
49
50
 
50
51
  def associate_parents_and_childrens_for(hierarchy_graph_keys, items)
51
52
  items.each do |item|
@@ -58,7 +59,7 @@ module Locabulary
58
59
  end
59
60
 
60
61
  def build_item(faceted_node)
61
- term_label = faceted_node.value
62
+ term_label = convert_faceted_node_value_to_term_label(faceted_node.value)
62
63
  locabulary_item = find_locabulary_item(predicate_name: predicate_name, term_label: term_label)
63
64
  if locabulary_item
64
65
  FacetWrapperForItem.build_for_faceted_node_and_locabulary_item(faceted_node: faceted_node, locabulary_item: locabulary_item)
@@ -75,6 +76,14 @@ module Locabulary
75
76
  # that we want to consider a developer notification but not abort the whole process.
76
77
  nil
77
78
  end
79
+
80
+ # Responsible for converting the hierarchy delimiter of the facet item to the hierarchy delimiter of the Locabulary::Item.
81
+ def convert_faceted_node_value_to_term_label(value)
82
+ value.gsub(
83
+ /(?<!#{faceted_item_hierarchy_delimiter})#{faceted_item_hierarchy_delimiter}(?!#{faceted_item_hierarchy_delimiter})/,
84
+ locabulary_item_class.hierarchy_delimiter
85
+ )
86
+ end
78
87
  end
79
88
  end
80
89
  end
@@ -1,5 +1,6 @@
1
1
  require 'forwardable'
2
2
  require 'delegate'
3
+ require 'locabulary/item'
3
4
 
4
5
  module Locabulary
5
6
  # A wrapper for a Locabulary::Items::Base that includes information from
@@ -22,7 +23,7 @@ module Locabulary
22
23
  predicate_name = options.fetch(:predicate_name)
23
24
  faceted_node = options.fetch(:faceted_node)
24
25
  term_label = options.fetch(:term_label)
25
- locabulary_item = Locabulary::Item.build(predicate_name: predicate_name, term_label: term_label, default_presentation_sequence: nil)
26
+ locabulary_item = Item.build(predicate_name: predicate_name, term_label: term_label, default_presentation_sequence: nil)
26
27
  new(faceted_node: faceted_node, locabulary_item: locabulary_item)
27
28
  end
28
29
 
@@ -34,7 +35,7 @@ module Locabulary
34
35
  # @see Locabulary::FacetedHierarchicalTreeSorter
35
36
  # @param options [Hash]
36
37
  # @option predicate_name [String]
37
- # @option faceted_node [#qvalue, #value, #hits]
38
+ # @option faceted_node [#value, #hits]
38
39
  # @option term_label [String]
39
40
  # @return Locabulary::FacetWrapperForItem
40
41
  def self.build_for_faceted_node_and_locabulary_item(options = {})
@@ -53,6 +54,6 @@ module Locabulary
53
54
  attr_reader :__faceted_node__, :__locabulary_item__
54
55
 
55
56
  extend Forwardable
56
- def_delegators :__faceted_node__, :qvalue, :value, :hits
57
+ def_delegators :__faceted_node__, :value, :hits
57
58
  end
58
59
  end
@@ -15,11 +15,12 @@ module Locabulary
15
15
  # @see Locabulary::Items
16
16
  def self.build(attributes = {})
17
17
  predicate_name = attributes.fetch(:predicate_name) { attributes.fetch('predicate_name') }
18
- builder_for(predicate_name: predicate_name).call(attributes)
18
+ class_to_instantiate(predicate_name: predicate_name).new(attributes)
19
19
  end
20
20
 
21
21
  # @api public
22
22
  # @since 0.2.1
23
+ # @deprecated 0.6.0 Prefer instead class_to_instantiate
23
24
  #
24
25
  # Responsible for finding the appropriate Factory method for building a Locabulary::Item
25
26
  #
@@ -27,14 +28,25 @@ module Locabulary
27
28
  # @option predicate_name [String] Used for lookup of the correct Locabulary::Item type
28
29
  # @return [#call] A builder method (`.new` for the given constant)
29
30
  def self.builder_for(options = {})
31
+ class_to_instantiate(options).method(:new)
32
+ end
33
+
34
+ # @api public
35
+ # @since 0.5.1
36
+ #
37
+ # Responsible for finding the appropriate class that will be instantiated
38
+ #
39
+ # @param options [Hash]
40
+ # @option options [String] :predicate_name Used for lookup of the correct Locabulary::Item type
41
+ # @return [Locabulary::Items::Base]
42
+ def self.class_to_instantiate(options = {})
30
43
  predicate_name = options.fetch(:predicate_name)
31
44
  possible_class_name_for_predicate_name = predicate_name.singularize.classify
32
- klass = begin
45
+ begin
33
46
  Items.const_get(possible_class_name_for_predicate_name)
34
47
  rescue NameError
35
48
  Items::Base
36
49
  end
37
- klass.method(:new)
38
50
  end
39
51
  end
40
52
  end
@@ -1,3 +1,3 @@
1
1
  module Locabulary
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  end
data/lib/locabulary.rb CHANGED
@@ -108,10 +108,4 @@ module Locabulary
108
108
  def self.active_labels_for(options = {})
109
109
  active_items_for(options).map(&:term_label)
110
110
  end
111
-
112
- # @api private
113
- def self.reset_active_cache!
114
- Commands::ActiveItemsForCommand.reset_cache!
115
- Commands::ActiveHierarchicalRootsCommand.reset_cache!
116
- end
117
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locabulary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
@@ -240,6 +240,7 @@ files:
240
240
  - LICENSE
241
241
  - README.md
242
242
  - Rakefile
243
+ - bin/rspec_isolated
243
244
  - config/client_secrets.example.yml
244
245
  - data/administrative_units.json
245
246
  - data/affiliation.json