rom-files 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +9 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +112 -0
  6. data/.rubocop_todo.yml +7 -0
  7. data/.ruby-version +1 -0
  8. data/.simplecov +6 -0
  9. data/.travis.yml +24 -0
  10. data/.yardopts +6 -0
  11. data/CHANGELOG.md +10 -0
  12. data/Gemfile +25 -0
  13. data/Guardfile +48 -0
  14. data/LICENSE.md +21 -0
  15. data/README.md +44 -0
  16. data/Rakefile +37 -0
  17. data/Roadmap.taskpaper +44 -0
  18. data/bin/_guard-core +21 -0
  19. data/bin/console +7 -0
  20. data/bin/guard +21 -0
  21. data/bin/rake +21 -0
  22. data/bin/rspec +21 -0
  23. data/bin/yard +21 -0
  24. data/bin/yardoc +21 -0
  25. data/bin/yri +21 -0
  26. data/lib/dry/types/pathname.rb +25 -0
  27. data/lib/pathname/extensions.rb +32 -0
  28. data/lib/pathname/extensions/constants.rb +12 -0
  29. data/lib/pathname/extensions/explode.rb +27 -0
  30. data/lib/pathname/extensions/ext.rb +28 -0
  31. data/lib/pathname/extensions/partial.rb +30 -0
  32. data/lib/pathname/extensions/pathmap.rb +128 -0
  33. data/lib/rom-files.rb +3 -0
  34. data/lib/rom/files.rb +28 -0
  35. data/lib/rom/files/associations.rb +6 -0
  36. data/lib/rom/files/associations/many_to_many.rb +12 -0
  37. data/lib/rom/files/associations/many_to_one.rb +12 -0
  38. data/lib/rom/files/associations/one_to_many.rb +12 -0
  39. data/lib/rom/files/associations/one_to_one.rb +12 -0
  40. data/lib/rom/files/attribute.rb +21 -0
  41. data/lib/rom/files/commands/create.rb +18 -0
  42. data/lib/rom/files/commands/delete.rb +17 -0
  43. data/lib/rom/files/commands/update.rb +17 -0
  44. data/lib/rom/files/connection.rb +120 -0
  45. data/lib/rom/files/constants.rb +16 -0
  46. data/lib/rom/files/dataset.rb +89 -0
  47. data/lib/rom/files/dataset/filtering.rb +96 -0
  48. data/lib/rom/files/dataset/mime_type.rb +44 -0
  49. data/lib/rom/files/dataset/paths.rb +79 -0
  50. data/lib/rom/files/dataset/sorting.rb +27 -0
  51. data/lib/rom/files/extensions.rb +30 -0
  52. data/lib/rom/files/extensions/gem.rb +29 -0
  53. data/lib/rom/files/extensions/gem/relations/documentations.rb +18 -0
  54. data/lib/rom/files/extensions/gem/relations/executables.rb +20 -0
  55. data/lib/rom/files/extensions/gem/relations/implementations.rb +29 -0
  56. data/lib/rom/files/extensions/gem/relations/specifications.rb +29 -0
  57. data/lib/rom/files/extensions/markdown/attributes_inferrer.rb +20 -0
  58. data/lib/rom/files/extensions/markdown/types.rb +18 -0
  59. data/lib/rom/files/extensions/markup/attributes_inferrer.rb +32 -0
  60. data/lib/rom/files/extensions/ruby/attributes_inferrer.rb +21 -0
  61. data/lib/rom/files/extensions/ruby/types.rb +45 -0
  62. data/lib/rom/files/extensions/text/attributes_inferrer.rb +20 -0
  63. data/lib/rom/files/gateway.rb +63 -0
  64. data/lib/rom/files/plugins/configuration/gem.rb +30 -0
  65. data/lib/rom/files/plugins/relation/instrumentation.rb +28 -0
  66. data/lib/rom/files/plugins/schema/contents.rb +72 -0
  67. data/lib/rom/files/plugins/schema/mime.rb +59 -0
  68. data/lib/rom/files/plugins/schema/shebang.rb +79 -0
  69. data/lib/rom/files/plugins/schema/stat.rb +108 -0
  70. data/lib/rom/files/relation.rb +143 -0
  71. data/lib/rom/files/schema.rb +77 -0
  72. data/lib/rom/files/schema/attributes_inferrer.rb +79 -0
  73. data/lib/rom/files/schema/inferrer.rb +36 -0
  74. data/lib/rom/files/types.rb +37 -0
  75. data/lib/rom/files/version.rb +7 -0
  76. data/rom-files.gemspec +48 -0
  77. data/spec/integration/rom/files/gateway_spec.rb +28 -0
  78. data/spec/integration/rom/files/gem_spec.rb +98 -0
  79. data/spec/integration/rom/files/relations_spec.rb +63 -0
  80. data/spec/integration/rom/files/schema/inferrer_spec.rb +77 -0
  81. data/spec/lib/dry/types/pathname_spec.rb +50 -0
  82. data/spec/lib/pathname/extensions/explode_spec.rb +25 -0
  83. data/spec/lib/pathname/extensions/ext_spec.rb +33 -0
  84. data/spec/lib/pathname/extensions/partial_spec.rb +17 -0
  85. data/spec/lib/pathname/extensions/pathmap_spec.rb +147 -0
  86. data/spec/lib/rom/files/attribute_spec.rb +43 -0
  87. data/spec/lib/rom/files/connection_spec.rb +76 -0
  88. data/spec/lib/rom/files/dataset/inside_spec.rb +22 -0
  89. data/spec/lib/rom/files/dataset/mime_type_spec.rb +23 -0
  90. data/spec/lib/rom/files/dataset/recursive_question_mark_spec.rb +42 -0
  91. data/spec/lib/rom/files/dataset/recursive_spec.rb +29 -0
  92. data/spec/lib/rom/files/dataset/reject_append_spec.rb +68 -0
  93. data/spec/lib/rom/files/dataset/reject_spec.rb +26 -0
  94. data/spec/lib/rom/files/dataset/select_append_spec.rb +69 -0
  95. data/spec/lib/rom/files/dataset/select_spec.rb +38 -0
  96. data/spec/lib/rom/files/dataset/sort_spec.rb +22 -0
  97. data/spec/lib/rom/files/dataset_spec.rb +52 -0
  98. data/spec/lib/rom/files/extensions/text/attributes_inferrer_spec.rb +54 -0
  99. data/spec/lib/rom/files/gateway_spec.rb +39 -0
  100. data/spec/lib/rom/files/plugins/schema/contents_spec.rb +66 -0
  101. data/spec/lib/rom/files/plugins/schema/mime_spec.rb +66 -0
  102. data/spec/lib/rom/files/plugins/schema/stat_spec.rb +109 -0
  103. data/spec/lib/rom/files/relation/pluck_spec.rb +20 -0
  104. data/spec/lib/rom/files/relation/reject_spec.rb +22 -0
  105. data/spec/lib/rom/files/relation/select_spec.rb +35 -0
  106. data/spec/lib/rom/files/relation/sort_spec.rb +21 -0
  107. data/spec/lib/rom/files/relation/to_a_spec.rb +39 -0
  108. data/spec/lib/rom/files/relation_spec.rb +10 -0
  109. data/spec/lib/rom/files/schema/attributes_inferrer_spec.rb +45 -0
  110. data/spec/lib/rom/files/schema/inferrer_spec.rb +29 -0
  111. data/spec/lib/rom/files/schema_spec.rb +109 -0
  112. data/spec/lib/rom/files/types/mime_type_spec.rb +9 -0
  113. data/spec/lib/rom/files/types/path_spec.rb +10 -0
  114. data/spec/lib/rom/files/types_spec.rb +6 -0
  115. data/spec/shared/rom/files/files_setup.rb +19 -0
  116. data/spec/shared/rom/files/filesystem_setup.rb +10 -0
  117. data/spec/shared/rom/files/gateway_setup.rb +17 -0
  118. data/spec/shared/rom/files/media_dataset.rb +10 -0
  119. data/spec/shared/rom/files/media_files.rb +17 -0
  120. data/spec/shared/rom/files/media_relation.rb +30 -0
  121. data/spec/spec_helper.rb +10 -0
  122. metadata +421 -0
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/attribute'
4
+ require 'shared/rom/files/media_relation'
5
+
6
+ RSpec.describe ROM::Files::Attribute do
7
+ Types = ROM::Files::Types
8
+
9
+ subject(:attribute) { described_class.new(type.meta(name: name)) }
10
+ let(:type) { Types::String }
11
+ let(:name) { :attr_name }
12
+ let(:path) { Pathname(__FILE__) }
13
+
14
+ it { is_expected.to be_a described_class } # no-op
15
+
16
+ describe '#call' do
17
+ subject(:call) { attribute.method(:call) }
18
+
19
+ context 'with DATA' do
20
+ let(:type) { Types::String.meta(DATA: true) }
21
+
22
+ its([Pathname(__FILE__)]) { is_expected.to eq File.read(__FILE__) }
23
+ end
24
+
25
+ context 'with stat' do
26
+ let(:type) { Types::FileStat.meta(__stat__: true) }
27
+
28
+ its([Pathname(__FILE__)]) { is_expected.to eq File.stat(__FILE__) }
29
+ end
30
+
31
+ context 'with specific stat' do
32
+ let(:type) { Types::Int.meta(__stat__: :mode) }
33
+
34
+ its([Pathname(__FILE__)]) { is_expected.to eq 0o0100644 }
35
+ end
36
+
37
+ context 'with proc' do
38
+ let(:type) { Types::String.meta(__proc__: ->(path) { path.extname }) }
39
+
40
+ its([Pathname(__FILE__)]) { is_expected.to eq '.rb' }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/lint/spec'
4
+ require 'rom/files/connection'
5
+ require 'shared/rom/files/media_relation'
6
+
7
+ RSpec.describe ROM::Files::Connection do
8
+ include_context 'media relation'
9
+
10
+ subject(:connection) { described_class.new(uri) }
11
+
12
+ its(:path) { is_expected.to eq uri }
13
+
14
+ describe '#create_dataset' do
15
+ subject(:dataset) { connection.create_dataset(name_or_mime_type) }
16
+
17
+ xcontext '(path)' do
18
+ let(:name_or_mime_type) { :media }
19
+
20
+ it { is_expected.to be_a ROM::Files::Dataset }
21
+ its(:path) { is_expected.to eq uri.join(name_or_mime_type.to_s) }
22
+ its(:mime_type) { is_expected.to eq nil }
23
+ end
24
+
25
+ context '(mime_type)' do
26
+ let(:name_or_mime_type) { 'application/x-ruby' }
27
+
28
+ it { is_expected.to be_a ROM::Files::Dataset }
29
+ its(:path) { is_expected.to eq uri }
30
+ its(:mime_type) { is_expected.to eq name_or_mime_type }
31
+ end
32
+ end
33
+
34
+ describe '#key?' do
35
+ subject { connection.key?(name) }
36
+
37
+ context 'with existing path' do
38
+ let(:name) { :media }
39
+
40
+ it { is_expected.to eq true }
41
+ end
42
+
43
+ context 'with non-existing path' do
44
+ let(:name) { :not_real }
45
+
46
+ it { is_expected.to eq false }
47
+ end
48
+
49
+ context 'with registered MIME type' do
50
+ let(:name) { 'application/x-ruby' }
51
+
52
+ it { is_expected.to eq true }
53
+ end
54
+
55
+ context 'with unknown MIME type' do
56
+ let(:name) { 'application/x-files' }
57
+
58
+ it { is_expected.to eq false }
59
+ end
60
+ end
61
+
62
+ describe '#search' do
63
+ subject(:files) { connection.search(patterns, exclude_patterns: exclude_patterns, sorting: sorting, directories: directories) }
64
+ let(:patterns) { ['*'] }
65
+ let(:exclude_patterns) { [] }
66
+ let(:sorting) { nil }
67
+ let(:directories) { false }
68
+
69
+ it { is_expected.to be_a Array }
70
+
71
+ xcontext 'including everything'
72
+ xcontext 'excluding images'
73
+ xcontext 'sorting results'
74
+ xcontext 'including directories'
75
+ end
76
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#inside' do
7
+ include_context 'media dataset'
8
+
9
+ subject(:dataset) { described_class.new(uri.join(dir)) }
10
+
11
+ context '(dirname)' do
12
+ subject { dataset.inside('lib') }
13
+
14
+ its(:inside_paths) { is_expected.to eql [Pathname('lib')] }
15
+ end
16
+
17
+ context '(list, of, directories)' do
18
+ subject { dataset.inside('lib', 'spec') }
19
+
20
+ its(:inside_paths) { is_expected.to eql [Pathname('lib'), Pathname('spec')] }
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#mime' do
7
+ include_context 'media dataset'
8
+
9
+ its(:mime_type) { is_expected.to eq nil }
10
+
11
+ context '()' do
12
+ subject { dataset.mime }
13
+
14
+ its(:mime_type) { is_expected.to eq nil }
15
+ end
16
+
17
+ context '(method)' do
18
+ subject { dataset.mime('application/x-ruby') }
19
+
20
+ its(:mime_type) { is_expected.to eq 'application/x-ruby' }
21
+ its(:include_patterns) { is_expected.to eq %w[*.rb *.rbw] }
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#recursive?' do
7
+ include_context 'media dataset'
8
+
9
+ subject { dataset.recursive? }
10
+
11
+ it { is_expected.to be true }
12
+
13
+ context 'after #recursive' do
14
+ let(:dataset) { super().recursive }
15
+
16
+ it { is_expected.to be true }
17
+ end
18
+
19
+ context 'after #not_recursive' do
20
+ let(:dataset) { super().not_recursive }
21
+
22
+ it { is_expected.to be false }
23
+ end
24
+
25
+ context 'after manual recursion via #inside' do
26
+ let(:dataset) { super().not_recursive.inside('**') }
27
+
28
+ it { is_expected.to be true }
29
+ end
30
+
31
+ context 'after manual recursion via #select' do
32
+ let(:dataset) { super().select('**/*.md') }
33
+
34
+ it { is_expected.to be true }
35
+ end
36
+
37
+ context 'after manual recursion via #select without folder' do
38
+ let(:dataset) { super().select('**') }
39
+
40
+ it { is_expected.to be true }
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#recursive' do
7
+ include_context 'media dataset'
8
+
9
+ context '()' do
10
+ subject { dataset.recursive }
11
+
12
+ its(:search_recursive) { is_expected.to eql true }
13
+ its(:search_patterns) { is_expected.to eql [Pathname('**/*')] }
14
+ end
15
+
16
+ context 'with custom select' do
17
+ subject { dataset.select('*.txt').recursive }
18
+
19
+ its(:search_recursive) { is_expected.to eql true }
20
+ its(:search_patterns) { is_expected.to eql [Pathname('**/*.txt')] }
21
+ end
22
+
23
+ context 'with multiple select' do
24
+ subject { dataset.select('*.txt', '*.md').recursive }
25
+
26
+ its(:search_recursive) { is_expected.to eql true }
27
+ its(:search_patterns) { is_expected.to eql [Pathname('**/*.txt'), Pathname('**/*.md')] }
28
+ end
29
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#reject_append' do
7
+ include_context 'media dataset'
8
+
9
+ context 'with blank #exclude_patterns' do
10
+ context '(simple_pattern)' do
11
+ subject { dataset.reject_append('*.txt') }
12
+
13
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt] }
14
+ end
15
+
16
+ context '(multiple, patterns)' do
17
+ subject { dataset.reject_append('*.txt', '*.md') }
18
+
19
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt *.md] }
20
+ end
21
+
22
+ context '(glob_pattern)' do
23
+ subject { dataset.reject_append('*.{txt,md}') }
24
+
25
+ its(:exclude_patterns) { is_expected.to eq %w[*.{txt,md}] }
26
+ end
27
+
28
+ context '(ordered_glob_pattern)' do
29
+ subject { dataset.reject_append('*.{md,txt}') }
30
+
31
+ its(:exclude_patterns) { is_expected.to eq %w[*.{md,txt}] }
32
+ end
33
+ end
34
+
35
+ context 'after #reject' do
36
+ let(:dataset) { super().reject('*.txt') }
37
+
38
+ context '(duplicate_pattern)' do
39
+ subject { dataset.reject_append('*.txt') }
40
+
41
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt] }
42
+ end
43
+
44
+ context '(simple_pattern)' do
45
+ subject { dataset.reject_append('*.md') }
46
+
47
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt *.md] }
48
+ end
49
+
50
+ context '(multiple, duplicated, patterns)' do
51
+ subject { dataset.reject_append('*.txt', '*.md') }
52
+
53
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt *.md] }
54
+ end
55
+
56
+ context '(glob_pattern)' do
57
+ subject { dataset.reject_append('*.{txt,md}') }
58
+
59
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt *.{txt,md}] }
60
+ end
61
+
62
+ context '(ordered_glob_pattern)' do
63
+ subject { dataset.reject_append('*.{md,txt}') }
64
+
65
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt *.{md,txt}] }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#reject' do
7
+ include_context 'media dataset'
8
+
9
+ context 'dataset.reject(pattern)' do
10
+ subject { dataset.reject('*.txt') }
11
+
12
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt] }
13
+ end
14
+
15
+ context '(list, of, patterns)' do
16
+ subject { dataset.reject('*.txt', '*.md') }
17
+
18
+ its(:exclude_patterns) { is_expected.to eq %w[*.txt *.md] }
19
+ end
20
+
21
+ context '(glob_expression)' do
22
+ subject { dataset.reject('*.{txt,md}') }
23
+
24
+ its(:exclude_patterns) { is_expected.to eq %w[*.{txt,md}] }
25
+ end
26
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#select_append' do
7
+ include_context 'media dataset'
8
+
9
+ context 'with blank #include_patterns' do
10
+ let(:dataset) { super().select }
11
+
12
+ context '(simple_pattern)' do
13
+ subject { dataset.select_append('*.txt') }
14
+
15
+ its(:include_patterns) { is_expected.to eq %w[*.txt] }
16
+ end
17
+
18
+ context '(multiple, patterns)' do
19
+ subject { dataset.select_append('*.txt', '*.md') }
20
+
21
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.md] }
22
+ end
23
+
24
+ context '(glob_pattern)' do
25
+ subject { dataset.select_append('*.{txt,md}') }
26
+
27
+ its(:include_patterns) { is_expected.to eq %w[*.{txt,md}] }
28
+ end
29
+
30
+ context '(ordered_glob_pattern)' do
31
+ subject { dataset.select_append('*.{md,txt}') }
32
+
33
+ its(:include_patterns) { is_expected.to eq %w[*.{md,txt}] }
34
+ end
35
+ end
36
+ context 'after #select' do
37
+ let(:dataset) { super().select('*.txt') }
38
+
39
+ context '(duplicate_pattern)' do
40
+ subject { dataset.select_append('*.txt') }
41
+
42
+ its(:include_patterns) { is_expected.to eq %w[*.txt] }
43
+ end
44
+
45
+ context '(simple_pattern)' do
46
+ subject { dataset.select_append('*.md') }
47
+
48
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.md] }
49
+ end
50
+
51
+ context '(multiple, duplicated, patterns)' do
52
+ subject { dataset.select_append('*.txt', '*.md') }
53
+
54
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.md] }
55
+ end
56
+
57
+ context '(glob_pattern)' do
58
+ subject { dataset.select_append('*.{txt,md}') }
59
+
60
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.{txt,md}] }
61
+ end
62
+
63
+ context '(ordered_glob_pattern)' do
64
+ subject { dataset.select_append('*.{md,txt}') }
65
+
66
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.{md,txt}] }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/files/dataset'
4
+ require 'shared/rom/files/media_dataset'
5
+
6
+ RSpec.describe ROM::Files::Dataset, '#select' do
7
+ include_context 'media dataset'
8
+
9
+ context '(simple_pattern)' do
10
+ subject { dataset.select('*.txt') }
11
+
12
+ its(:include_patterns) { is_expected.to eq %w[*.txt] }
13
+ end
14
+
15
+ context '(multiple, patterns)' do
16
+ subject { dataset.select('*.txt', '*.md') }
17
+
18
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.md] }
19
+ end
20
+
21
+ context '(multiple, duplicated patterns)' do
22
+ subject { dataset.select('*.txt', '*.md', '*.txt') }
23
+
24
+ its(:include_patterns) { is_expected.to eq %w[*.txt *.md] }
25
+ end
26
+
27
+ context '(glob_pattern)' do
28
+ subject { dataset.select('*.{txt,md}') }
29
+
30
+ its(:include_patterns) { is_expected.to eq %w[*.{txt,md}] }
31
+ end
32
+
33
+ context '(ordered_glob_pattern)' do
34
+ subject { dataset.select('*.{md,txt}') }
35
+
36
+ its(:include_patterns) { is_expected.to eq %w[*.{md,txt}] }
37
+ end
38
+ end