cascading-configuration-array-unique 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -203,7 +203,7 @@ end
203
203
 
204
204
  (The MIT License)
205
205
 
206
- Copyright (c) 2011 Asher
206
+ Copyright (c) Asher
207
207
 
208
208
  Permission is hereby granted, free of charge, to any person obtaining
209
209
  a copy of this software and associated documentation files (the
@@ -36,7 +36,7 @@ See README.md
36
36
 
37
37
  (The MIT License)
38
38
 
39
- Copyright (c) 2011 Asher
39
+ Copyright (c) Asher
40
40
 
41
41
  Permission is hereby granted, free of charge, to any person obtaining
42
42
  a copy of this software and associated documentation files (the
@@ -1,25 +1,17 @@
1
1
 
2
+ require 'compositing-array-unique'
3
+
2
4
  if $__cascading_configuration__spec__development
3
- require_relative '../../settings-array/lib/cascading-configuration-array.rb'
5
+ require_relative '../../variable/lib/cascading-configuration-variable.rb'
4
6
  else
5
- require 'cascading-configuration-array'
7
+ require 'cascading-configuration-variable'
6
8
  end
7
9
 
8
10
  module ::CascadingConfiguration
9
11
  module Array
10
12
  module Unique
11
- class CompositingArray < ::CascadingConfiguration::Array::CompositingArray
12
- end
13
- module ModuleSupportMethods
14
- end
15
- module Interface
16
- end
17
13
  end
18
14
  end
19
15
  end
20
16
 
21
- require_relative 'cascading-configuration-array-unique/_private_/CascadingConfiguration/Array/Unique/CompositingArray.rb'
22
- require_relative 'cascading-configuration-array-unique/_private_/CascadingConfiguration/Array/Unique/ModuleSupportMethods.rb'
23
-
24
- require_relative 'cascading-configuration-array-unique/CascadingConfiguration/Array/Unique/Interface.rb'
25
17
  require_relative 'cascading-configuration-array-unique/CascadingConfiguration/Array/Unique.rb'
@@ -2,11 +2,53 @@
2
2
  module ::CascadingConfiguration::Array::Unique
3
3
 
4
4
  # Configuration modules for storage of settings arrays
5
- include ::CascadingConfiguration::Variable
5
+ include ::CascadingConfiguration::Inheritance
6
+
7
+ ##############################################
8
+ # attr_configuration_unique_array #
9
+ # attr_module_configuration_unique_array #
10
+ # attr_local_configuration_unique_array #
11
+ # attr_object_configuration_unique_array #
12
+ # attr_instance_configuration_unique_array #
13
+ ##############################################
14
+
15
+ def attr_configuration_unique_array( *configuration_names, & define_block ) ;; end
16
+ def attr_module_configuration_unique_array( *configuration_names, & define_block ) ;; end
17
+ def attr_class_configuration_unique_array( *configuration_names, & define_block ) ;; end
18
+ def attr_local_configuration_unique_array( *configuration_names, & define_block ) ;; end
19
+ def attr_object_configuration_unique_array( *configuration_names, & define_block ) ;; end
20
+ def attr_instance_configuration_unique_array( *configuration_names, & define_block ) ;; end
21
+
22
+ ccua = self
23
+ cca = ::CascadingConfiguration::Array
24
+ ccv = ::CascadingConfiguration::Variable
25
+ ccm = ::CascadingConfiguration::Methods
26
+
27
+ setter_proc = ::Proc.new do |instance, configuration_name, value|
28
+
29
+ return instance.__send__( configuration_name ).replace( value )
6
30
 
7
- # Interface to declare configuration settings arrays
8
- include ::CascadingConfiguration::Array::Unique::Interface
31
+ end
32
+
33
+ getter_proc = ::Proc.new do |instance, configuration_name|
34
+
35
+ composite_unique_array = nil
36
+
37
+ if ccv.has_configuration_variable?( instance, configuration_name )
38
+ composite_unique_array = ccv.get_configuration_variable( instance, configuration_name )
39
+ else
40
+ parent_composite_array = nil
41
+ if ancestor = ::CascadingConfiguration::Variable.ancestor( instance, configuration_name )
42
+ parent_composite_array = ancestor.__send__( configuration_name )
43
+ end
44
+ composite_unique_array = ::CompositingArray::Unique.new( parent_composite_array )
45
+ ccv.set_configuration_variable( instance, configuration_name, composite_unique_array )
46
+ end
47
+
48
+ return composite_unique_array
49
+
50
+ end
9
51
 
10
- extend ::CascadingConfiguration::Array::Unique::ModuleSupportMethods
52
+ ccm.declare_compositing_configuration_object( self, :unique_array, setter_proc, getter_proc )
11
53
 
12
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cascading-configuration-array-unique
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cascading-configuration-variable
16
- requirement: &70254022097220 !ruby/object:Gem::Requirement
16
+ requirement: &70261379169140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70254022097220
24
+ version_requirements: *70261379169140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: cascading-configuration-array
27
- requirement: &70254022096360 !ruby/object:Gem::Requirement
27
+ requirement: &70261379165120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,19 +32,15 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70254022096360
35
+ version_requirements: *70261379165120
36
36
  description: Provides :attr_configuration_array.
37
37
  email: asher@ridiculouspower.com
38
38
  executables: []
39
39
  extensions: []
40
40
  extra_rdoc_files: []
41
41
  files:
42
- - lib/cascading-configuration-array-unique/_private_/CascadingConfiguration/Array/Unique/CompositingArray.rb
43
- - lib/cascading-configuration-array-unique/_private_/CascadingConfiguration/Array/Unique/ModuleSupportMethods.rb
44
- - lib/cascading-configuration-array-unique/CascadingConfiguration/Array/Unique/Interface.rb
45
42
  - lib/cascading-configuration-array-unique/CascadingConfiguration/Array/Unique.rb
46
43
  - lib/cascading-configuration-array-unique.rb
47
- - spec/_private_/CascadingConfiguration/Array/CompositingArray_spec.rb
48
44
  - spec/CascadingConfiguration/Array/Unique_spec.rb
49
45
  - README.md
50
46
  - README.rdoc
@@ -68,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
64
  version: '0'
69
65
  requirements: []
70
66
  rubyforge_project: cascading-configuration-array-unique
71
- rubygems_version: 1.8.10
67
+ rubygems_version: 1.8.11
72
68
  signing_key:
73
69
  specification_version: 3
74
70
  summary: Support package for cascading-configuration.
@@ -1,111 +0,0 @@
1
-
2
- module ::CascadingConfiguration::Array::Unique::Interface
3
-
4
- ######################
5
- # self.setter_proc #
6
- ######################
7
-
8
- def self.setter_proc( configuration_name )
9
-
10
- return Proc.new do |array|
11
-
12
- return ::CascadingConfiguration::Array::Unique.set_composite_unique_array( self,
13
- configuration_name,
14
- array )
15
-
16
- end
17
-
18
- end
19
-
20
- ######################
21
- # self.getter_proc #
22
- ######################
23
-
24
- def self.getter_proc( configuration_name )
25
-
26
- return Proc.new do
27
-
28
- return ::CascadingConfiguration::Array::Unique.composite_unique_array( self,
29
- configuration_name )
30
-
31
- end
32
-
33
- end
34
-
35
- #####################################
36
- # attr_configuration_unique_array #
37
- #####################################
38
-
39
- # defines configuration in class or module
40
- # configuration cascades downward to instance including all classes or modules in-between
41
- def attr_configuration_unique_array( *configuration_names )
42
-
43
- return ::CascadingConfiguration::Variable.
44
- define_cascading_configuration( self,
45
- ::CascadingConfiguration::Array::Unique::Interface,
46
- *configuration_names )
47
-
48
- end
49
-
50
- ############################################
51
- # attr_module_configuration_unique_array #
52
- ############################################
53
-
54
- # defines configuration in class or module
55
- # configuration cascades downward to last class or module
56
- def attr_module_configuration_unique_array( *configuration_names )
57
-
58
- return ::CascadingConfiguration::Variable.
59
- define_module_configuration( self,
60
- ::CascadingConfiguration::Array::Unique::Interface,
61
- *configuration_names )
62
-
63
- end
64
- alias_method :attr_class_configuration_unique_array, :attr_module_configuration_unique_array
65
-
66
- ###########################################
67
- # attr_local_configuration_unique_array #
68
- ###########################################
69
-
70
- # defines configuration in present class or module context
71
- # configuration does not cascade
72
- def attr_local_configuration_unique_array( *configuration_names )
73
-
74
- return ::CascadingConfiguration::Variable.
75
- define_local_configuration( self,
76
- ::CascadingConfiguration::Array::Unique::Interface,
77
- *configuration_names )
78
-
79
- end
80
-
81
- ############################################
82
- # attr_object_configuration_unique_array #
83
- ############################################
84
-
85
- # defines configuration in present instance
86
- # configuration does not cascade
87
- def attr_object_configuration_unique_array( *configuration_names )
88
-
89
- return ::CascadingConfiguration::Variable.
90
- define_object_configuration( self,
91
- ::CascadingConfiguration::Array::Unique::Interface,
92
- *configuration_names )
93
-
94
- end
95
-
96
- ##############################################
97
- # attr_instance_configuration_unique_array #
98
- ##############################################
99
-
100
- # defines configuration in present class or module context
101
- # configuration does not cascade
102
- def attr_instance_configuration_unique_array( *configuration_names )
103
-
104
- return ::CascadingConfiguration::Variable.
105
- define_instance_configuration( self,
106
- ::CascadingConfiguration::Array::Unique::Interface,
107
- *configuration_names )
108
-
109
- end
110
-
111
- end
@@ -1,166 +0,0 @@
1
-
2
- class ::CascadingConfiguration::Array::Unique::CompositingArray <
3
- ::CascadingConfiguration::Array::CompositingArray
4
-
5
- ################
6
- # initialize #
7
- ################
8
-
9
- def initialize( configuration_instance, configuration_name )
10
-
11
- @unique_keys = { }
12
-
13
- super
14
-
15
- end
16
-
17
- ##################################### Self Management ##########################################
18
-
19
- #########
20
- # []= #
21
- #########
22
-
23
- def []=( index, object )
24
-
25
- # we only set if we don't already have the object being inserted
26
- # for this reason we return nil if no insert occurred
27
-
28
- return_value = nil
29
-
30
- # make sure that set is unique
31
- unless @unique_keys.has_key?( object )
32
-
33
- @unique_keys[ object ] = true
34
-
35
- return_value = super
36
-
37
- end
38
-
39
- return return_value
40
-
41
- end
42
-
43
- ############
44
- # insert #
45
- ############
46
-
47
- def insert( index, *objects )
48
-
49
- # we only insert if we don't already have the object being inserted
50
- # for this reason we return nil if no insert occurred
51
-
52
- # if we have less elements in self than the index we are inserting at
53
- # we need to make sure the nils inserted cascade
54
- if index > count
55
- if @unique_keys.has_key?( nil )
56
- index -= ( index - count + 1 )
57
- else
58
- objects.unshift( nil )
59
- index -= ( index - count )
60
- end
61
- end
62
-
63
- # get rid of objects already inserted
64
- indexes_to_delete = [ ]
65
- objects.each_with_index do |this_object, index|
66
- if @unique_keys.has_key?( this_object )
67
- indexes_to_delete.push( index )
68
- else
69
- @unique_keys[ this_object ] = true
70
- end
71
- end
72
- indexes_to_delete.sort.reverse.each do |this_index|
73
- objects.delete_at( this_index )
74
- end
75
-
76
- return nil if objects.empty?
77
-
78
- return super
79
-
80
- end
81
-
82
- ##############
83
- # collect! #
84
- # map! #
85
- ##############
86
-
87
- def collect!
88
-
89
- return to_enum unless block_given?
90
-
91
- delete_indexes = [ ]
92
- self.each_with_index do |this_object, index|
93
- replacement_object = yield( this_object )
94
- if @unique_keys.has_key?( replacement_object ) and replacement_object != this_object
95
- delete_indexes.push( index )
96
- else
97
- self[ index ] = replacement_object
98
- end
99
- end
100
-
101
- delete_indexes.sort.reverse.each do |this_index|
102
- delete_at( this_index )
103
- end
104
-
105
- return self
106
-
107
- end
108
- alias_method :map!, :collect!
109
-
110
- ##################################################################################################
111
- private ######################################################################################
112
- ##################################################################################################
113
-
114
- #############################
115
- # non_cascading_delete_at #
116
- #############################
117
-
118
- def non_cascading_delete_at( index )
119
-
120
- object = super
121
-
122
- @unique_keys.delete( object )
123
-
124
- return object
125
-
126
- end
127
-
128
- ######################### Self-as-Sub Management for Parent Updates ############################
129
-
130
- ########################################
131
- # update_as_sub_array_for_parent_set #
132
- ########################################
133
-
134
- def update_as_sub_array_for_parent_set( index, object )
135
-
136
- super unless @unique_keys.has_key?( object )
137
-
138
- end
139
-
140
- ###########################################
141
- # update_as_sub_array_for_parent_insert #
142
- ###########################################
143
-
144
- def update_as_sub_array_for_parent_insert( index, *objects )
145
-
146
- # new parent indexes have been inserted at index in parent
147
-
148
- # get rid of objects already inserted
149
- indexes_to_delete = [ ]
150
- objects.each_with_index do |this_object, index|
151
- if @unique_keys.has_key?( this_object )
152
- indexes_to_delete.push( index )
153
- else
154
- @unique_keys[ this_object ] = true
155
- end
156
- end
157
- indexes_to_delete.sort.reverse.each do |this_index|
158
- objects.delete_at( this_index )
159
- end
160
- return false if objects.empty?
161
-
162
- super
163
-
164
- end
165
-
166
- end