rom-files 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +112 -0
- data/.rubocop_todo.yml +7 -0
- data/.ruby-version +1 -0
- data/.simplecov +6 -0
- data/.travis.yml +24 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +25 -0
- data/Guardfile +48 -0
- data/LICENSE.md +21 -0
- data/README.md +44 -0
- data/Rakefile +37 -0
- data/Roadmap.taskpaper +44 -0
- data/bin/_guard-core +21 -0
- data/bin/console +7 -0
- data/bin/guard +21 -0
- data/bin/rake +21 -0
- data/bin/rspec +21 -0
- data/bin/yard +21 -0
- data/bin/yardoc +21 -0
- data/bin/yri +21 -0
- data/lib/dry/types/pathname.rb +25 -0
- data/lib/pathname/extensions.rb +32 -0
- data/lib/pathname/extensions/constants.rb +12 -0
- data/lib/pathname/extensions/explode.rb +27 -0
- data/lib/pathname/extensions/ext.rb +28 -0
- data/lib/pathname/extensions/partial.rb +30 -0
- data/lib/pathname/extensions/pathmap.rb +128 -0
- data/lib/rom-files.rb +3 -0
- data/lib/rom/files.rb +28 -0
- data/lib/rom/files/associations.rb +6 -0
- data/lib/rom/files/associations/many_to_many.rb +12 -0
- data/lib/rom/files/associations/many_to_one.rb +12 -0
- data/lib/rom/files/associations/one_to_many.rb +12 -0
- data/lib/rom/files/associations/one_to_one.rb +12 -0
- data/lib/rom/files/attribute.rb +21 -0
- data/lib/rom/files/commands/create.rb +18 -0
- data/lib/rom/files/commands/delete.rb +17 -0
- data/lib/rom/files/commands/update.rb +17 -0
- data/lib/rom/files/connection.rb +120 -0
- data/lib/rom/files/constants.rb +16 -0
- data/lib/rom/files/dataset.rb +89 -0
- data/lib/rom/files/dataset/filtering.rb +96 -0
- data/lib/rom/files/dataset/mime_type.rb +44 -0
- data/lib/rom/files/dataset/paths.rb +79 -0
- data/lib/rom/files/dataset/sorting.rb +27 -0
- data/lib/rom/files/extensions.rb +30 -0
- data/lib/rom/files/extensions/gem.rb +29 -0
- data/lib/rom/files/extensions/gem/relations/documentations.rb +18 -0
- data/lib/rom/files/extensions/gem/relations/executables.rb +20 -0
- data/lib/rom/files/extensions/gem/relations/implementations.rb +29 -0
- data/lib/rom/files/extensions/gem/relations/specifications.rb +29 -0
- data/lib/rom/files/extensions/markdown/attributes_inferrer.rb +20 -0
- data/lib/rom/files/extensions/markdown/types.rb +18 -0
- data/lib/rom/files/extensions/markup/attributes_inferrer.rb +32 -0
- data/lib/rom/files/extensions/ruby/attributes_inferrer.rb +21 -0
- data/lib/rom/files/extensions/ruby/types.rb +45 -0
- data/lib/rom/files/extensions/text/attributes_inferrer.rb +20 -0
- data/lib/rom/files/gateway.rb +63 -0
- data/lib/rom/files/plugins/configuration/gem.rb +30 -0
- data/lib/rom/files/plugins/relation/instrumentation.rb +28 -0
- data/lib/rom/files/plugins/schema/contents.rb +72 -0
- data/lib/rom/files/plugins/schema/mime.rb +59 -0
- data/lib/rom/files/plugins/schema/shebang.rb +79 -0
- data/lib/rom/files/plugins/schema/stat.rb +108 -0
- data/lib/rom/files/relation.rb +143 -0
- data/lib/rom/files/schema.rb +77 -0
- data/lib/rom/files/schema/attributes_inferrer.rb +79 -0
- data/lib/rom/files/schema/inferrer.rb +36 -0
- data/lib/rom/files/types.rb +37 -0
- data/lib/rom/files/version.rb +7 -0
- data/rom-files.gemspec +48 -0
- data/spec/integration/rom/files/gateway_spec.rb +28 -0
- data/spec/integration/rom/files/gem_spec.rb +98 -0
- data/spec/integration/rom/files/relations_spec.rb +63 -0
- data/spec/integration/rom/files/schema/inferrer_spec.rb +77 -0
- data/spec/lib/dry/types/pathname_spec.rb +50 -0
- data/spec/lib/pathname/extensions/explode_spec.rb +25 -0
- data/spec/lib/pathname/extensions/ext_spec.rb +33 -0
- data/spec/lib/pathname/extensions/partial_spec.rb +17 -0
- data/spec/lib/pathname/extensions/pathmap_spec.rb +147 -0
- data/spec/lib/rom/files/attribute_spec.rb +43 -0
- data/spec/lib/rom/files/connection_spec.rb +76 -0
- data/spec/lib/rom/files/dataset/inside_spec.rb +22 -0
- data/spec/lib/rom/files/dataset/mime_type_spec.rb +23 -0
- data/spec/lib/rom/files/dataset/recursive_question_mark_spec.rb +42 -0
- data/spec/lib/rom/files/dataset/recursive_spec.rb +29 -0
- data/spec/lib/rom/files/dataset/reject_append_spec.rb +68 -0
- data/spec/lib/rom/files/dataset/reject_spec.rb +26 -0
- data/spec/lib/rom/files/dataset/select_append_spec.rb +69 -0
- data/spec/lib/rom/files/dataset/select_spec.rb +38 -0
- data/spec/lib/rom/files/dataset/sort_spec.rb +22 -0
- data/spec/lib/rom/files/dataset_spec.rb +52 -0
- data/spec/lib/rom/files/extensions/text/attributes_inferrer_spec.rb +54 -0
- data/spec/lib/rom/files/gateway_spec.rb +39 -0
- data/spec/lib/rom/files/plugins/schema/contents_spec.rb +66 -0
- data/spec/lib/rom/files/plugins/schema/mime_spec.rb +66 -0
- data/spec/lib/rom/files/plugins/schema/stat_spec.rb +109 -0
- data/spec/lib/rom/files/relation/pluck_spec.rb +20 -0
- data/spec/lib/rom/files/relation/reject_spec.rb +22 -0
- data/spec/lib/rom/files/relation/select_spec.rb +35 -0
- data/spec/lib/rom/files/relation/sort_spec.rb +21 -0
- data/spec/lib/rom/files/relation/to_a_spec.rb +39 -0
- data/spec/lib/rom/files/relation_spec.rb +10 -0
- data/spec/lib/rom/files/schema/attributes_inferrer_spec.rb +45 -0
- data/spec/lib/rom/files/schema/inferrer_spec.rb +29 -0
- data/spec/lib/rom/files/schema_spec.rb +109 -0
- data/spec/lib/rom/files/types/mime_type_spec.rb +9 -0
- data/spec/lib/rom/files/types/path_spec.rb +10 -0
- data/spec/lib/rom/files/types_spec.rb +6 -0
- data/spec/shared/rom/files/files_setup.rb +19 -0
- data/spec/shared/rom/files/filesystem_setup.rb +10 -0
- data/spec/shared/rom/files/gateway_setup.rb +17 -0
- data/spec/shared/rom/files/media_dataset.rb +10 -0
- data/spec/shared/rom/files/media_files.rb +17 -0
- data/spec/shared/rom/files/media_relation.rb +30 -0
- data/spec/spec_helper.rb +10 -0
- metadata +421 -0
@@ -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, '#sort' do
|
7
|
+
include_context 'media dataset'
|
8
|
+
|
9
|
+
its(:sorting) { is_expected.to eq nil }
|
10
|
+
|
11
|
+
context '()' do
|
12
|
+
subject { dataset.sort }
|
13
|
+
|
14
|
+
its(:sorting) { is_expected.to eq :to_s }
|
15
|
+
end
|
16
|
+
|
17
|
+
context '(method)' do
|
18
|
+
subject { dataset.sort(:basename) }
|
19
|
+
|
20
|
+
its(:sorting) { is_expected.to eq :basename }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rom/files/dataset'
|
4
|
+
require 'rom/lint/spec'
|
5
|
+
require 'shared/rom/files/media_files'
|
6
|
+
|
7
|
+
RSpec.describe ROM::Files::Dataset do
|
8
|
+
include_context 'media files'
|
9
|
+
|
10
|
+
subject(:dataset) { connection.create_dataset(dir) }
|
11
|
+
let(:connection) { ROM::Files::Connection.new(uri) }
|
12
|
+
|
13
|
+
it_behaves_like "a rom enumerable dataset"
|
14
|
+
|
15
|
+
its(:path) { is_expected.to eq uri }
|
16
|
+
its(:mime_type) { is_expected.to eq nil }
|
17
|
+
its(:inside_paths) { is_expected.to eq [Pathname(dir)] }
|
18
|
+
its(:include_patterns) { is_expected.to eq %w[*] }
|
19
|
+
its(:exclude_patterns) { is_expected.to eq [] }
|
20
|
+
its(:sorting) { is_expected.to eq nil }
|
21
|
+
its(:row_proc) { is_expected.to be_a Proc }
|
22
|
+
its(:count) { is_expected.to eq 3 }
|
23
|
+
its(:each) { is_expected.to be_a Enumerator }
|
24
|
+
|
25
|
+
describe '#with' do
|
26
|
+
subject(:new_dataset) { dataset.with(options) }
|
27
|
+
let(:options) { {} }
|
28
|
+
|
29
|
+
context '(path:)' do
|
30
|
+
let(:options) { Hash[path: Pathname.pwd] }
|
31
|
+
its(:path) { is_expected.to eq Pathname.pwd }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#at' do
|
36
|
+
subject(:new_dataset) { dataset.at('~') }
|
37
|
+
|
38
|
+
its(:path) { is_expected.to eq Pathname('~') }
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#up' do
|
42
|
+
subject(:new_dataset) { dataset.up }
|
43
|
+
|
44
|
+
its(:path) { is_expected.to eq uri.join('..') }
|
45
|
+
end
|
46
|
+
|
47
|
+
context '#dig' do
|
48
|
+
subject(:new_dataset) { dataset.up.dig(dir) }
|
49
|
+
|
50
|
+
its(:path) { is_expected.to eq uri.join('../media') }
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rom/files/extensions/text/attributes_inferrer'
|
4
|
+
require 'shared/rom/files/media_relation'
|
5
|
+
|
6
|
+
RSpec.describe ROM::Files::Extensions::Text::AttributesInferrer do
|
7
|
+
include_context 'media files'
|
8
|
+
|
9
|
+
subject(:inferrer) { described_class.new(attr_class: attr_class) }
|
10
|
+
let(:attr_class) { ROM::Files::Attribute }
|
11
|
+
|
12
|
+
its(:attr_class) { is_expected.to eq attr_class }
|
13
|
+
|
14
|
+
describe '#call' do
|
15
|
+
subject(:result) { inferrer.(schema, gateway) }
|
16
|
+
let(:relation_name) { ROM::Relation::Name.new(:text, 'text/plain') }
|
17
|
+
let(:schema) { ROM::Files::Schema.new(relation_name) }
|
18
|
+
|
19
|
+
it { is_expected.to be_a Array }
|
20
|
+
its(:size) { is_expected.to eq 2 }
|
21
|
+
|
22
|
+
describe 'inferred' do
|
23
|
+
subject(:inferred) { result.first }
|
24
|
+
|
25
|
+
it { is_expected.to be_a Array }
|
26
|
+
its(:size) { is_expected.to eq 2 }
|
27
|
+
|
28
|
+
describe '__FILE__' do
|
29
|
+
subject(:attribute) { inferred.first }
|
30
|
+
|
31
|
+
it { is_expected.to be_a attr_class }
|
32
|
+
its(:name) { is_expected.to eq ROM::Files::ID }
|
33
|
+
its(:primitive) { is_expected.to eq Pathname }
|
34
|
+
its(:primary_key?) { is_expected.to be true }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'DATA' do
|
38
|
+
subject(:attribute) { inferred[1] }
|
39
|
+
|
40
|
+
it { is_expected.to be_a attr_class }
|
41
|
+
its(:name) { is_expected.to eq :DATA }
|
42
|
+
its(:primitive) { is_expected.to eq String }
|
43
|
+
its(:primary_key?) { is_expected.to be false }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'missing' do
|
48
|
+
subject(:missing) { result.last }
|
49
|
+
|
50
|
+
it { is_expected.to be_a Array }
|
51
|
+
its(:size) { is_expected.to eq 0 }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rom/lint/spec'
|
4
|
+
require 'rom/files/gateway'
|
5
|
+
require 'shared/rom/files/media_relation'
|
6
|
+
|
7
|
+
RSpec.describe ROM::Files::Gateway do
|
8
|
+
include_context 'media relation'
|
9
|
+
|
10
|
+
subject(:gateway_instance) { ROM::Gateway.setup(identifier, uri) }
|
11
|
+
let(:gateway) { described_class }
|
12
|
+
let(:identifier) { :files }
|
13
|
+
|
14
|
+
it_behaves_like "a rom gateway"
|
15
|
+
|
16
|
+
describe '#use_logger' do
|
17
|
+
let(:logger) { Logger.new(STDOUT) }
|
18
|
+
it 'sets logger' do
|
19
|
+
gateway_instance.use_logger(logger)
|
20
|
+
expect(gateway_instance.logger).to eq logger
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#dataset?' do
|
25
|
+
subject { gateway_instance.dataset?(relation) }
|
26
|
+
|
27
|
+
context 'with existing relation' do
|
28
|
+
let(:relation) { :media }
|
29
|
+
|
30
|
+
it { is_expected.to be true }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with non-existing relation' do
|
34
|
+
let(:relation) { :not_here }
|
35
|
+
|
36
|
+
it { is_expected.to be false }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared/rom/files/media_relation'
|
4
|
+
|
5
|
+
RSpec.describe ROM::Files::Plugins::Schema::Contents do
|
6
|
+
include_context 'media relation'
|
7
|
+
|
8
|
+
subject(:schema) { schema_dsl.() }
|
9
|
+
let(:relation) { ROM::Relation::Name[:media] }
|
10
|
+
let(:schema_dsl) do
|
11
|
+
ROM::Schema::DSL.new(relation, adapter: :files)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param name [Symbol]
|
15
|
+
# @param type [Dry::Types::Definition]
|
16
|
+
# @return [ROM::Attribute]
|
17
|
+
def build_attribute(name = :DATA, type: ROM::Types::String)
|
18
|
+
ROM::Attribute.new(
|
19
|
+
type.meta(name: name, source: relation, DATA: true)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.apply' do
|
24
|
+
let(:type) { ROM::Types::Date }
|
25
|
+
|
26
|
+
context 'use :contents' do
|
27
|
+
before { schema_dsl.use :contents }
|
28
|
+
its([:DATA]) { is_expected.to eql build_attribute }
|
29
|
+
|
30
|
+
context 'contents(name)' do
|
31
|
+
before { schema_dsl.contents :custom }
|
32
|
+
its([:custom]) { is_expected.to eql build_attribute(:custom) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'contents(name, type)' do
|
36
|
+
before { schema_dsl.contents :custom, type }
|
37
|
+
its([:custom]) { is_expected.to eql build_attribute(:custom, type: type) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'contents(name, type:)' do
|
41
|
+
before { schema_dsl.contents :custom, type: type }
|
42
|
+
its([:custom]) { is_expected.to eql build_attribute(:custom, type: type) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'contents(type:)' do
|
46
|
+
before { schema_dsl.contents type: type }
|
47
|
+
its([:DATA]) { is_expected.to eql build_attribute(type: type) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'use :contents, name:' do
|
52
|
+
before { schema_dsl.use :contents, name: :contents }
|
53
|
+
its([:contents]) { is_expected.to eql build_attribute :contents }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'use :contents, type:' do
|
57
|
+
before { schema_dsl.use :contents, type: type }
|
58
|
+
its([:DATA]) { is_expected.to eql build_attribute type: type }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'use :contents, name:, type:' do
|
62
|
+
before { schema_dsl.use :contents, name: :contents, type: type }
|
63
|
+
its([:contents]) { is_expected.to eql build_attribute :contents, type: type }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared/rom/files/media_relation'
|
4
|
+
|
5
|
+
RSpec.describe ROM::Files::Plugins::Schema::Mime do
|
6
|
+
include_context 'media relation'
|
7
|
+
|
8
|
+
subject(:schema) { schema_dsl.() }
|
9
|
+
let(:relation) { ROM::Relation::Name[:media] }
|
10
|
+
let(:schema_dsl) do
|
11
|
+
ROM::Schema::DSL.new(relation, adapter: :files)
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param name [Symbol]
|
15
|
+
# @param type [Dry::Types::Definition]
|
16
|
+
# @return [ROM::Attribute]
|
17
|
+
def build_attribute(name = :mime_type, type: ROM::Files::Types::MimeType.optional)
|
18
|
+
ROM::Attribute.new(
|
19
|
+
type.meta(name: name, source: relation, __proc__: described_class::PROC)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.apply' do
|
24
|
+
let(:type) { ROM::Types::Date }
|
25
|
+
|
26
|
+
context 'use :mime' do
|
27
|
+
before { schema_dsl.use :mime }
|
28
|
+
its([:mime_type]) { is_expected.to eql build_attribute }
|
29
|
+
|
30
|
+
context 'mime(name)' do
|
31
|
+
before { schema_dsl.mime :custom }
|
32
|
+
its([:custom]) { is_expected.to eql build_attribute(:custom) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'mime(name, type)' do
|
36
|
+
before { schema_dsl.mime :custom, type }
|
37
|
+
its([:custom]) { is_expected.to eql build_attribute(:custom, type: type) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'mime(name, type:)' do
|
41
|
+
before { schema_dsl.mime :custom, type: type }
|
42
|
+
its([:custom]) { is_expected.to eql build_attribute(:custom, type: type) }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'mime(type:)' do
|
46
|
+
before { schema_dsl.mime type: type }
|
47
|
+
its([:mime_type]) { is_expected.to eql build_attribute(type: type) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'use :mime, name:' do
|
52
|
+
before { schema_dsl.use :mime, name: :mime }
|
53
|
+
its([:mime]) { is_expected.to eql build_attribute :mime }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'use :mime, type:' do
|
57
|
+
before { schema_dsl.use :mime, type: type }
|
58
|
+
its([:mime_type]) { is_expected.to eql build_attribute type: type }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'use :mime, name:, type:' do
|
62
|
+
before { schema_dsl.use :mime, name: :mime, type: type }
|
63
|
+
its([:mime]) { is_expected.to eql build_attribute :mime, type: type }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shared/rom/files/media_relation'
|
4
|
+
|
5
|
+
RSpec.describe ROM::Files::Plugins::Schema::Stat do
|
6
|
+
FIELD = ROM::Files::Plugins::Schema::Stat::NAME
|
7
|
+
|
8
|
+
include_context 'media relation'
|
9
|
+
|
10
|
+
subject(:schema) { schema_dsl.() }
|
11
|
+
let(:relation_name) { ROM::Relation::Name[:media] }
|
12
|
+
let(:schema_dsl) do
|
13
|
+
ROM::Schema::DSL.new(relation_name, adapter: :files)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param name [Symbol]
|
17
|
+
# @param type [Dry::Types::Definition]
|
18
|
+
# @param stat [Symbol]
|
19
|
+
# @return [ROM::Attribute]
|
20
|
+
def build_attribute(name = FIELD,
|
21
|
+
type: ROM::Files::Types::FileStat,
|
22
|
+
stat: (name == FIELD) || name)
|
23
|
+
ROM::Attribute.new(
|
24
|
+
type.meta(name: name, source: relation_name, __stat__: stat)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.apply' do
|
29
|
+
context 'use :stat' do
|
30
|
+
before { schema_dsl.use :stat }
|
31
|
+
|
32
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
33
|
+
|
34
|
+
context 'stat :stat' do
|
35
|
+
before { schema_dsl.stat :stat }
|
36
|
+
|
37
|
+
its([:stat]) { is_expected.to eql build_attribute(:stat) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'stat stats:' do
|
41
|
+
before { schema_dsl.stat stats: %i[atime] }
|
42
|
+
|
43
|
+
its('to_h.keys') { is_expected.to eql %i[stat atime] }
|
44
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
45
|
+
its([:atime]) { is_expected.to eql build_attribute(:atime, type: ROM::Files::Types::Time) }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'stat false, stats:' do
|
49
|
+
before { schema_dsl.stat false, stats: %i[atime] }
|
50
|
+
|
51
|
+
its('to_h.keys') { is_expected.to eql %i[atime] }
|
52
|
+
its([:atime]) { is_expected.to eql build_attribute(:atime, type: ROM::Files::Types::Time) }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'stat stats: [aliased]' do
|
56
|
+
before { schema_dsl.stat stats: %i[created_at] }
|
57
|
+
|
58
|
+
its('to_h.keys') { is_expected.to eql %i[stat created_at] }
|
59
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
60
|
+
its([:created_at]) { is_expected.to eql build_attribute(:created_at, type: ROM::Files::Types::Time, stat: :birthtime) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'stat aliases:' do
|
64
|
+
before { schema_dsl.stat aliases: { modified_at: :mtime } }
|
65
|
+
|
66
|
+
its('to_h.keys') { is_expected.to eql %i[stat modified_at] }
|
67
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
68
|
+
its([:modified_at]) { is_expected.to eql build_attribute(:modified_at, type: ROM::Files::Types::Time, stat: :mtime) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'use :stat, name:' do
|
73
|
+
before { schema_dsl.use :stat, name: :stat }
|
74
|
+
|
75
|
+
its([:stat]) { is_expected.to eql build_attribute(:stat) }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'use :stat, stats:' do
|
79
|
+
before { schema_dsl.use :stat, stats: %i[atime] }
|
80
|
+
|
81
|
+
its('to_h.keys') { is_expected.to eql %i[stat atime] }
|
82
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
83
|
+
its([:atime]) { is_expected.to eql build_attribute(:atime, type: ROM::Files::Types::Time) }
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'use :stat, name: false, stats:' do
|
87
|
+
before { schema_dsl.use :stat, name: false, stats: %i[atime] }
|
88
|
+
|
89
|
+
its('to_h.keys') { is_expected.to eql %i[atime] }
|
90
|
+
its([:atime]) { is_expected.to eql build_attribute(:atime, type: ROM::Files::Types::Time) }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'use :stat, stats: [aliased]' do
|
94
|
+
before { schema_dsl.use :stat, stats: %i[created_at] }
|
95
|
+
|
96
|
+
its('to_h.keys') { is_expected.to eql %i[stat created_at] }
|
97
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
98
|
+
its([:created_at]) { is_expected.to eql build_attribute(:created_at, type: ROM::Files::Types::Time, stat: :birthtime) }
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'use :stat, aliases:' do
|
102
|
+
before { schema_dsl.use :stat, aliases: { modified_at: :mtime } }
|
103
|
+
|
104
|
+
its('to_h.keys') { is_expected.to eql %i[stat modified_at] }
|
105
|
+
its([:stat]) { is_expected.to eql build_attribute }
|
106
|
+
its([:modified_at]) { is_expected.to eql build_attribute(:modified_at, type: ROM::Files::Types::Time, stat: :mtime) }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rom/files/relation'
|
4
|
+
require 'shared/rom/files/media_relation'
|
5
|
+
|
6
|
+
RSpec.describe ROM::Files::Relation, '#pluck' do
|
7
|
+
include_context 'media relation'
|
8
|
+
|
9
|
+
context 'with method name' do
|
10
|
+
subject { relation.pluck(:basename) }
|
11
|
+
|
12
|
+
it { is_expected.to eql([Pathname('some_image.png'), Pathname('some_file.txt'), Pathname('some_markdown.md')]) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with block' do
|
16
|
+
subject { relation.pluck { |path| path.basename.to_s } }
|
17
|
+
|
18
|
+
it { is_expected.to eql %w[some_image.png some_file.txt some_markdown.md] }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rom/files/relation'
|
4
|
+
require 'shared/rom/files/media_relation'
|
5
|
+
|
6
|
+
RSpec.describe ROM::Files::Relation, '#reject' do
|
7
|
+
include_context 'media relation'
|
8
|
+
|
9
|
+
subject(:names) { relation.pluck(:basename) }
|
10
|
+
|
11
|
+
context '(list, of, patterns)' do
|
12
|
+
let(:relation) { super().reject('*.txt', '*.md') }
|
13
|
+
|
14
|
+
it { is_expected.to eql [P('some_image.png')] }
|
15
|
+
end
|
16
|
+
|
17
|
+
context '(glob_expression)' do
|
18
|
+
let(:relation) { super().reject('*.{txt,md}') }
|
19
|
+
|
20
|
+
it { is_expected.to eql [P('some_image.png')] }
|
21
|
+
end
|
22
|
+
end
|