datashift 0.11.0 → 0.11.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.11.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "datashift"
8
- s.version = "0.11.0"
8
+ s.version = "0.11.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Thomas Statter"]
@@ -16,6 +16,13 @@ module DataShift
16
16
 
17
17
  module Querying
18
18
 
19
+ # Options:
20
+ #
21
+ # :split_on_prefix : Add a prefix to each search term
22
+ # :case_sensitive : Default is a case insensitive lookup.
23
+ # :use_like : Attempts a lookup using ike and x% rather than equality
24
+ #
25
+
19
26
  def search_for_record(klazz, field, search_term, options = {})
20
27
 
21
28
  begin
@@ -40,27 +47,31 @@ module DataShift
40
47
 
41
48
  # Find a record for model klazz, looking up on field containing search_terms
42
49
  # Responds to global Options :
50
+ #
51
+ # :add_prefix : Add a prefix to each search term
43
52
  # :case_sensitive : Default is a case insensitive lookup.
44
- # :use_like : Attempts a lookup using ike and x% rather than equality
53
+ # :use_like : Attempts a lookup using ike and x% rather than equality
45
54
  #
46
55
  # Returns nil if no record found
47
- def get_record_by(klazz, field, search_term, split_on = ' ', split_on_prefix = nil)
56
+ def get_record_by(klazz, field, search_term, split_on = ' ', options = {})
48
57
 
49
58
  begin
50
-
59
+
60
+ split_on_prefix = options[:add_prefix]
61
+
51
62
  record = search_for_record(klazz, field, search_term)
52
63
 
53
64
  # try individual portions of search_term, front -> back i.e "A_B_C_D" => A, B, C etc
54
65
  search_term.split(split_on).each do |str|
55
66
  z = (split_on_prefix) ? "#{split_on_prefix}#{str}": str
56
- record = search_for_record(klazz, field, z)
67
+ record = search_for_record(klazz, field, z, options)
57
68
  break if record
58
69
  end unless(record)
59
70
 
60
71
  # this time try incrementally scanning i.e "A_B_C_D" => A, A_B, A_B_C etc
61
72
  search_term.split(split_on).inject("") do |str, term|
62
73
  z = (split_on_prefix) ? "#{split_on_prefix}#{str}#{split_on}#{term}": "#{str}#{split_on}#{term}"
63
- record = search_for_record(klazz, field, z)
74
+ record = search_for_record(klazz, field, z, options)
64
75
  break if record
65
76
  term
66
77
  end unless(record)
@@ -74,8 +85,8 @@ module DataShift
74
85
  end
75
86
  end
76
87
 
77
- def get_record_by!(klazz, field, search_terms, split_on = ' ', split_on_prefix = nil)
78
- x = get_record_by(klazz, field, search_terms, split_on, split_on_prefix)
88
+ def get_record_by!(klazz, field, search_terms, split_on = ' ', options = {} )
89
+ x = get_record_by(klazz, field, search_terms, split_on, options)
79
90
 
80
91
  raise RecordNotFound, "No #{klazz} record found for [#{search_terms}] on #{field}" unless(x)
81
92
 
@@ -136,7 +136,7 @@ module DataShift
136
136
  record = nil
137
137
 
138
138
  puts "Attempting to find matching record where #{attach_to_find_by_field} ~= #{base_name}"
139
- record = get_record_by(attach_to_klass, attach_to_find_by_field, base_name, split_on)
139
+ record = get_record_by(attach_to_klass, attach_to_find_by_field, base_name, split_on, options)
140
140
 
141
141
  if(record)
142
142
  puts "Found record for attachment :\n#{record.inspect}"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: datashift
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.11.0
5
+ version: 0.11.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Thomas Statter