Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Add rubocop and update code to match the style rules
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Jul 29, 2013
1 parent 7ed3bd2 commit 1e39c49
Show file tree
Hide file tree
Showing 42 changed files with 214 additions and 75 deletions.
11 changes: 6 additions & 5 deletions Gemfile
@@ -1,21 +1,22 @@
# encoding: utf-8
source 'https://rubygems.org'

gemspec

gem 'rom-relation', :path => '.'
gem 'rom-relation', path: '.'

gem 'axiom', :git => 'https://github.com/dkubb/axiom.git'
gem 'axiom', git: 'https://github.com/dkubb/axiom.git'

group :test do
gem 'bogus', '~> 0.1'
gem 'randexp'
gem 'ruby-graphviz'
gem 'rom-mapper', :git => 'https://github.com/rom-rb/rom-mapper.git'
gem 'axiom-memory-adapter', :git => 'https://github.com/dkubb/axiom-memory-adapter.git'
gem 'rom-mapper', git: 'https://github.com/rom-rb/rom-mapper.git'
gem 'axiom-memory-adapter', git: 'https://github.com/dkubb/axiom-memory-adapter.git'
end

group :development do
gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git'
gem 'devtools', git: 'https://github.com/rom-rb/devtools.git'
end

# added by devtools
Expand Down
6 changes: 6 additions & 0 deletions Guardfile
Expand Up @@ -17,3 +17,9 @@ guard :rspec do

notification :tmux, :display_message => true
end

guard :rubocop, cli: %w[--config config/rubocop.yml] do
watch(%r{.+\.(?:rb|rake)\z})
watch(%r{\Aconfig/rubocop\.yml\z}) { |m| File.dirname(m[0]) }
watch(%r{(?:.+/)?\.rubocop\.yml\z}) { |m| File.dirname(m[0]) }
end
45 changes: 45 additions & 0 deletions config/rubocop.yml
@@ -0,0 +1,45 @@
AllCops:
Includes:
- '**/*.rake'
- 'Gemfile'
- 'Gemfile.devtools'
Excludes:
- '**/vendor/**'

# Avoid parameter lists longer than five parameters.
ParameterLists:
Max: 3
CountKeywordArgs: true

# Avoid more than `Max` levels of nesting.
BlockNesting:
Max: 3

# Align with the style guide.
CollectionMethods:
PreferredMethods:
collect: 'map'
inject: 'reduce'
find: 'detect'
find_all: 'select'

# Do not force public/protected/private keyword to be indented at the same
# level as the def keyword. My personal preference is to outdent these keywords
# because I think when scanning code it makes it easier to identify the
# sections of code and visually separate them. When the keyword is at the same
# level I think it sort of blends in with the def keywords and makes it harder
# to scan the code and see where the sections are.
AccessControl:
Enabled: false

LineLength:
Max: 90

Blocks:
Enabled: false

Documentation:
Enabled: false

EmptyLineBetweenDefs:
Enabled: false # TODO: re-enable once SpecHelper.mock_model case is properly handled
4 changes: 3 additions & 1 deletion lib/rom-relation.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'addressable/uri'

require 'concord'
Expand All @@ -19,7 +21,7 @@ module ROM
Undefined = Object.new.freeze

# An empty frozen Hash useful for parameter default values
EMPTY_HASH = Hash.new.freeze
EMPTY_HASH = {}.freeze

# An empty frozen Array useful for parameter default values
EMPTY_ARRAY = [].freeze
Expand Down
8 changes: 6 additions & 2 deletions lib/rom/environment.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM

# The environment used to build and finalize mappers and their relations
Expand All @@ -13,7 +15,8 @@ class Environment
# env = ROM::Environment.coerce(config)
#
# @param [Environment, Hash<#to_sym, String>] config
# an environment or a hash of adapter uri strings, keyed by repository name
# an environment or a hash of adapter uri strings,
# keyed by repository name
#
# @return [Environment]
#
Expand Down Expand Up @@ -82,7 +85,8 @@ def repository(name)
def register_relations(repository_name, relations)
relations.each do |relation|
name = relation.name
registry[name] = repository(repository_name).register(name, relation).get(name)
repository = repository(repository_name).register(name, relation)
registry[name] = repository.get(name)
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/rom/relation.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM

