rom-yaml 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7fb0f21b9cb89e51692a67a4590f3adc3a11ef0
4
+ data.tar.gz: 3b916caf45d21fbbe37f72834c56a35f4ecc2000
5
+ SHA512:
6
+ metadata.gz: d087d68eebecfb3823c8bfecc98b34a5f4a27cee4d405de1fbd485e22eb193561f6093b1800a8fdf961a600cedd468dee4f7ec5a494dc19b366825c314275627
7
+ data.tar.gz: c27b34ce93067a04fe6d7f93ad48949fcc32a67e4268f3f809b5d7e89e7fb954c955c602f403ef44b32a0a43aec4cf01a057a8a75103e2fb5bb39c41d2d2fc1f
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,63 @@
1
+ # Generated by `rubocop --auto-gen-config`
2
+ inherit_from: .rubocop_todo.yml
3
+
4
+ # It’s quite readable when we know what we are doing
5
+ Lint/AssignmentInCondition:
6
+ Enabled: false
7
+
8
+ # No need to handle LoadError in rake
9
+ Lint/HandleExceptions:
10
+ Exclude:
11
+ - rakelib/*.rake
12
+
13
+ # The enforced style doesn’t match Vim’s defaults
14
+ Style/AlignParameters:
15
+ Enabled: false
16
+
17
+ # UTF-8 is perfectly fine in comments
18
+ Style/AsciiComments:
19
+ Enabled: false
20
+
21
+ # Allow using braces for value-returning blocks
22
+ Style/Blocks:
23
+ Enabled: false
24
+
25
+ # Documentation checked by Inch CI
26
+ Style/Documentation:
27
+ Enabled: false
28
+
29
+ # Early returns have their vices
30
+ Style/GuardClause:
31
+ Enabled: false
32
+
33
+ # Need to be skipped for >-> usage
34
+ Style/Lambda:
35
+ Enabled: false
36
+
37
+ # Multiline block chains are ok
38
+ Style/MultilineBlockChain:
39
+ Enabled: false
40
+
41
+ # Even a single escaped slash can be confusing
42
+ Style/RegexpLiteral:
43
+ MaxSlashes: 0
44
+
45
+ # Don’t introduce semantic fail/raise distinction
46
+ Style/SignalException:
47
+ EnforcedStyle: only_raise
48
+
49
+ # Need to be skipped for >-> usage
50
+ Style/SpaceAroundOperators:
51
+ Enabled: false
52
+
53
+ # Accept both single and double quotes
54
+ Style/StringLiterals:
55
+ Enabled: false
56
+
57
+ # Allow def self.foo; @foo; end
58
+ Style/TrivialAccessors:
59
+ Enabled: false
60
+
61
+ # Allow rom-csv
62
+ Style/FileName:
63
+ Enabled: false
@@ -0,0 +1,6 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-02-09 17:10:04 +0100 using RuboCop version 0.28.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ bundler_args: --without tools
3
+ env:
4
+ - CODECLIMATE_REPO_TOKEN=ef69eb6a9e19987527e5010a02bbf71cd4ddc8a5137ba308f299817f56d06e7f
5
+ script: "bundle exec rake spec"
6
+ rvm:
7
+ - 2.0
8
+ - 2.1
9
+ - 2.2
10
+ - rbx-2
11
+ - jruby
12
+ - ruby-head
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ notifications:
17
+ webhooks:
18
+ urls:
19
+ - https://webhooks.gitter.im/e/39e1225f489f38b0bd09
20
+ on_success: change
21
+ on_failure: always
22
+ on_start: false
@@ -0,0 +1,3 @@
1
+ ## v0.0.1 2015-03-22
2
+
3
+ First public release
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'byebug', platform: :mri
7
+ gem 'inflecto'
8
+ gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'master'
9
+ gem 'rspec', '~> 3.1'
10
+ gem 'codeclimate-test-reporter', require: false
11
+ gem 'virtus'
12
+ end
13
+
14
+ group :tools do
15
+ gem 'rubocop'
16
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Piotr Solnica
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ [gem]: https://rubygems.org/gems/rom-yaml
2
+ [travis]: https://travis-ci.org/rom-rb/rom-yaml
3
+ [gemnasium]: https://gemnasium.com/rom-rb/rom-yaml
4
+ [codeclimate]: https://codeclimate.com/github/rom-rb/rom-yaml
5
+ [inchpages]: http://inch-ci.org/github/rom-rb/rom-yaml
6
+
7
+ # ROM::YAML
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/rom-yaml.svg)][gem]
10
+ [![Build Status](https://travis-ci.org/rom-rb/rom-yaml.svg?branch=master)][travis]
11
+ [![Dependency Status](https://gemnasium.com/rom-rb/rom-yaml.png)][gemnasium]
12
+ [![Code Climate](https://codeclimate.com/github/rom-rb/rom-yaml/badges/gpa.svg)][codeclimate]
13
+ [![Test Coverage](https://codeclimate.com/github/rom-rb/rom-yaml/badges/coverage.svg)][codeclimate]
14
+ [![Inline docs](http://inch-ci.org/github/rom-rb/rom-yaml.svg?branch=master)][inchpages]
15
+
16
+ YAML support 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-yaml'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install rom-yaml
33
+
34
+ ## Usage
35
+
36
+ See `spec/integration/adapter_spec.rb` for a sample usage.
37
+
38
+ ## License
39
+
40
+ See `LICENSE` file.
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: :spec
@@ -0,0 +1 @@
1
+ require 'rom/yaml'
@@ -0,0 +1,7 @@
1
+ require 'rom'
2
+
3
+ require 'rom/yaml/version'
4
+ require 'rom/yaml/repository'
5
+ require 'rom/yaml/relation'
6
+
7
+ ROM.register_adapter(:yaml, ROM::YAML)
@@ -0,0 +1,18 @@
1
+ require 'rom/memory/dataset'
2
+
3
+ module ROM
4
+ module YAML
5
+ # YAML in-memory dataset used by YAML repositories
6
+ #
7
+ # @api public
8
+ class Dataset < ROM::Memory::Dataset
9
+ # Data-row transformation proc
10
+ #
11
+ # @api private
12
+ def self.row_proc
13
+ # TODO: this is not recursive
14
+ Transproc(:symbolize_keys)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'rom/relation'
2
+
3
+ module ROM
4
+ module YAML
5
+ # YAML-specific relation subclass
6
+ #
7
+ # @api private
8
+ class Relation < ROM::Relation
9
+ forward :join, :project, :restrict, :order
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,76 @@
1
+ require 'yaml'
2
+
3
+ require 'rom/repository'
4
+ require 'rom/yaml/dataset'
5
+
6
+ module ROM
7
+ module YAML
8
+ # YAML repository
9
+ #
10
+ # Connects to a yaml file and uses it as a data-source
11
+ #
12
+ # @example
13
+ # ROM.setup(:yaml, '/path/to/data.yml')
14
+ #
15
+ # rom = ROM.finalize.env
16
+ #
17
+ # repository = rom.repositories[:default]
18
+ #
19
+ # repository.dataset?(:users) # => true
20
+ # repository[:users] # => data under 'users' key from the yaml file
21
+ #
22
+ # @api public
23
+ class Repository < ROM::Repository
24
+ # Registered datasets
25
+ #
26
+ # @api private
27
+ attr_reader :datasets
28
+
29
+ # @param [String] path The absolute path to yaml file
30
+ #
31
+ # @api private
32
+ def initialize(path)
33
+ @datasets = {}
34
+
35
+ if File.directory?(path)
36
+ @connection = Dir["#{path}/*.yml"].each_with_object({}) do |file, h|
37
+ name = File.basename(file, '.*')
38
+ data = ::YAML.load_file(file)[name]
39
+ h[name] = data
40
+ end
41
+ else
42
+ @connection = ::YAML.load_file(path)
43
+ end
44
+ end
45
+
46
+ # Return dataset by its name
47
+ #
48
+ # @param [Symbol]
49
+ #
50
+ # @return [Array<Hash>]
51
+ #
52
+ # @api public
53
+ def [](name)
54
+ datasets.fetch(name)
55
+ end
56
+
57
+ # Register a new dataset
58
+ #
59
+ # @param [Symbol]
60
+ #
61
+ # @return [Dataset]
62
+ #
63
+ # @api public
64
+ def dataset(name)
65
+ datasets[name] = Dataset.new(connection.fetch(name.to_s))
66
+ end
67
+
68
+ # Return if a dataset with provided name exists
69
+ #
70
+ # @api public
71
+ def dataset?(name)
72
+ datasets.key?(name)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ module ROM
2
+ module YAML
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ require "rubocop/rake_task"
3
+
4
+ Rake::Task[:default].enhance [:rubocop]
5
+
6
+ RuboCop::RakeTask.new do |task|
7
+ task.options << "--display-cop-names"
8
+ end
9
+
10
+ namespace :rubocop do
11
+ desc 'Generate a configuration file acting as a TODO list.'
12
+ task :auto_gen_config do
13
+ exec "bundle exec rubocop --auto-gen-config"
14
+ end
15
+ end
16
+
17
+ rescue LoadError
18
+ 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/yaml/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rom-yaml'
8
+ spec.version = ROM::YAML::VERSION.dup
9
+ spec.authors = ['Piotr Solnica']
10
+ spec.email = ['piotr.solnica@gmail.com']
11
+ spec.summary = 'YAML support for Ruby Object Mapper'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'http://rom-rb.org'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'rom', '~> 0.6.0'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rubocop', '~> 0.28.0'
26
+ end
@@ -0,0 +1,4 @@
1
+ tasks:
2
+ - title: 'Task One'
3
+ - title: 'Task Two'
4
+ - title: 'Task Three'
@@ -0,0 +1,3 @@
1
+ users:
2
+ - name: 'Jane'
3
+ email: 'jane@doe.org'
@@ -0,0 +1,6 @@
1
+ users:
2
+ - name: 'Jane'
3
+ email: 'jane@doe.org'
4
+ roles:
5
+ - role_name: 'Member'
6
+ - role_name: 'Admin'
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rom/lint/spec'
4
+
5
+ describe 'YAML adapter' do
6
+ subject(:rom) { setup.finalize }
7
+
8
+ let(:root) { Pathname(__FILE__).dirname.join('..') }
9
+
10
+ let(:path) { "#{root}/fixtures/test_db.yml" }
11
+ let(:setup) { ROM.setup(:yaml, path) }
12
+
13
+ before do
14
+ setup.relation(:users) do
15
+ def by_name(name)
16
+ restrict(name: name)
17
+ end
18
+ end
19
+
20
+ setup.mappers do
21
+ define(:users) do
22
+ register_as :entity
23
+
24
+ model name: 'User'
25
+
26
+ attribute :name
27
+ attribute :email
28
+
29
+ embedded :roles, type: :array do
30
+ attribute :name, from: 'role_name'
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ describe 'env#relation' do
37
+ it 'returns mapped object' do
38
+ jane = rom.relation(:users).as(:entity).by_name('Jane').first
39
+
40
+ expect(jane.name).to eql('Jane')
41
+ expect(jane.email).to eql('jane@doe.org')
42
+ expect(jane.roles.length).to eql(2)
43
+ expect(jane.roles).to eql([
44
+ { name: 'Member' }, { name: 'Admin' }
45
+ ])
46
+ end
47
+ end
48
+
49
+ describe 'multi-file setup' do
50
+ it 'uses one-file-per-relation' do
51
+ setup = ROM.setup(:yaml, "#{root}/fixtures/db")
52
+
53
+ setup.relation(:users)
54
+ setup.relation(:tasks)
55
+
56
+ rom = setup.finalize
57
+
58
+ expect(rom.relation(:users)).to match_array([
59
+ { name: 'Jane', email: 'jane@doe.org' }
60
+ ])
61
+
62
+ expect(rom.relation(:tasks)).to match_array([
63
+ { title: 'Task One' },
64
+ { title: 'Task Two' },
65
+ { title: 'Task Three' }
66
+ ])
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ if RUBY_ENGINE == 'rbx'
4
+ require "codeclimate-test-reporter"
5
+ CodeClimate::TestReporter.start
6
+ end
7
+
8
+ require 'rom-yaml'
9
+
10
+ begin
11
+ require 'byebug'
12
+ rescue LoadError
13
+ end
14
+
15
+ root = Pathname(__FILE__).dirname
16
+
17
+ Dir[root.join('shared/*.rb').to_s].each { |f| require f }
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rom/lint/spec'
4
+
5
+ describe ROM::YAML::Dataset do
6
+ let(:data) { [{ id: 1 }, { id: 2 }] }
7
+ let(:dataset) { ROM::YAML::Dataset.new(data) }
8
+
9
+ it_behaves_like "a rom enumerable dataset"
10
+
11
+ it "symbolizes keys" do
12
+ dataset = ROM::YAML::Dataset.new(["foo" => 23])
13
+ expect(dataset.to_a).to eq([{ foo: 23 }])
14
+ end
15
+
16
+ it "does not symbolizes keys recursively" do
17
+ dataset = ROM::YAML::Dataset.new(["foo" => { "bar" => :baz }])
18
+ expect(dataset.to_a).to eq([foo: { "bar" => :baz }])
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rom/lint/spec'
4
+
5
+ describe ROM::YAML::Repository do
6
+ let(:root) { Pathname(__FILE__).dirname.join('..') }
7
+
8
+ it_behaves_like 'a rom repository' do
9
+ let(:identifier) { :yaml }
10
+ let(:repository) { ROM::YAML::Repository }
11
+ let(:uri) { "#{root}/fixtures/test_db.yml" }
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rom-yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Solnica
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-22 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: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.28.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.28.0
69
+ description: YAML support for Ruby Object Mapper
70
+ email:
71
+ - piotr.solnica@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".rubocop_todo.yml"
80
+ - ".travis.yml"
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - lib/rom-yaml.rb
87
+ - lib/rom/yaml.rb
88
+ - lib/rom/yaml/dataset.rb
89
+ - lib/rom/yaml/relation.rb
90
+ - lib/rom/yaml/repository.rb
91
+ - lib/rom/yaml/version.rb
92
+ - rakelib/rubocop.rake
93
+ - rom-yaml.gemspec
94
+ - spec/fixtures/db/tasks.yml
95
+ - spec/fixtures/db/users.yml
96
+ - spec/fixtures/test_db.yml
97
+ - spec/integration/adapter_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/unit/dataset_spec.rb
100
+ - spec/unit/repository_spec.rb
101
+ homepage: http://rom-rb.org
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: YAML support for Ruby Object Mapper
125
+ test_files:
126
+ - spec/fixtures/db/tasks.yml
127
+ - spec/fixtures/db/users.yml
128
+ - spec/fixtures/test_db.yml
129
+ - spec/integration/adapter_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/unit/dataset_spec.rb
132
+ - spec/unit/repository_spec.rb
133
+ has_rdoc: