nested_array 1.2.0 → 2.0.0

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
  SHA256:
3
- metadata.gz: 540363bb5ada651621c74257b8d1f79015f3916443ce58a328a040eb53770edf
4
- data.tar.gz: 743c036b6644d16f66822ad083cb5d3d72ecad7e47976e30e4c058d313101ff2
3
+ metadata.gz: 6d681422cfda9dbfc86841b49ced1e215bf6dbb0a35676df690748922b4aac7b
4
+ data.tar.gz: 151c06bb5ebbf793bd6b90fee9fd3d8dcea0485fda834fa65cceb2e1edc38928
5
5
  SHA512:
6
- metadata.gz: 45d7dc6fdfebfed713c4c45172a10ede2b4fe5fc562ae4c2a3faf148ac42e44ae1d3823875f45667f3a894bd02ca78df7bee5de217deb8b8dece8817847d9ee5
7
- data.tar.gz: a0b0e64c7c8fa384ae20381fbbb361154445935d80ae1da742428976bd0f6d27e0389854120203e83741290397eda133d41c7d9966dcb22d565096d7845560c0
6
+ metadata.gz: da25eac83649dcd5ddcaf537be626c682192137bce781dd5e35062970929a262b3cab604624feb4e4cc06a420f1ab5e03f7bc817c661dc0082342adf54666813
7
+ data.tar.gz: caeb434ad4c64d90c25d9440ce38fa5173b52c8b6776b071a7ba3c514535a3aed179d85fe83ea70ee8a4bda105d0686c828be1f7e2780cccb3432176c69f8e96
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nested_array (1.2.0)
4
+ nested_array (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -49,4 +49,4 @@ DEPENDENCIES
49
49
  rspec (~> 3.9)
50
50
 
51
51
  BUNDLED WITH
52
- 2.1.4
52
+ 2.0.1
data/README-ru.md CHANGED
@@ -1,224 +1,48 @@
1
1
  # NestedArray
2
2
 
3
- Предназначен для преобразования в древовидную структуру плоских данных описанных по паттерну «Список смежности» (Adjacency List), то есть в нодах указа предок `parent_id`. Например:
3
+ Предназначен для преобразования в древовидную структуру плоских данных описанных по паттерну «Список смежности» (Adjacency List), то есть в нодах указа предок `parent_id`.
4
4
 
5
5
  ```ruby
6
6
  [
7
7
  {id: 1, parent_id: nil, name: 'first', …},
8
8
  {id: 2, parent_id: 1, name: 'second', …},
9
- {id: 3, parent_id: 1, name: 'third', }
9
+
10
10
  ]
11
11
  # ↓ ↓ ↓
12
12
  [
13
- {id: 1, parent_id: nil, name: 'first', children: [
14
- {id: 2, parent_id: 1, name: 'second', …},
15
- {id: 3, parent_id: 1, name: 'third', …}
16
- ], …}
17
13
  ]
18
14
  ```
19
15
 
16
+ ## Installation
20
17
 
21
-
22
-
23
- ## Установка
24
-
25
- Добавте строку в _Gemfile_ вашего приложения:
26
-
27
- ```ruby
28
- gem 'nested_array', '~> 1.0.0' # версия не расширяет базовый класс Array методами гема. Для использования необходимо преобразовать данные к новому типу, см ниже.
29
- gem 'nested_array', '~> 2.0.0' # Версия с автоматическим расширением базового класса Array методами гема.
30
- ```
31
-
32
- И затем выполните `bundle install`.
33
-
34
- Или установите его как `gem install nested_array`
35
-
36
-
37
-
38
-
39
- ## Использование
40
-
41
- <a name="methods"></a>
42
- __Список методов__
43
-
44
- * [to_nested](#to_nested) — преобразует плоскую структуру во вложенную;
45
- * [each_nested](#each_nested) — перебирает вложенную стуктуру;
46
- * [each_nested!](#each_nested) — перебирает вложенную стуктуру, предоставляя доступ к исходным данным;
47
- * [nested_to_html](#nested_to_html) — преобразует вложенную структуру в html вёрстку (многоуровневый список `<ul><li>…`);
48
- * [nested_to_options](#nested_to_options) — преобразует вложенную структуру в массив для формирования опций html-тега `<select>` с псевдографикой;
49
- * [concat_nested](#concat_nested) — скеивание вложенных структур, ноды склеиваются если путь к ним одинаков.
50
-
51
-
52
-
53
-
54
- <a name="to_nested"></a>
55
- ### to_nested [↑](#methods "К методам")
56
-
57
- Преобразует плоскую структуру во вложенную.
58
-
59
- ```ruby
60
- a = [{'id' => 1, 'parent_id' => nil}]
61
- a = NestedArray::Array.new a
62
- b = a.to_nested
63
- ```
64
-
65
- __Опции__
66
-
67
- У каждой ноды вложенной структуры есть базовые свойства, такие как идентификатор, идентификатор предка и другие. Для доступа к этим данным используются ключи, которые можно настроить как в примере ниже. По умолчанию используются следующие __строковые__ (_чувствительны к string/symbol_) ключи:
68
-
69
- ```ruby
70
- b = a.to_nested({
71
- id: 'id', # указывает какое свойство ноды является идентификатором;
72
- parent_id: 'parent_id', # -//- предком;
73
- children: 'children', # -//- массивом потомков;
74
- level: 'level' # -//- дополнительным свойством с уровнем вложенности;
75
- root_id: nil # определяет что является корнем для построения дерева,
76
- # например, для построения ветви корнем корнем
77
- # является идентификатор одной из нод.
78
- })
79
- ```
80
-
81
- Дополнительные опции преобразования:
82
-
83
- ```ruby
84
- b = a.to_nested({
85
- hashed: false, # потомки могут храниться не в массиве а в хэше;
86
- add_level: false, # добавляет в ноду информацию о уровене вложенности ноды;
87
- })
88
- ```
89
-
90
-
91
-
92
-
93
- <a name="each_nested"></a>
94
- ### each_nested [↑](#methods "К методам")
95
-
96
- Перебирает вложенную стуктуру.
97
-
98
- ```ruby
99
- nested.each_nested do |node, parents, level, is_last_children|
100
- puts node # > {'id' => ...}
101
- puts parents # > [{'id' => ...}]
102
- puts level # > 0
103
- puts is_last_children # > false
104
- end
105
- ```
106
-
107
-
108
-
109
-
110
- <a name="nested_to_html"></a>
111
- ### nested_to_html [↑](#methods "К методам")
112
-
113
- Формирует _html_-код для вывода вложенных структур с использованием вложенных друг в друга списков `<ul>`.
114
-
115
- __Пример__
116
-
117
- ```ruby
118
- [
119
- {'id' => 1, 'parent_id' => nil, 'name' => 'first'},
120
- {'id' => 2, 'parent_id' => 1, 'name' => 'second'},
121
- {'id' => 3, 'parent_id' => 1, 'name' => 'third'}
122
- ].to_nested.nested_to_html do |node|
123
- node['name']
124
- end
125
- ```
126
-
127
- Вернёт
128
-
129
- ```html
130
- <li>first
131
- <ul>
132
- <li>second</li>
133
- <li>third</li>
134
- </ul>
135
- </li>
136
- ```
137
-
138
- __Расширенный пример__
139
-
140
- ```ruby
141
- .nested_to_html li: '<li class="my">', _ul: '<i></i></ul>' do |node, parents, level|
142
- block_options = {}
143
- block_options[:li] = '<li class="my current">' if node['id'] == 2
144
- [
145
- "id: #{node['id']}, #{node['name']}, parent name: #{parents[level]&.[]('name')}",
146
- block_options
147
- ]
148
- end
149
- ```
150
-
151
- __Опции__
152
-
153
- Все опции могут быть аргументами метода, и только некоторые опции влияют на результат через блок — на лету (последняя строка блока).
154
-
155
- ```ruby
156
- tabulated: true,
157
- inline: false,
158
- tab: "\t",
159
- ul: '<ul>', # может задаваться блоком
160
- _ul: '</ul>',
161
- li: '<li>', # может задаваться блоком
162
- _li: '</li>',
163
- ```
164
-
165
-
166
-
167
-
168
- <a name="nested_to_options"></a>
169
- ### nested_to_options [↑](#methods "К методам")
170
-
171
- Формирования опций для html-тега &lt;select&gt;
172
-
173
- Возвращает массив с псевдографикой, позволяющей вывести древовидную структуру.
18
+ Add this line to your application's Gemfile:
174
19
 
175
20
  ```ruby
176
-
177
- [['option_text1', 'option_value1'],['option_text2', 'option_value2'],…]
21
+ gem 'nested_array'
178
22
  ```
179
23
 
180
- __Опции__
181
-
182
- ```ruby
183
- option_value: 'id', # Что брать в качестве значений при формировании опций селекта.
184
- option_text: 'name',
185
- ```
186
-
187
-
188
-
189
-
190
- <a name="concat_nested"></a>
191
- ### concat_nested [↑](#methods "К методам")
192
-
193
- Скеивание вложенных структур.
194
-
195
- * Ноды склеиваются если путь к ним одинаков;
196
- * Путь определяется из сложения Текстов (конфигурируемо через :path_key);
197
-
198
- __Опции__
199
-
200
- ```ruby
201
- path_separator: '-=path_separator=-',
202
- path_key: 'text',
203
- ```
204
-
205
-
206
-
24
+ And then execute:
207
25
 
208
- ## Разработка
26
+ $ bundle
209
27
 
210
-
28
+ Or install it yourself as:
211
29
 
30
+ $ gem install nested_array
212
31
 
32
+ ## Usage
213
33
 
34
+ TODO: Write usage instructions here
214
35
 
215
- ## Содействие
36
+ ## Development
216
37
 
217
-
38
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
218
39
 
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
219
41
 
42
+ ## Contributing
220
43
 
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nested_array.
221
45
 
222
- ## Лицензия
46
+ ## License
223
47
 
224
- В соответствии с условиями [лицензии MIT](https://opensource.org/licenses/MIT).
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/README.md CHANGED
@@ -1,21 +1,5 @@
1
1
  # NestedArray
2
2
 
3
- It is intended for transformation into a tree structure of flat data described by the “Adjacency List” pattern, that is, the ancestor is specified in the nodes by the field `parent_id`. For instance:
4
-
5
- ```ruby
6
- [
7
- {id: 1, parent_id: nil, name: 'first', …},
8
- {id: 2, parent_id: 1, name: 'second', …},
9
- {id: 3, parent_id: 1, name: 'third', …}
10
- ]
11
- # ↓ ↓ ↓
12
- [
13
- {id: 1, parent_id: nil, name: 'first', children: [
14
- {id: 2, parent_id: 1, name: 'second', …},
15
- {id: 3, parent_id: 1, name: 'third', …}
16
- ], …}
17
- ]
18
- ```
19
3
 
20
4
 
21
5
  ## Installation
@@ -23,23 +7,20 @@ It is intended for transformation into a tree structure of flat data described b
23
7
  Add this line to your application's Gemfile:
24
8
 
25
9
  ```ruby
26
- gem 'nested_array', '~> 1.0.0'
27
- gem 'nested_array', '~> 2.0.0'
10
+ gem 'nested_array'
28
11
  ```
29
12
 
30
- And then execute: `bundle`.
13
+ And then execute:
31
14
 
32
- Or install it yourself as `gem install nested_array`.
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nested_array
33
20
 
34
21
  ## Usage
35
22
 
36
- ```html
37
- <ul>
38
- <%= Catalogs.all.to_a.to_nested.nested_to_html do |node| %>
39
- <% link_to "#{node['name']}", catalog_view_path(node['slug']) %>
40
- <% end %>
41
- </ul>
42
- ```
23
+ TODO: Write usage instructions here
43
24
 
44
25
  ## Development
45
26
 
@@ -49,7 +30,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
49
30
 
50
31
  ## Contributing
51
32
 
52
- Bug reports and pull requests are welcome on GitHub at https://github.com/Zlatov/nested_array.
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nested_array.
53
34
 
54
35
  ## License
55
36
 
@@ -0,0 +1,10 @@
1
+ continue
2
+ NestedArrayModule.class
3
+ NestedArrayModule
4
+ NestedArrayMod
5
+ NestedArray.class
6
+ NestedArray
7
+ self.parent
8
+ self.class
9
+ continue
10
+ NestedArray.class
data/lib/nested_array.rb CHANGED
@@ -11,7 +11,7 @@ module NestedArray
11
11
  end
12
12
  end
13
13
 
14
- # class Array
14
+ class Array
15
15
 
16
- # include ::NestedArray::Nested
17
- # end
16
+ include ::NestedArray::Nested
17
+ end
@@ -31,16 +31,9 @@ module NestedArray::Nested
31
31
  # Параматры для "склеивания" вложенных структур
32
32
  path_separator: '-=path_separator=-',
33
33
  path_key: 'text',
34
-
35
- # Настройки формирования массива для опций тега <select>
36
- option_value: 'id', # Что брать в качестве значений при формировании опций селекта.
37
- option_text: 'name',
38
34
  }
39
35
  end
40
36
 
41
- #
42
- # Перебирает вложенную стуктуру.
43
- #
44
37
  def each_nested options={}
45
38
  options = NESTED_OPTIONS.merge options
46
39
  level = 0
@@ -54,9 +47,8 @@ module NestedArray::Nested
54
47
  node = cache[level][i[level]]
55
48
  i[level]+= 1
56
49
  if node != nil
57
- is_last_children = cache[level][i[level]].blank?
58
50
 
59
- yield(node.clone, parents.clone, level, is_last_children)
51
+ yield(node.clone, parents.clone, level)
60
52
 
61
53
  if !node[options[:children]].nil? && node[options[:children]].length > 0
62
54
  level+= 1
@@ -252,16 +244,15 @@ module NestedArray::Nested
252
244
  i[level]+= 1
253
245
  if node != nil
254
246
 
255
- node_html, node_options = yield(node.clone, parents.clone, level)
256
247
  html+= options[:tab] * (level * 2 + 1) if options[:tabulated]
257
- html+= node_options&.[](:li) || options[:li]
258
- html+= node_html.to_s
248
+ html+= options[:li]
249
+ html+= yield(node.clone, parents.clone, level)
259
250
 
260
251
  if !node[options[:children]].nil? && node[options[:children]].length > 0
261
252
  level+= 1
262
253
  html+= "\n" if !options[:inline]
263
254
  html+= options[:tab] * (level * 2) if options[:tabulated]
264
- html+= node_options&.[](:ul) || options[:ul]
255
+ html+= options[:ul]
265
256
  html+= "\n" if !options[:inline]
266
257
  parents[level] = node.clone
267
258
  cache[level] = node[options[:children]]
@@ -286,29 +277,6 @@ module NestedArray::Nested
286
277
  html.html_safe
287
278
  end
288
279
 
289
- #
290
- # Возвращает массив для формирования опций html-тега <select>
291
- # с псевдографикой, позволяющей вывести древовидную структуру.
292
- # ```
293
- # [['option_text1', 'option_value1'],['option_text2', 'option_value2'],…]
294
- # ```
295
- def nested_to_options options={}
296
- options = NESTED_OPTIONS.merge options
297
- ret = []
298
- last = []
299
- each_nested do |node, parents, level, is_last|
300
- last[level+1] = is_last
301
- node_text = node[options[:option_text]]
302
- node_level = (1..level).map{|l| last[l] == true ? '&nbsp;' : '┃'}.join
303
- node_last = is_last ? '┗' : '┣'
304
- node_children = node[options[:children]].present? && node[options[:children]].length > 0 ? '┳' : '━'
305
- option_text = "#{node_level}#{node_last}#{node_children}╸#{node_text}"
306
- option_value = node[options[:option_value]]
307
- ret.push [option_text, option_value]
308
- end
309
- ret
310
- end
311
-
312
280
  # "Скеивание" вложенных структур
313
281
  # ноды склеиваются если путь к ним одинаков;
314
282
  # путь определяется из сложения Текстов (конфигурируемо через :path_key);
@@ -1,3 +1,3 @@
1
1
  module NestedArray
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_array
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zlatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,26 +98,14 @@ files:
98
98
  - README.md
99
99
  - Rakefile
100
100
  - bash/build/gem.sh
101
- - bash/push/gem.sh
102
101
  - bash/test/gem.sh
103
- - bin/bundle
104
- - bin/byebug
105
102
  - bin/console
106
- - bin/htmldiff
107
- - bin/ldiff
108
- - bin/rake
109
- - bin/rspec
110
103
  - bin/setup
111
- - dev/nested_options.rb
104
+ - lib/.byebug_history
112
105
  - lib/nested_array.rb
113
106
  - lib/nested_array/nested.rb
114
107
  - lib/nested_array/version.rb
115
108
  - nested_array.gemspec
116
- - test.old/Gemfile
117
- - test.old/Gemfile.lock
118
- - test.old/bash/run/bundle.sh
119
- - test.old/bash/run/test.sh
120
- - test.old/test.rb
121
109
  homepage: https://github.com/Zlatov/nested_array
122
110
  licenses:
123
111
  - MIT
@@ -140,7 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
128
  - !ruby/object:Gem::Version
141
129
  version: '0'
142
130
  requirements: []
143
- rubygems_version: 3.0.3
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.6
144
133
  signing_key:
145
134
  specification_version: 4
146
135
  summary: Convert a flat array into a nested one in 1 pass and another…
data/bash/push/gem.sh DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -eu
4
-
5
- cd "$(dirname "${0}")"
6
-
7
- cd ../..
8
-
9
- if [[ -z ${1-} ]]
10
- then
11
- echo "Не указан путь к скомпилированному гему" 1>&2;
12
- exit 0
13
- fi
14
-
15
- gem push $1
data/bin/bundle DELETED
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'bundle' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "rubygems"
12
-
13
- m = Module.new do
14
- module_function
15
-
16
- def invoked_as_script?
17
- File.expand_path($0) == File.expand_path(__FILE__)
18
- end
19
-
20
- def env_var_version
21
- ENV["BUNDLER_VERSION"]
22
- end
23
-
24
- def cli_arg_version
25
- return unless invoked_as_script? # don't want to hijack other binstubs
26
- return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
- bundler_version = nil
28
- update_index = nil
29
- ARGV.each_with_index do |a, i|
30
- if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
- bundler_version = a
32
- end
33
- next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
- bundler_version = $1 || ">= 0.a"
35
- update_index = i
36
- end
37
- bundler_version
38
- end
39
-
40
- def gemfile
41
- gemfile = ENV["BUNDLE_GEMFILE"]
42
- return gemfile if gemfile && !gemfile.empty?
43
-
44
- File.expand_path("../../Gemfile", __FILE__)
45
- end
46
-
47
- def lockfile
48
- lockfile =
49
- case File.basename(gemfile)
50
- when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
- else "#{gemfile}.lock"
52
- end
53
- File.expand_path(lockfile)
54
- end
55
-
56
- def lockfile_version
57
- return unless File.file?(lockfile)
58
- lockfile_contents = File.read(lockfile)
59
- return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
- Regexp.last_match(1)
61
- end
62
-
63
- def bundler_version
64
- @bundler_version ||= begin
65
- env_var_version || cli_arg_version ||
66
- lockfile_version || "#{Gem::Requirement.default}.a"
67
- end
68
- end
69
-
70
- def load_bundler!
71
- ENV["BUNDLE_GEMFILE"] ||= gemfile
72
-
73
- # must dup string for RG < 1.8 compatibility
74
- activate_bundler(bundler_version.dup)
75
- end
76
-
77
- def activate_bundler(bundler_version)
78
- if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
- bundler_version = "< 2"
80
- end
81
- gem_error = activation_error_handling do
82
- gem "bundler", bundler_version
83
- end
84
- return if gem_error.nil?
85
- require_error = activation_error_handling do
86
- require "bundler/version"
87
- end
88
- return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
- warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
- exit 42
91
- end
92
-
93
- def activation_error_handling
94
- yield
95
- nil
96
- rescue StandardError, LoadError => e
97
- e
98
- end
99
- end
100
-
101
- m.load_bundler!
102
-
103
- if m.invoked_as_script?
104
- load Gem.bin_path("bundler", "bundle")
105
- end
data/bin/byebug DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'byebug' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("byebug", "byebug")
data/bin/htmldiff DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'htmldiff' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'ldiff' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("diff-lcs", "ldiff")
data/bin/rake DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rake' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rake", "rake")
data/bin/rspec DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rspec' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rspec-core", "rspec")
@@ -1,25 +0,0 @@
1
- require_relative '../lib/nested_array.rb'
2
- require 'awesome_print'
3
-
4
- a = [
5
- {'id' => 1, 'parent_id' => nil, 'name' => 'category 1'},
6
- {'id' => 2, 'parent_id' => nil, 'name' => 'category 2'},
7
- {'id' => 3, 'parent_id' => 2, 'name' => 'category 3'},
8
- {'id' => 4, 'parent_id' => nil, 'name' => 'category 4'},
9
- {'id' => 5, 'parent_id' => 4, 'name' => 'category 5'},
10
- {'id' => 6, 'parent_id' => 5, 'name' => 'category 6'},
11
- {'id' => 7, 'parent_id' => nil, 'name' => 'category 7'},
12
- {'id' => 8, 'parent_id' => 7, 'name' => 'category 8'},
13
- {'id' => 9, 'parent_id' => 7, 'name' => 'category 9'},
14
- {'id' => 10, 'parent_id' => 9, 'name' => 'category 10'},
15
- {'id' => 11, 'parent_id' => 9, 'name' => 'category 11'}
16
- ]
17
-
18
- b = a.shuffle
19
-
20
- array = b.to_nested.nested_to_options
21
- print 'array: '.red; p array
22
-
23
- array.each do |v|
24
- puts v[0]
25
- end
data/test.old/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'activesupport'
4
- gem 'awesome_print'
5
- gem 'nested_array', path: '../'
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- nested_array (1.0.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- activesupport (6.0.2.1)
10
- concurrent-ruby (~> 1.0, >= 1.0.2)
11
- i18n (>= 0.7, < 2)
12
- minitest (~> 5.1)
13
- tzinfo (~> 1.1)
14
- zeitwerk (~> 2.2)
15
- awesome_print (1.8.0)
16
- concurrent-ruby (1.1.6)
17
- i18n (1.8.2)
18
- concurrent-ruby (~> 1.0)
19
- minitest (5.14.0)
20
- thread_safe (0.3.6)
21
- tzinfo (1.2.6)
22
- thread_safe (~> 0.1)
23
- zeitwerk (2.2.2)
24
-
25
- PLATFORMS
26
- ruby
27
-
28
- DEPENDENCIES
29
- activesupport
30
- awesome_print
31
- nested_array!
32
-
33
- BUNDLED WITH
34
- 2.0.1
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -eu
4
-
5
- cd "$(dirname "${0}")"
6
-
7
- cd ../..
8
-
9
- bundle install
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -eu
4
-
5
- cd "$(dirname "${0}")"
6
-
7
- cd ../..
8
-
9
- bundle exec ruby test.rb
data/test.old/test.rb DELETED
@@ -1,42 +0,0 @@
1
- require 'active_support/all'
2
- require 'awesome_print'
3
- require 'nested_array'
4
-
5
- puts 'Начато тестирование.'.blue
6
- puts "Версия руби: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
7
-
8
- def to_nested_1
9
- puts "Тестирование #{__method__}".blue
10
- a = [
11
- {'id' => 1, 'parent_id' => nil, 'name' => 'first'},
12
- {'id' => 2, 'parent_id' => 1, 'name' => 'second'},
13
- {'id' => 3, 'parent_id' => 1, 'name' => 'third'}
14
- ]
15
- a = NestedArray::Array.new a
16
- b = a.to_nested
17
- return false if b != [
18
- {'id' => 1, 'parent_id' => nil, 'name' => 'first', 'children' => [
19
- {'id' => 2, 'parent_id' => 1, 'name' => 'second'},
20
- {'id' => 3, 'parent_id' => 1, 'name' => 'third'}
21
- ]},
22
- ]
23
- b = a.to_nested add_level: true
24
- return false if b != [
25
- {'id' => 1, 'parent_id' => nil, 'name' => 'first', 'level' => 0, 'children' => [
26
- {'id' => 2, 'parent_id' => 1, 'name' => 'second', 'level' => 1},
27
- {'id' => 3, 'parent_id' => 1, 'name' => 'third', 'level' => 1}
28
- ]},
29
- ]
30
- return true
31
- end
32
-
33
-
34
-
35
-
36
- begin
37
- raise if !to_nested_1
38
- rescue => e
39
- puts 'Тестирование не пройдено.'.red
40
- exit 1
41
- end
42
- puts 'Тестирование пройдено.'.green