# Enhanced ROM relation wrapping axiom relation and using injected mapper to
Expand All @@ -21,7 +23,7 @@ def insert(object)

def update(object)
tuple = mapper.dump(object)
new(relation.delete([tuple]).insert([ tuple ]))
new(relation.delete([tuple]).insert([tuple]))
end

def delete(object)
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/repository.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM

# A repository with a given +name+ and +adapter+
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/schema.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM

# Represents ROM's relation schema
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/schema/definition.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM
class Schema

Expand Down
4 changes: 3 additions & 1 deletion lib/rom/schema/definition/relation.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM
class Schema
class Definition
Expand All @@ -14,7 +16,7 @@ def initialize(&block)
end

def header
Axiom::Relation::Header.coerce(@header, :keys => @keys)
Axiom::Relation::Header.coerce(@header, keys: @keys)
end

def attribute(name, type)
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/schema/definition/relation/base.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM
class Schema
class Definition
Expand Down
8 changes: 7 additions & 1 deletion lib/rom/support/axiom/adapter.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module Axiom

# Raised when passing an +uri+ with an unregistered scheme to {Adapter.new}
Expand Down Expand Up @@ -60,8 +62,12 @@ def self.build(uri)
# @api private
def self.get(uri)
uri_scheme = uri.scheme

REGISTRY.fetch(uri_scheme) {
raise UnknownAdapterError, "'#{uri_scheme}' is no registered uri scheme"
raise(
UnknownAdapterError,
"#{uri_scheme.inspect} is no registered uri scheme"
)
}
end

Expand Down
2 changes: 2 additions & 0 deletions lib/rom/support/axiom/adapter/data_objects.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'axiom-do-adapter'

module Axiom
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/support/axiom/adapter/memory.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'axiom-memory-adapter'
require 'rom/support/axiom/adapter'

Expand Down
2 changes: 2 additions & 0 deletions lib/rom/support/axiom/adapter/postgres.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'do_postgres'

require 'rom/support/axiom/adapter'
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/support/axiom/adapter/sqlite3.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'do_sqlite3'

require 'rom/support/axiom/adapter'
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/version.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

module ROM
class Relation
VERSION = '0.0.1'
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/environment_setup_spec.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'spec_helper'

describe 'Setting up environment' do
Expand All @@ -13,7 +15,7 @@
end
end

env = ROM::Environment.coerce(:memory => 'memory://test')
env = ROM::Environment.coerce(memory: 'memory://test')
env.load_schema(schema)

repository = env.repository(:memory)
Expand Down
46 changes: 36 additions & 10 deletions spec/integration/schema_definition_spec.rb
@@ -1,17 +1,43 @@
# encoding: utf-8

require 'spec_helper'

describe 'Defining a ROM schema' do
let(:people) { Axiom::Relation::Base.new(:people, people_header) }
let(:people_header) { Axiom::Relation::Header.coerce(people_attributes, :keys => people_keys) }
let(:people_attributes) { [ [ :id, Integer ], [ :name, String ] ] }
let(:people_keys) { [ :id ] }
let(:people) {
Axiom::Relation::Base.new(:people, people_header)
}

let(:people_header) {
Axiom::Relation::Header.coerce(people_attributes, keys: people_keys)
}

let(:people_attributes) {
[[:id, Integer], [:name, String]]
}

let(:people_keys) {
[:id]
}

let(:profiles) {
Axiom::Relation::Base.new(:profiles, profiles_header)
}

let(:profiles_header) {
Axiom::Relation::Header.coerce(profiles_attributes, keys: profiles_keys)
}

let(:profiles_attributes) {
[[:id, Integer], [:person_id, Integer], [:text, String]]
}

