array-unique 1.1.0 → 1.1.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.
@@ -1,7 +1,3 @@
1
1
 
2
2
  class ::Array::Unique < ::Array::Hooked
3
3
  end
4
-
5
- class ::UniqueArray < ::Array::Unique
6
- end
7
-
@@ -10,5 +10,3 @@ files = [
10
10
  files.each do |this_file|
11
11
  require_relative( File.join( basepath, this_file ) + '.rb' )
12
12
  end
13
-
14
- require_relative( basepath + '.rb' )
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'array/hooked'
3
+ #require_relative '../../../array-hooked/lib/array-hooked.rb'
3
4
 
4
5
  # namespaces that have to be declared ahead of time for proper load order
5
6
  require_relative './namespaces'
@@ -9,6 +10,6 @@ require_relative './requires.rb'
9
10
 
10
11
  class ::Array::Unique < ::Array::Hooked
11
12
 
12
- include ::Array::Unique::Interface
13
+ include ::Array::Unique::ArrayInterface
13
14
 
14
15
  end
@@ -1,5 +1,5 @@
1
1
 
2
- module ::Array::Unique::Interface
2
+ module ::Array::Unique::ArrayInterface
3
3
 
4
4
  include ::Array::Hooked::ArrayInterface
5
5
 
@@ -9,7 +9,7 @@ module ::Array::Unique::Interface
9
9
  # initialize #
10
10
  ################
11
11
 
12
- def initialize( *args )
12
+ def initialize( configuration_instance = nil, *args )
13
13
 
14
14
  @unique_keys = { }
15
15
 
@@ -32,64 +32,48 @@ module ::Array::Unique::Interface
32
32
 
33
33
  # make sure that set is unique
34
34
  unless @unique_keys.has_key?( object )
35
+
36
+ if index > count
37
+ index = count
38
+ unless object.nil? or @unique_keys.has_key?( nil )
39
+ index += 1
40
+ end
41
+ end
42
+ return_value = super
35
43
 
36
44
  @unique_keys[ object ] = true
37
45
 
38
- return_value = super
39
-
40
46
  end
41
47
 
42
48
  return return_value
43
49
 
44
50
  end
45
51
 
46
- ############
47
- # insert #
48
- ############
52
+ ################################################
53
+ # perform_single_object_insert_between_hooks #
54
+ ################################################
49
55
 
50
- def insert( index, *objects )
51
-
52
- # we only insert if we don't already have the object being inserted
53
- # for this reason we return nil if no insert occurred
56
+ def perform_single_object_insert_between_hooks( index, object )
54
57
 
55
- # if we have less elements in self than the index we are inserting at
56
- # we need to make sure the nils inserted cascade
57
- if index > count
58
- if @unique_keys.has_key?( nil )
59
- index -= ( index - count + 1 )
60
- else
61
- objects.unshift( nil )
62
- index -= ( index - count )
63
- end
58
+ if @unique_keys.has_key?( object )
59
+ index = nil
60
+ else
61
+ @unique_keys[ object ] = true
62
+ index = super
64
63
  end
65
64
 
66
- # get rid of objects already inserted
67
- indexes_to_delete = [ ]
68
- objects.each_with_index do |this_object, index|
69
- if @unique_keys.has_key?( this_object )
70
- indexes_to_delete.push( index )
71
- else
72
- @unique_keys[ this_object ] = true
73
- end
74
- end
75
- indexes_to_delete.sort.reverse.each do |this_index|
76
- objects.delete_at( this_index )
77
- end
78
-
79
- return nil if objects.empty?
80
-
81
- return super
65
+ return index
82
66
 
83
67
  end
84
-
85
- ##################################
86
- # perform_delete_between_hooks #
87
- ##################################
88
68
 
89
- def perform_delete_between_hooks( index )
90
-
69
+ #####################################
70
+ # perform_delete_at_between_hooks #
71
+ #####################################
72
+
73
+ def perform_delete_at_between_hooks( index )
74
+
91
75
  @unique_keys.delete( self[ index ] )
92
-
76
+
93
77
  return super
94
78
 
95
79
  end
@@ -543,7 +543,7 @@ describe ::Array::Unique do
543
543
 
544
544
  it 'has a hook that is called before setting a value; return value is used in place of object' do
545
545
 
546
- class ::Array::Unique::SubMockPreSet < ::Array::Hooked
546
+ class ::Array::Unique::SubMockPreSet < ::Array::Unique
547
547
 
548
548
  def pre_set_hook( index, object, is_insert = false )
549
549
  return :some_other_value
@@ -565,7 +565,7 @@ describe ::Array::Unique do
565
565
 
566
566
  it 'has a hook that is called after setting a value' do
567
567
 
568
- class ::Array::Unique::SubMockPostSet < ::Array::Hooked
568
+ class ::Array::Unique::SubMockPostSet < ::Array::Unique
569
569
 
570
570
  def post_set_hook( index, object, is_insert = false )
571
571
  return :some_other_value
@@ -587,7 +587,7 @@ describe ::Array::Unique do
587
587
 
588
588
  it 'has a hook that is called before getting a value; if return value is false, get does not occur' do
589
589
 
590
- class ::Array::Unique::SubMockPreGet < ::Array::Hooked
590
+ class ::Array::Unique::SubMockPreGet < ::Array::Unique
591
591
 
592
592
  def pre_get_hook( index )
593
593
  return false
@@ -610,7 +610,7 @@ describe ::Array::Unique do
610
610
 
611
611
  it 'has a hook that is called after getting a value' do
612
612
 
613
- class ::Array::Unique::SubMockPostGet < ::Array::Hooked
613
+ class ::Array::Unique::SubMockPostGet < ::Array::Unique
614
614
 
615
615
  def post_get_hook( index, object )
616
616
  return :some_other_value
@@ -633,7 +633,7 @@ describe ::Array::Unique do
633
633
 
634
634
  it 'has a hook that is called before deleting an index; if return value is false, delete does not occur' do
635
635
 
636
- class ::Array::Unique::SubMockPreDelete < ::Array::Hooked
636
+ class ::Array::Unique::SubMockPreDelete < ::Array::Unique
637
637
 
638
638
  def pre_delete_hook( index )
639
639
  return false
@@ -656,7 +656,7 @@ describe ::Array::Unique do
656
656
 
657
657
  it 'has a hook that is called after deleting an index' do
658
658
 
659
- class ::Array::Unique::SubMockPostDelete < ::Array::Hooked
659
+ class ::Array::Unique::SubMockPostDelete < ::Array::Unique
660
660
 
661
661
  def post_delete_hook( index, object )
662
662
  return :some_other_value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array-unique
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-30 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: array-hooked