rom-filesystem 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07e33aa71201427c543df2bb38df3fa50d685592
4
+ data.tar.gz: b6fbf5bf3f40f2118bddff64e5479425011f91f1
5
+ SHA512:
6
+ metadata.gz: e8988020d9c982751865363369b52bc324d7a5be2e97aec4c70f04e8cfe730c9114cb66dcc6b6209358e36394b9e7e2d4597edbb496a59974a2949bff4eeb342
7
+ data.tar.gz: 5df3ecc124baf1cb699aa1817d0d16bc783f3e4b006199b4ac79dac02152af71246961d8acea348dbad41f4e8c71f5801994c1ec8b2517b9175f92b2619783a5
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,74 @@
1
+ # Generated by `rubocop --auto-gen-config`
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+ # Exclude temporary files
5
+ AllCops:
6
+ Exclude:
7
+ - tmp/**/*
8
+
9
+ # It’s quite readable when we know what we are doing
10
+ Lint/AssignmentInCondition:
11
+ Enabled: false
12
+
13
+ # No need to handle LoadError in Rakefile
14
+ Lint/HandleExceptions:
15
+ Exclude:
16
+ - Rakefile
17
+
18
+ # gemspec is a special snowflake
19
+ Metrics/LineLength:
20
+ Exclude:
21
+ - rom.gemspec
22
+
23
+ # The enforced style doesn’t match Vim’s defaults
24
+ Style/AlignParameters:
25
+ Enabled: false
26
+
27
+ # UTF-8 is perfectly fine in comments
28
+ Style/AsciiComments:
29
+ Enabled: false
30
+
31
+ # Allow using braces for value-returning blocks
32
+ Style/BlockDelimiters:
33
+ Enabled: false
34
+
35
+ # Documentation checked by Inch CI
36
+ Style/Documentation:
37
+ Enabled: false
38
+
39
+ # Early returns have their vices
40
+ Style/GuardClause:
41
+ Enabled: false
42
+
43
+ # Need to be skipped for >-> usage
44
+ Style/Lambda:
45
+ Enabled: false
46
+
47
+ # Multiline block chains are ok
48
+ Style/MultilineBlockChain:
49
+ Enabled: false
50
+
51
+ # Result::Success and Result::Failure use > for callbacks
52
+ Style/OpMethod:
53
+ Exclude:
54
+ - lib/rom/command_registry.rb
55
+
56
+ # Don’t introduce semantic fail/raise distinction
57
+ Style/SignalException:
58
+ EnforcedStyle: only_raise
59
+
60
+ # Need to be skipped for >-> usage
61
+ Style/SpaceAroundOperators:
62
+ Enabled: false
63
+
64
+ # Accept both single and double quotes
65
+ Style/StringLiterals:
66
+ Enabled: false
67
+
68
+ # Allow def self.foo; @foo; end
69
+ Style/TrivialAccessors:
70
+ Enabled: false
71
+
72
+ # Allow rom-sql
73
+ Style/FileName:
74
+ Enabled: false
@@ -0,0 +1,21 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-09-26 17:45:40 +0200 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ Metrics/AbcSize:
11
+ Max: 23
12
+
13
+ # Offense count: 17
14
+ # Configuration parameters: AllowURI, URISchemes.
15
+ Metrics/LineLength:
16
+ Max: 118
17
+
18
+ # Offense count: 5
19
+ # Configuration parameters: CountComments.
20
+ Metrics/MethodLength:
21
+ Max: 17
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ bundler_args: --without yard guard benchmarks tools
5
+ script: "bundle exec rake ci"
6
+ rvm:
7
+ - 2.0
8
+ - 2.1
9
+ - 2.2
10
+ - 2.3.0
11
+ - rbx-2
12
+ - jruby-9000
13
+ - jruby-head
14
+ - ruby-head
15
+ env:
16
+ global:
17
+ - CODECLIMATE_REPO_TOKEN=4bc2ab1a7aa4cefb2d9794f3f13941a479c42884d0afea032a841ed0fbebfb44
18
+ - JRUBY_OPTS='--dev -J-Xmx1024M'
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: jruby-9000
22
+ - rvm: ruby-head
23
+ - rvm: jruby-head
@@ -0,0 +1,3 @@
1
+ ## v0.1.0 2016-02-06
2
+
3
+ First release. Allows to retrieve file data from relations (directories).
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec', '~> 3.1'
7
+ gem 'codeclimate-test-reporter', require: false
8
+ gem 'inflecto'
9
+ end
10
+
11
+ group :tools do
12
+ gem 'guard'
13
+ gem 'guard-rspec'
14
+ gem 'guard-rubocop'
15
+ gem 'rubocop', '~> 0.28'
16
+ end
@@ -0,0 +1,24 @@
1
+ group :red_green_refactor, halt_on_fail: true do
2
+ guard :rspec, cmd: "rspec", all_on_start: true do
3
+ # run all specs if Gemfile.lock is modified
4
+ watch('Gemfile.lock') { 'spec' }
5
+
6
+ # run all specs if any library code is modified
7
+ watch(%r{\Alib/.+\.rb\z}) { 'spec' }
8
+
9
+ # run all specs if supporting files are modified
10
+ watch('spec/spec_helper.rb') { 'spec' }
11
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
12
+
13
+ # run a spec if it is modified
14
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
15
+
16
+ notification :tmux, display_message: true if ENV.key?('TMUX')
17
+ end
18
+
19
+ guard :rubocop do
20
+ # run rubocop on modified file
21
+ watch(%r{\Alib/.+\.rb\z})
22
+ watch(%r{\Aspec/.+\.rb\z})
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Héctor Ramón
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ [gem]: https://rubygems.org/gems/rom-filesystem
2
+ [travis]: https://travis-ci.org/hecrj/rom-filesystem
3
+ [gemnasium]: https://gemnasium.com/hecrj/rom-filesystem
4
+ [codeclimate]: https://codeclimate.com/github/hecrj/rom-filesystem
5
+ [inchpages]: http://inch-ci.org/github/hecrj/rom-filesystem
6
+
7
+ # ROM::Filesystem
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/rom-filesystem.svg)][gem]
10
+ [![Build Status](https://travis-ci.org/hecrj/rom-filesystem.svg?branch=master)][travis]
11
+ [![Dependency Status](https://gemnasium.com/hecrj/rom-filesystem.png)][gemnasium]
12
+ [![Code Climate](https://codeclimate.com/github/hecrj/rom-filesystem/badges/gpa.svg)][codeclimate]
13
+ [![Test Coverage](https://codeclimate.com/github/hecrj/rom-filesystem/badges/coverage.svg)][codeclimate]
14
+ [![Inline docs](http://inch-ci.org/github/hecrj/rom-filesystem.svg?branch=master)][inchpages]
15
+
16
+ Filesystem adapater for [Ruby Object Mapper](https://github.com/rom-rb/rom).
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'rom-filesystem'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install rom-filesystem
33
+
34
+ ## License
35
+
36
+ See `LICENSE` file.
@@ -0,0 +1,18 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: [:ci]
5
+
6
+ desc 'Run CI tasks'
7
+ task ci: [:spec]
8
+
9
+ begin
10
+ require 'rubocop/rake_task'
11
+
12
+ Rake::Task[:default].enhance [:rubocop]
13
+
14
+ RuboCop::RakeTask.new do |task|
15
+ task.options << '--display-cop-names'
16
+ end
17
+ rescue LoadError
18
+ end
@@ -0,0 +1 @@
1
+ require 'rom/filesystem'
@@ -0,0 +1,7 @@
1
+ require 'rom'
2
+
3
+ require 'rom/filesystem/version'
4
+ require 'rom/filesystem/gateway'
5
+ require 'rom/filesystem/relation'
6
+
7
+ ROM.register_adapter(:filesystem, ROM::Filesystem)
@@ -0,0 +1,41 @@
1
+ module ROM
2
+ module Filesystem
3
+ class Dataset
4
+ def initialize(dir, options = {})
5
+ @dir = dir
6
+ @options = options
7
+
8
+ @options[:select] ||= ['*']
9
+ end
10
+
11
+ def select(*args)
12
+ self.class.new(@dir, @options.merge(select: args))
13
+ end
14
+
15
+ def sort
16
+ self.class.new(@dir, @options.merge(sort: true))
17
+ end
18
+
19
+ def each(&block)
20
+ to_a.each(&block)
21
+ end
22
+
23
+ def to_a
24
+ root = Pathname.new(@dir.path)
25
+ paths = @options[:select].map { |filter| "#{root}/#{filter}" }
26
+
27
+ matches = Dir[*paths].reject { |f| f == '.' || f == '..' }
28
+ matches = matches.sort if @options[:sort]
29
+
30
+ matches.map do |filename|
31
+ path = root.join(filename)
32
+
33
+ {
34
+ name: path.basename.to_s,
35
+ path: path
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ require 'rom/filesystem/dataset'
2
+
3
+ module ROM
4
+ module Filesystem
5
+ class Gateway < ROM::Gateway
6
+ def initialize(root)
7
+ @root = File.absolute_path(root)
8
+ end
9
+
10
+ def dataset(name)
11
+ Dataset.new(Dir.new("#{@root}/#{name}"))
12
+ end
13
+
14
+ def dataset?(name)
15
+ Dir.exist?("#{@root}/#{name}")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module ROM
2
+ module Filesystem
3
+ class Relation < ROM::Relation
4
+ adapter :filesystem
5
+
6
+ forward :select, :sort
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Rom
2
+ module Filesystem
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rom/filesystem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rom-filesystem'
8
+ spec.version = Rom::Filesystem::VERSION
9
+ spec.authors = ['Héctor Ramón']
10
+ spec.email = ['hector0193@gmail.com']
11
+
12
+ spec.summary = 'Filesystem adapter for ROM'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/hecrj/rom-filesystem'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'rom', '~> 1.0.0'
23
+
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Reading relations' do
4
+ include_context 'media files'
5
+
6
+ before :each do
7
+ configuration.relation(:media) do
8
+ register_as :media
9
+ end
10
+ end
11
+
12
+ it 'lists file paths' do
13
+ paths = container.relation(:media).sort.to_a.map { |file| file[:path] }
14
+
15
+ expect(paths).to eql([
16
+ Pathname.new(TMP_TEST_DIR).join('media/some_file.txt'),
17
+ Pathname.new(TMP_TEST_DIR).join('media/some_image.png'),
18
+ Pathname.new(TMP_TEST_DIR).join('media/some_markdown.md')
19
+ ])
20
+ end
21
+
22
+ it 'lists file names' do
23
+ names = container.relation(:media).sort.to_a.map { |file| file[:name] }
24
+
25
+ expect(names).to eql(%w(some_file.txt some_image.png some_markdown.md))
26
+ end
27
+
28
+ it 'selects files' do
29
+ files = container.relation(:media).select('*.txt', '*.png').sort.to_a.map { |file| file[:name] }
30
+
31
+ expect(files).to eql(%w(some_file.txt some_image.png))
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ shared_context 'database setup' do
2
+ let(:configuration) { ROM::Configuration.new(:filesystem, TMP_TEST_DIR).use(:macros) }
3
+ let(:container) { ROM.container(configuration) }
4
+ end
@@ -0,0 +1,19 @@
1
+ shared_context 'media files' do
2
+ include_context 'database setup'
3
+
4
+ before :each do
5
+ media_dir = TMP_TEST_DIR.join('media')
6
+
7
+ FileUtils.mkdir_p(media_dir)
8
+
9
+ File.open(media_dir.join('some_file.txt'), 'w') do |f|
10
+ f.write('some content')
11
+ end
12
+
13
+ File.open(media_dir.join('some_markdown.md'), 'w') do |f|
14
+ f.write('some markdown file')
15
+ end
16
+
17
+ File.open(media_dir.join('some_image.png'), 'w') {}
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ Bundler.setup
5
+
6
+ if RUBY_ENGINE == 'rbx'
7
+ require 'codeclimate-test-reporter'
8
+ CodeClimate::TestReporter.start
9
+ end
10
+
11
+ require 'rom-filesystem'
12
+
13
+ root = Pathname(__FILE__).dirname
14
+ TMP_PATH = root.join('../tmp')
15
+ TMP_TEST_DIR = TMP_PATH.join('test')
16
+
17
+ Dir[root.join('shared/*.rb').to_s].each { |f| require f }
18
+
19
+ RSpec.configure do |config|
20
+ config.before do
21
+ FileUtils.rm_r(TMP_TEST_DIR) if File.exist?(TMP_TEST_DIR)
22
+ FileUtils.mkdir_p(TMP_TEST_DIR)
23
+
24
+ @constants = Object.constants
25
+ end
26
+
27
+ config.after do
28
+ added_constants = Object.constants - @constants
29
+ added_constants.each { |name| Object.send(:remove_const, name) }
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rom-filesystem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Héctor Ramón
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rom
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Filesystem adapter for ROM
56
+ email:
57
+ - hector0193@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".rubocop_todo.yml"
66
+ - ".travis.yml"
67
+ - CHANGELOG.md
68
+ - Gemfile
69
+ - Guardfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/rom-filesystem.rb
74
+ - lib/rom/filesystem.rb
75
+ - lib/rom/filesystem/dataset.rb
76
+ - lib/rom/filesystem/gateway.rb
77
+ - lib/rom/filesystem/relation.rb
78
+ - lib/rom/filesystem/version.rb
79
+ - rom-filesystem.gemspec
80
+ - spec/integration/read_spec.rb
81
+ - spec/shared/database_setup.rb
82
+ - spec/shared/media_files.rb
83
+ - spec/spec_helper.rb
84
+ homepage: https://github.com/hecrj/rom-filesystem
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Filesystem adapter for ROM
108
+ test_files:
109
+ - spec/integration/read_spec.rb
110
+ - spec/shared/database_setup.rb
111
+ - spec/shared/media_files.rb
112
+ - spec/spec_helper.rb