locabulary 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 278eebac39c183be338728d67f3be9fab289bc96
4
- data.tar.gz: 6ed77a8d3f22e607c0a083cbe1f14c22e83ef835
3
+ metadata.gz: f1eb4d78aa929a7b2ef35ab9a952a1bdb8c0ca23
4
+ data.tar.gz: 871c5926d7e64db00a969b719822571cfaf01f20
5
5
  SHA512:
6
- metadata.gz: be8235aa07b3e25f76d51ec1559d0d1050430ce54bf3156be255e8bbb7b88d426f60dc1ea1680a11c49000567663dc83615a343a5410fcfb82b2b87639601478
7
- data.tar.gz: 58887e1e050416cec0011b9f4d1e8848e2a06107c2387401987cb2262cd97f48a32b6f0358a1ede2ec52f8987e947d3ca02603939e7fa3aba237e823043fe338
6
+ metadata.gz: 68d54f45f0210abacc45a9a2ddf7011099eeaea01a6622bf3c042370ad19c46d7dc07711b9f8ffed3b2d0573ccd3ba16f7c0499e78342fad71f0c616c0400617
7
+ data.tar.gz: 3b306460efc705ce496ff1b1297013a2b8056416591bcb958fc58786fd6b86e1fbe9805d93c248d95e4e0152a0cbebc07f13ca5641b5c7b85a58d60f7c562d56
data/lib/locabulary.rb CHANGED
@@ -2,13 +2,11 @@ require 'date'
2
2
  require 'json'
3
3
  require 'locabulary/exceptions'
4
4
  require 'locabulary/item'
5
- require 'locabulary/commands/build_ordered_hierarchical_tree_command'
6
- require 'locabulary/commands/active_items_for_command'
7
- require 'locabulary/commands/active_hierarchical_roots_command'
5
+ require 'locabulary/services'
8
6
 
9
7
  # @since 0.1.0
10
8
  module Locabulary
11
- # @api private
9
+ # @api public
12
10
  # @since 0.5.0
13
11
  #
14
12
  # Responsible for building a hierarchical tree from faceted items, and ordering the nodes as per the presentation sequence for the
@@ -18,11 +16,11 @@ module Locabulary
18
16
  # @option options [String] :predicate_name
19
17
  # @option options [Array<#hits, #value>] :faceted_items
20
18
  # @option options [String] :faceted_item_hierarchy_delimiter
21
- # @return Array[<FacetWrapperForItem>]
19
+ # @return [Array<FacetWrapperForItem>]
22
20
  #
23
- # @see Locabulary::Commands::BuildOrderedHierarchicalTree
21
+ # @see Locabulary::Services
24
22
  def self.build_ordered_hierarchical_tree(options = {})
25
- Commands::BuildOrderedHierarchicalTreeCommand.call(options)
23
+ Services.call(:build_ordered_hierarchical_tree, options)
26
24
  end
27
25
 
28
26
  # @api public
@@ -33,11 +31,11 @@ module Locabulary
33
31
  # @param [Hash] options
34
32
  # @option options [String] :predicate_name
35
33
  # @option options [Date] :as_of (Date.today)
36
- # @return Array[<Locabulary::Items::Base>]
34
+ # @return [Array<Locabulary::Items::Base>]
37
35
  #
38
- # @see Locabulary::Commands::ActiveItemsForCommand
36
+ # @see Locabulary::Services
39
37
  def self.active_items_for(options = {})
40
- Commands::ActiveItemsForCommand.call(options)
38
+ Services.call(:active_items_for, options)
41
39
  end
42
40
 
43
41
  # @api public
@@ -50,12 +48,17 @@ module Locabulary
50
48
  # @option options [String] :predicate_name
51
49
  # @option options [Date] :as_of (Date.today)
52
50
  # @return [Array<Locabulary::Items::Base>] - the root nodes
51
+ # @see Locabulary::Services
53
52
  def self.active_hierarchical_roots(options = {})
54
- Commands::ActiveHierarchicalRootsCommand.call(options)
53
+ Services.call(:active_hierarchical_roots, options)
55
54
  end
56
55
 
57
56
  # @api public
58
57
  # @since 0.5.0
58
+ #
59
+ # For the given :predicate_name and :term_label find an item.
60
+ # We prefer to find an active item, but will settle for a non-active item.
61
+ #
59
62
  # @param options [Hash]
60
63
  # @option options [String] :predicate_name
