rom-support 0.1.0

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: 29285bc52be91138894978734ea97b5ff8cf1916
4
+ data.tar.gz: cb55485edd81dcf8e45a44a0df2c99a8d156ee10
5
+ SHA512:
6
+ metadata.gz: 7e107d16dcec735f0ce71c4c6f820102f62fee1852b31329a29d6322233ecb0b10ea713939053b4c8a0737f9544dcfcf72cc72fd67a9ee1253872ff6bd8aa3e1
7
+ data.tar.gz: 53d9fe73f2c618604142cee6a294d002a9f0f9e0eb0406dbea6697bc57c749c5fa8e2aced4d01aaf225006f72c1eca00b1e4c549747ccb6c5f7b0fb98ab53982
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ Gemfile.lock
15
+ vendor/
16
+
17
+ .idea/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --order random
3
+ --warnings
4
+ -r ./spec/spec_helper
@@ -0,0 +1,29 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ env:
5
+ - CODECLIMATE_REPO_TOKEN=513a7c6a20ab24a3937cb3a75400c8bba6f86a9405d05241445fdf432c378f77
6
+ bundler_args: --without tools
7
+ script: "bundle exec rake spec"
8
+ rvm:
9
+ - 2.0
10
+ - 2.1
11
+ - 2.2
12
+ - rbx-2
13
+ - jruby
14
+ - ruby-head
15
+ - jruby-head
16
+ env:
17
+ global:
18
+ - JRUBY_OPTS='--dev -J-Xmx1024M'
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+ - rvm: jruby-head
23
+ notifications:
24
+ webhooks:
25
+ urls:
26
+ - https://webhooks.gitter.im/e/39e1225f489f38b0bd09
27
+ on_success: change
28
+ on_failure: always
29
+ on_start: false
@@ -0,0 +1,3 @@
1
+ v0.1.0 2015-08-10
2
+
3
+ First public release. The code was ported from rom 0.8.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,35 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rom-mapper', github: 'rom-rb/rom-mapper', branch: 'master'
6
+
7
+ group :console do
8
+ gem 'pry'
9
+ gem 'pg', platforms: [:mri]
10
+ end
11
+
12
+ group :test do
13
+ gem 'activesupport'
14
+ gem 'inflecto', '~> 0.0', '>= 0.0.2'
15
+
16
+ platforms :rbx do
17
+ gem 'rubysl-bigdecimal', platforms: :rbx
18
+ gem 'codeclimate-test-reporter', require: false
19
+ end
20
+ end
21
+
22
+ group :tools do
23
+ gem 'rubocop', '~> 0.31'
24
+
25
+ gem 'guard'
26
+ gem 'guard-rspec'
27
+ gem 'guard-rubocop'
28
+
29
+ gem 'byebug'
30
+
31
+ platform :mri do
32
+ gem 'mutant', '>= 0.8.0', github: 'mbj/mutant', branch: 'master'
33
+ gem 'mutant-rspec'
34
+ end
35
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013-2015 Ruby Object Mapper Team
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ [gem]: https://rubygems.org/gems/rom-support
2
+ [travis]: https://travis-ci.org/rom-rb/rom-support
3
+ [gemnasium]: https://gemnasium.com/rom-rb/rom-support
4
+ [codeclimate]: https://codeclimate.com/github/rom-rb/rom-support
5
+ [inchpages]: http://inch-ci.org/github/rom-rb/rom-support
6
+
7
+ # rom-support
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/rom-support.svg)][gem]
10
+ [![Build Status](https://travis-ci.org/rom-rb/rom-support.svg?branch=master)][travis]
11
+ [![Dependency Status](https://gemnasium.com/rom-rb/rom-support.png)][gemnasium]
12
+ [![Code Climate](https://codeclimate.com/github/rom-rb/rom-support/badges/gpa.svg)][codeclimate]
13
+ [![Test Coverage](https://codeclimate.com/github/rom-rb/rom-support/badges/coverage.svg)][codeclimate]
14
+ [![Inline docs](http://inch-ci.org/github/rom-rb/rom-support.svg?branch=master)][inchpages]
15
+
16
+ Support libraries for ROM gems. Most likely some or even all of those will become standalone micro-libs at some point or replaced with existing ones.
@@ -0,0 +1,15 @@
1
+ require "rspec/core/rake_task"
2
+ require "rake/testtask"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: [:ci]
6
+
7
+ desc 'Run specs in isolation'
8
+ task :"spec:isolation" do
9
+ FileList["spec/**/*_spec.rb"].each do |spec|
10
+ sh "rspec", spec
11
+ end
12
+ end
13
+
14
+ desc "Run CI tasks"
15
+ task ci: [:spec]
@@ -0,0 +1 @@
1
+ require 'rom/support/constants'
@@ -0,0 +1,41 @@
1
+ require 'rom/support/enumerable_dataset'
2
+
3
+ module ROM
4
+ # A helper module that adds data-proxy behavior to an array-like object
5
+ #
6
+ # @see EnumerableDataset
7
+ #
8
+ # @api public
9
+ module ArrayDataset
10
+ extend DataProxy::ClassMethods
11
+ include EnumerableDataset
12
+
13
+ # Extends the class with data-proxy behavior
14
+ #
15
+ # @api private
16
+ def self.included(klass)
17
+ klass.class_eval do
18
+ include Options
19
+ include DataProxy
20
+ end
21
+ end
22
+
23
+ forward(
24
+ :*, :+, :-, :compact, :compact!, :flatten, :flatten!, :length, :pop,
25
+ :reverse, :reverse!, :sample, :size, :shift, :shuffle, :shuffle!,
26
+ :slice, :slice!, :sort!, :uniq, :uniq!, :unshift, :values_at
27
+ )
28
+
29
+ [
30
+ :map!, :combination, :cycle, :delete_if, :keep_if, :permutation, :reject!,
31
+ :select!, :sort_by!
32
+ ].each do |method|
33
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
34
+ def #{method}(*args, &block)
35
+ return to_enum unless block
36
+ self.class.new(data.send(:#{method}, *args, &block), options)
37
+ end
38
+ RUBY
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ module ROM
2
+ module AutoCurry
3
+ def self.extended(klass)
4
+ busy = false
5
+
6
+ klass.define_singleton_method(:method_added) do |name|
7
+ return if busy
8
+ busy = true
9
+ auto_curry(name)
10
+ busy = false
11
+ super(name)
12
+ end
13
+ end
14
+
15
+ def auto_curry(name)
16
+ curried = self.curried
17
+ meth = instance_method(name)
18
+ arity = meth.arity
19
+
20
+ define_method(name) do |*args|
21
+ if arity < 0 || arity == args.size
22
+ meth.bind(self).(*args)
23
+ else
24
+ curried.new(self, name: name, curry_args: args, arity: arity)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ require 'rom/support/options'
2
+
3
+ module ROM
4
+ # Internal support class for generating classes
5
+ #
6
+ # @private
7
+ class ClassBuilder
8
+ include Options
9
+
10
+ option :name, type: String, reader: true
11
+ option :parent, type: Class, reader: true, parent: Object
12
+
13
+ # Generate a class based on options
14
+ #
15
+ # @example
16
+ # builder = ROM::ClasBuilder.new(name: 'MyClass')
17
+ #
18
+ # klass = builder.call
19
+ # klass.name # => "MyClass"
20
+ #
21
+ # @return [Class]
22
+ #
23
+ # @api private
24
+ def call
25
+ klass = Class.new(parent)
26
+
27
+ klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
28
+ def self.name
29
+ #{name.inspect}
30
+ end
31
+
32
+ def self.inspect
33
+ name
34
+ end
35
+
36
+ def self.to_s
37
+ name
38
+ end
39
+ RUBY
40
+
41
+ yield(klass) if block_given?
42
+
43
+ klass
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,56 @@
1
+ module ROM
2
+ # Internal support module for class-level settings
3
+ #
4
+ # @private
5
+ module ClassMacros
6
+ # Specify what macros a class will use
7
+ #
8
+ # @example
9
+ # class MyClass
10
+ # extend ROM::ClassMacros
11
+ #
12
+ # defines :one, :two
13
+ #
14
+ # one 1
15
+ # two 2
16
+ # end
17
+ #
18
+ # class OtherClass < MyClass
19
+ # two 'two'
20
+ # end
21
+ #
22
+ # MyClass.one # => 1
23
+ # MyClass.two # => 2
24
+ #
25
+ # OtherClass.one # => 1
26
+ # OtherClass.two # => 'two'
27
+ #
28
+ # @api private
29
+ def defines(*args)
30
+ mod = Module.new
31
+
32
+ args.each do |name|
33
+ mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
34
+ def #{name}(value = Undefined)
35
+ if value == Undefined
36
+ defined?(@#{name}) && @#{name}
37
+ else
38
+ @#{name} = value
39
+ end
40
+ end
41
+ RUBY
42
+ end
43
+
44
+ delegates = args.map { |name| "klass.#{name}(#{name})" }.join("\n")
45
+
46
+ mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
47
+ def inherited(klass)
48
+ super
49
+ #{delegates}
50
+ end
51
+ RUBY
52
+
53
+ extend(mod)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module ROM
2
+ Undefined = Object.new.freeze
3
+ EMPTY_HASH = {}.freeze
4
+ EMPTY_ARRAY = [].freeze
5
+ end
@@ -0,0 +1,102 @@
1
+ require 'equalizer'
2
+
3
+ module ROM
4
+ # Helper module for dataset classes
5
+ #
6
+ # It provides a constructor accepting data, header and an optional row_proc.
7
+ # This module is used internally by EnumerableDataset and ArrayDataset.
8
+ #
9
+ # @private
10
+ module DataProxy
11
+ NON_FORWARDABLE = [
12
+ :each, :to_a, :to_ary, :kind_of?, :instance_of?, :is_a?
13
+ ].freeze
14
+
15
+ # Wrapped data array
16
+ #
17
+ # @return [Object] Data object for the iterator
18
+ #
19
+ # @api private
20
+ attr_reader :data
21
+
22
+ # @return [Proc] tuple processing proc
23
+ #
24
+ # @api private
25
+ attr_reader :row_proc
26
+
27
+ # Extends the class with `forward` DSL and Equalizer using `data` attribute
28
+ #
29
+ # @see ClassMethods#forward
30
+ #
31
+ # @api private
32
+ def self.included(klass)
33
+ klass.class_eval do
34
+ extend ClassMethods
35
+
36
+ include Equalizer.new(:data)
37
+
38
+ option :row_proc, reader: true, default: proc { |obj| obj.class.row_proc }
39
+ end
40
+ end
41
+
42
+ # @api private
43
+ def initialize(data, options = {})
44
+ @data = data
45
+ super(data, options)
46
+ end
47
+
48
+ # Iterate over data using row_proc
49
+ #
50
+ # @return [Enumerator] if block is not given
51
+ #
52
+ # @api private
53
+ def each
54
+ return to_enum unless block_given?
55
+ data.each { |tuple| yield(row_proc[tuple]) }
56
+ end
57
+
58
+ module ClassMethods
59
+ # Default no-op tuple proc
60
+ #
61
+ # @return [Proc]
62
+ #
63
+ # @api private
64
+ def row_proc
65
+ -> tuple { tuple }
66
+ end
67
+
68
+ # Forward provided methods to the underlaying data object
69
+ #
70
+ # @example
71
+ #
72
+ # class MyDataset
73
+ # include DataProxy
74
+ #
75
+ # forward(:find_all, :map)
76
+ # end
77
+ #
78
+ # @return [undefined]
79
+ #
80
+ # @api public
81
+ def forward(*methods)
82
+ # FIXME: we should probably raise if one of the non-forwardable methods
83
+ # was provided
84
+ (methods - NON_FORWARDABLE).each do |method_name|
85
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
86
+ def #{method_name}(*args, &block)
87
+ response = data.public_send(#{method_name.inspect}, *args, &block)
88
+
89
+ if response.equal?(data)
90
+ self
91
+ elsif response.is_a?(data.class)
92
+ self.class.new(response)
93
+ else
94
+ response
95
+ end
96
+ end
97
+ RUBY
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end