Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Dec 23, 2014
0 parents commit ab3ee00
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.o
*.a
mkmf.log
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--order random
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: ruby
bundler_args: --without yard guard benchmarks
env:
- CODECLIMATE_REPO_TOKEN=886f3b795e74159719804f8e18b853f4c23a81bd814404e52ec248a0dae6d656
script: "bundle exec rake spec"
rvm:
- 2.0
- 2.1
- rbx-2
- jruby
- ruby-head
matrix:
allow_failures:
- rvm: ruby-head
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/39e1225f489f38b0bd09
on_success: change
on_failure: always
on_start: false
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## v0.0.2 2014-12-06

### Added

* Command API (solnic)

[Compare v0.0.1...v0.0.2](https://github.com/rom-rb/rom-sql/compare/v0.0.1...v0.0.2)

## v0.0.1 2014-11-25

First public release
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source 'https://rubygems.org'

gemspec

group :test do
gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'master'
gem 'rspec', '~> 3.1'
gem 'codeclimate-test-reporter', require: false
gem 'virtus'
end
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Piotr Solnica

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[gem]: https://rubygems.org/gems/rom-yaml
[travis]: https://travis-ci.org/rom-rb/rom-yaml
[gemnasium]: https://gemnasium.com/rom-rb/rom-yaml
[codeclimate]: https://codeclimate.com/github/rom-rb/rom-yaml
[inchpages]: http://inch-ci.org/github/rom-rb/rom-yaml

# ROM::yaml

[![Gem Version](https://badge.fury.io/rb/rom-yaml.svg)][gem]
[![Build Status](https://travis-ci.org/rom-rb/rom-yaml.svg?branch=master)][travis]
[![Dependency Status](https://gemnasium.com/rom-rb/rom-yaml.png)][gemnasium]
[![Code Climate](https://codeclimate.com/github/rom-rb/rom-yaml/badges/gpa.svg)][codeclimate]
[![Test Coverage](https://codeclimate.com/github/rom-rb/rom-yaml/badges/coverage.svg)][codeclimate]
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-yaml.svg?branch=master)][inchpages]

YAML support for [Ruby Object Mapper](https://github.com/rom-rb/rom)

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'rom-yaml'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install rom-yaml

## Usage

See `spec/integration/adapter_spec.rb` for a sample usage.

## License

See `LICENSE` file.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "rspec/core/rake_task"
require "rubocop/rake_task"

task default: [:spec, :rubocop]

RSpec::Core::RakeTask.new(:spec)

RuboCop::RakeTask.new do |task|
task.options << "--display-cop-names"
end
1 change: 1 addition & 0 deletions lib/rom-yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'rom/yaml'
5 changes: 5 additions & 0 deletions lib/rom/yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'yaml'

require 'rom'
require 'rom/yaml/version'
require 'rom/yaml/adapter'
22 changes: 22 additions & 0 deletions lib/rom/yaml/adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module ROM
module YAML
class Adapter < ROM::Adapter
def self.schemes
[:yaml]
end

def initialize(*args)
super
@connection = ::YAML.load_file("#{uri.host}#{uri.path}")
end

def [](name)
connection.fetch(name.to_s)
end

def dataset?(name)
connection.key?(name.to_s)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/rom/yaml/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ROM
module YAML
VERSION = '0.0.2'.freeze
end
end
27 changes: 27 additions & 0 deletions rom-yaml.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rom/yaml/version'

Gem::Specification.new do |spec|
spec.name = "rom-yaml"
spec.version = ROM::YAML::VERSION.dup
spec.authors = ["Piotr Solnica"]
spec.email = ["[email protected]"]
spec.summary = 'YAML support for Ruby Object Mapper'
spec.description = spec.summary
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "moped"
spec.add_runtime_dependency "rom", "~> 0.4", ">= 0.4.0"

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "rubocop", "~> 0.28.0"
end
3 changes: 3 additions & 0 deletions spec/fixtures/test_db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
users:
- name: 'Jane'
email: '[email protected]'
44 changes: 44 additions & 0 deletions spec/integration/adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

describe 'YAML adapter' do
subject(:rom) { setup.finalize }

let(:root) { Pathname(__FILE__).dirname.join('..') }

let(:setup) { ROM.setup("yaml://#{root}/fixtures/test_db.yml") }

before do
setup.schema do
base_relation(:users) do
repository :default

attribute 'name'
attribute 'email'
end
end

setup.relation(:users) do
def by_name(name)
find_all { |user| user['name'] == name }
end
end

setup.mappers do
define(:users) do
model name: 'User'

attribute :name, from: 'name'
attribute :email, from: 'email'
end
end
end

describe 'env#read' do
it 'returns mapped object' do
jane = rom.read(:users).by_name('Jane').to_a.first

expect(jane.name).to eql('Jane')
expect(jane.email).to eql('[email protected]')
end
end
end
12 changes: 12 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# encoding: utf-8

if RUBY_ENGINE == 'rbx'
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
end

require 'rom-yaml'

root = Pathname(__FILE__).dirname

Dir[root.join('shared/*.rb').to_s].each { |f| require f }

0 comments on commit ab3ee00

Please sign in to comment.