61
64
  # @option options [String] :term_label
@@ -11,6 +11,8 @@ module Locabulary
11
11
  new(options).call
12
12
  end
13
13
 
14
+ private_class_method :new
15
+
14
16
  # @param options [Hash]
15
17
  # @option options [#call] :item_builder - when called will create a Locabulary::Items::Base object
16
18
  # @option options [#call] :predicate_name -
@@ -20,7 +20,7 @@ module Locabulary
20
20
 
21
21
  # @api public
22
22
  # @since 0.2.1
23
- # @deprecated 0.6.0 Prefer instead class_to_instantiate
23
+ # @deprecated 0.6.0 Prefer instead class_to_instantiate; This will be removed in 0.7.0.
24
24
  #
25
25
  # Responsible for finding the appropriate Factory method for building a Locabulary::Item
26
26
  #
@@ -58,6 +58,7 @@ module Locabulary
58
58
  @children = []
59
59
  end
60
60
 
61
+ # @api private
61
62
  def to_h
62
63
  attribute_names.each_with_object({}) do |key, mem|
63
64
  mem[key.to_s] = send(key) unless send(key).to_s.strip == ''
@@ -66,6 +67,7 @@ module Locabulary
66
67
  end
67
68
  alias as_json to_h
68
69
 
70
+ # @api public
69
71
  def to_persistence_format_for_fedora
70
72
  return term_uri unless term_uri.to_s.strip == ''
71
73
  term_label
@@ -102,39 +104,50 @@ module Locabulary
102
104
  default_presentation_sequence || SORT_SEQUENCE_FOR_NIL
103
105
  end
104
106
 
107
+ # @api public
105
108
  def children
106
109
  @children.sort
107
110
  end
108
111
 
112
+ # @api private
113
+ # Yes, this is private. Its an internal mechanism.
109
114
  def add_child(*input)
110
115
  @children += input
111
116
  end
112
117
 
113
118
  HIERARCHY_DELIMITER = '::'.freeze
119
+
120
+ # @api public
114
121
  def slugs
115
122
  term_label.split(HIERARCHY_DELIMITER)
116
123
  end
117
124
 
125
+ # @api public
118
126
  def self.hierarchy_delimiter
119
127
  HIERARCHY_DELIMITER
120
128
  end
121
129
 
130
+ # @api public
122
131
  def parent_slugs
123
132
  slugs[0..-2]
124
133
  end
125
134
 
135
+ # @api public
126
136
  def parent_term_label
127
137
  parent_slugs.join(HIERARCHY_DELIMITER)
128
138
  end
129
139
 
140
+ # @api public
130
141
  def root_slug
131
142
  slugs[0]
132
143
  end
133
144
 
145
+ # @api public
134
146
  def selectable?
135
147
  children.count.zero?
136
148
  end
137
149
 
150
+ # @api public
138
151
  # When rendered as part of a select list
139
152
  def selectable_label
140
153
  slugs[-1]
@@ -142,6 +155,7 @@ module Locabulary
142
155
 
143
156
  alias selectable_id id
144
157
 
158
+ # @api public
145
159
  # When rendered as part of a facet list
146
160
  def hierarchy_facet_label
147
161
  slugs[-1]
@@ -0,0 +1,27 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'locabulary/services/build_ordered_hierarchical_tree_command'
3
+ require 'locabulary/services/active_items_for_command'
4
+ require 'locabulary/services/active_hierarchical_roots_command'
5
+
6
+ module Locabulary
7
+ # @api private
8
+ #
9
+ # A container namespace for service style objects; These service objects are
10
+ # responsible for encapsulating logic related to interaction with the data
11
+ # storage.
12
+ module Services
13
+ # @api private
14
+ # @since 0.6.1
15
+ #
16
+ # Responsible for delegating messages to underlying class.
17
+ # This indirection is used to protect the direct to private classes and thus
18
+ # keep a tightly defined interface.
19
+ #
20
+ # @param command_name [Symbol]
21
+ # @param options [Hash]
22
+ def self.call(command_name, options = {})
23
+ command_class = "#{command_name}_command".classify
24
+ const_get(command_class).call(options)
25
+ end
26
+ end
27
+ end
@@ -5,7 +5,10 @@ require 'locabulary/exceptions'
5
5
  require 'locabulary/hierarchy_processor'
6
6
 
7
7
  module Locabulary