let(:profiles) { Axiom::Relation::Base.new(:profiles, profiles_header) }
let(:profiles_header) { Axiom::Relation::Header.coerce(profiles_attributes, :keys => profiles_keys) }
let(:profiles_attributes) { [ [ :id, Integer ], [ :person_id, Integer ], [ :text, String ] ] }
let(:profiles_keys) { [ :id, :person_id ] }
let(:profiles_keys) {
[:id, :person_id]
}

let(:people_with_profile) { people.join(profiles.rename(:id => :profile_id, :person_id => :id)) }
let(:people_with_profile) {
people.join(profiles.rename(id: :profile_id, person_id: :id))
}

let(:schema) do
ROM::Schema.build do
Expand All @@ -36,7 +62,7 @@
end

relation :people_with_profile do
people.join(profiles.rename(:id => :profile_id, :person_id => :id))
people.join(profiles.rename(id: :profile_id, person_id: :id))
end
end
end
Expand Down
18 changes: 14 additions & 4 deletions spec/integration/working_with_relations_spec.rb
@@ -1,12 +1,22 @@
# encoding: utf-8

require 'spec_helper'

describe 'Working with relations' do
let(:header) { Axiom::Relation::Header.coerce([[:id, Integer], [:name, String]]) }
let(:mapper) { TestMapper.new(header, model) }
let(:model) { Class.new(OpenStruct) }
let(:header) {
Axiom::Relation::Header.coerce([[:id, Integer], [:name, String]])
}

let(:mapper) {
TestMapper.new(header, model)
}

let(:model) {
Class.new(OpenStruct)
}

specify 'relation setup' do
env = ROM::Environment.coerce(:test => 'memory://test')
env = ROM::Environment.coerce(test: 'memory://test')
repo = env.repository(:test)

repo.register(:users, Axiom::Relation::Base.new(:users, header))
Expand Down
4 changes: 3 additions & 1 deletion spec/shared/unit/environment_context.rb
@@ -1,4 +1,6 @@
# encoding: utf-8

shared_context 'Environment' do
let(:object) { described_class.coerce(:test => 'memory://test') }
let(:object) { described_class.coerce(test: 'memory://test') }
let(:uri) { 'memory://test' }
end
4 changes: 4 additions & 0 deletions spec/shared/unit/relation_context.rb
@@ -1,3 +1,7 @@
# # encoding: utf-8

# encoding: utf-8

This comment has been minimized.

Copy link
@dkubb

dkubb Jul 29, 2013

Contributor

Looks like something went a bit crazy here with the encoding ;)


shared_context 'Relation' do
subject(:relation) { described_class.new(users, mapper) }

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -29,7 +29,7 @@

include ROM

ROM_ENV = Environment.coerce(:test => "memory://test")
ROM_ENV = Environment.coerce(test: 'memory://test')
ROM_ADAPTER = ENV.fetch('ROM_ADAPTER', :in_memory).to_sym

Bogus.configure do |config|
Expand Down
31 changes: 2 additions & 29 deletions spec/support/helper.rb
@@ -1,11 +1,6 @@
module SpecHelper
# encoding: utf-8

def subclass(name = nil)
Class.new(described_class) do
define_singleton_method(:name) { "#{name}" }
yield if block_given?
end
end
module SpecHelper

def mock_model(*attributes)
Class.new {
Expand All @@ -19,26 +14,4 @@ def initialize(attrs)
}
end

def mock_relation(name, header = [], tuples = Axiom::Relation::Empty::ZERO_TUPLE)
Axiom::Relation::Base.new(name, header, tuples)
end

def mock_connector(attributes)
OpenStruct.new(attributes)
end

def mock_node(name)
OpenStruct.new(:name => name)
end

def mock_join_definition(left_relation, right_relation, left_keys, right_keys)
left = Relationship::JoinDefinition::Side.new(left_relation, left_keys)
right = Relationship::JoinDefinition::Side.new(right_relation, right_keys)
Relationship::JoinDefinition.new(left, right)
end

def attribute_alias(*args)
ROM::Relation::Header::Attribute.build(*args)
end

end

0 comments on commit 1e39c49

Please sign in to comment.