8
- module Commands
8
+ # :nodoc:
9
+ module Services
10
+ # @api private
11
+ #
9
12
  # Responsible for transforming the flat data for the given :predicate_name
10
13
  # into a hierarchy.
11
14
  class ActiveHierarchicalRootsCommand
@@ -35,6 +38,8 @@ module Locabulary
35
38
  cache[predicate_name] ||= new(options).call
36
39
  end
37
40
 
41
+ private_class_method :new
42
+
38
43
  def initialize(options = {})
39
44
  @predicate_name = options.fetch(:predicate_name)
40
45
  @as_of = options.fetch(:as_of) { Date.today }
@@ -67,5 +72,6 @@ module Locabulary
67
72
  Utility
68
73
  end
69
74
  end
75
+ private_constant :ActiveHierarchicalRootsCommand
70
76
  end
71
77
  end
@@ -3,7 +3,10 @@ require 'locabulary/item'
3
3
  require 'locabulary/utility'
4
4
 
5
5
  module Locabulary
6
- module Commands
6
+ # :nodoc:
7
+ module Services
8
+ # @api private
9
+ #
7
10
  # Responsible for extracting a non-hierarchical sorted array of Locabulary::Item for the given predicate_name
8
11
  #
9
12
  # @see Locabulary::Item
@@ -35,6 +38,8 @@ module Locabulary
35
38
  cache[predicate_name] ||= new(options).call
36
39
  end
37
40
 
41
+ private_class_method :new
42
+
38
43
  def initialize(options = {})
39
44
  @predicate_name = options.fetch(:predicate_name)
40
45
  @as_of = options.fetch(:as_of) { Date.today }
@@ -53,5 +58,6 @@ module Locabulary
53
58
 
54
59
  attr_reader :predicate_name, :as_of, :builder
55
60
  end
61
+ private_constant :ActiveItemsForCommand
56
62
  end
57
63
  end
@@ -6,7 +6,10 @@ require 'locabulary/facet_wrapper_for_item'
6
6
  require 'locabulary/hierarchy_processor'
7
7
 
8
8
  module Locabulary
9
- module Commands
9
+ # :nodoc:
10
+ module Services
11
+ # @api private
12
+ #
10
13
  # Responsible for building a hierarchical tree from faceted items, and ordering the nodes as per the presentation sequence for the
11
14
  # associated predicate_name.
12
15
  class BuildOrderedHierarchicalTreeCommand
@@ -24,6 +27,8 @@ module Locabulary
24
27
  new(options).call
25
28
  end
26
29
 
30
+ private_class_method :new
31
+
27
32
  def initialize(options = {})
28
33
  @predicate_name = options.fetch(:predicate_name)
29
34
  @faceted_items = options.fetch(:faceted_items)
@@ -67,5 +72,6 @@ module Locabulary
67
72
  value.split(faceted_item_hierarchy_delimiter).join(locabulary_item_class.hierarchy_delimiter)
68
73
  end
69
74
  end
75
+ private_constant :BuildOrderedHierarchicalTreeCommand
70
76
  end
71
77
  end
@@ -1,3 +1,3 @@
1
1
  module Locabulary
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locabulary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-08 00:00:00.000000000 Z
11
+ date: 2016-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -258,9 +258,6 @@ files:
258
258
  - data/work_patent_strategy.json
259
259
  - data/work_publication_strategy.json
260
260
  - lib/locabulary.rb
261
- - lib/locabulary/commands/active_hierarchical_roots_command.rb
262
- - lib/locabulary/commands/active_items_for_command.rb
263
- - lib/locabulary/commands/build_ordered_hierarchical_tree_command.rb
264
261
  - lib/locabulary/exceptions.rb
265
262
  - lib/locabulary/facet_wrapper_for_item.rb
266
263
  - lib/locabulary/hierarchy_processor.rb
@@ -270,6 +267,10 @@ files:
270
267
  - lib/locabulary/items/base.rb
271
268
  - lib/locabulary/json_creator.rb
272
269
  - lib/locabulary/schema.rb
270
+ - lib/locabulary/services.rb
271
+ - lib/locabulary/services/active_hierarchical_roots_command.rb
272
+ - lib/locabulary/services/active_items_for_command.rb
273
+ - lib/locabulary/services/build_ordered_hierarchical_tree_command.rb
273
274
  - lib/locabulary/utility.rb
274
275
  - lib/locabulary/version.rb
275
276
  - locabulary.gemspec