array_association 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/array_association.gemspec +33 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/array_association.rb +38 -0
- data/lib/array_association/utils.rb +10 -0
- data/lib/array_association/version.rb +3 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4d6260f2ba3759ec41f3b76abe2a52fbf7f84a65
|
4
|
+
data.tar.gz: 6a575ad5f582dc19c1a0367fa9128588192a81c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12937114a9eefdeeefb17e3950eb6be26f7ecb75852511f83168f06dcdb87b701eb81174f21b817c4fe8d5e62770b1d08c4ab979de01c6f2d837e82ef7f9816f
|
7
|
+
data.tar.gz: aead3cac6fce6f74ea8c47b45a5aa2711aa35499716e4d9b79195271765c734abacd803cbc473a7df251b094e692fa3665a9906af21b218f449a2c5debae98c0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
##################### Styles ##################################
|
5
|
+
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/SymbolArray:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/ClassAndModuleChildren:
|
13
|
+
Exclude:
|
14
|
+
- "app/controllers/*_controller.rb"
|
15
|
+
- "app/controllers/**/*_controller.rb"
|
16
|
+
|
17
|
+
#################### Lint ##################################
|
18
|
+
|
19
|
+
Lint/AmbiguousBlockAssociation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
##################### Metrics ##################################
|
23
|
+
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 110
|
26
|
+
|
27
|
+
Metrics/ClassLength:
|
28
|
+
Max: 200
|
29
|
+
|
30
|
+
Metrics/ModuleLength:
|
31
|
+
Max: 200
|
32
|
+
Exclude:
|
33
|
+
- "**/*_spec.rb"
|
34
|
+
|
35
|
+
Metrics/BlockLength:
|
36
|
+
Max: 50
|
37
|
+
Exclude:
|
38
|
+
- "**/*_spec.rb"
|
39
|
+
|
40
|
+
##################### Rails ##################################
|
41
|
+
|
42
|
+
Rails:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Rails/SkipsModelValidations:
|
46
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Igor Malinovskiy
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# ArrayAssociation
|
2
|
+
|
3
|
+
[![Build Status](https://semaphoreci.com/api/v1/igormalinovskiy/array_association/branches/master/shields_badge.svg)](https://semaphoreci.com/igormalinovskiy/array_association)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/psyipm/array_association/badges/gpa.svg)](https://codeclimate.com/github/psyipm/array_association)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/array_association.svg)](https://badge.fury.io/rb/array_association)
|
6
|
+
|
7
|
+
ActiveRecord-like association for Postgres Array columns
|
8
|
+
This gem defines some helpers to use array columns like assiciated models
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'array_association'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install array_association
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class User < ApplicationRecord
|
30
|
+
include ArrayAssociation
|
31
|
+
array_column :order_ids, :orders, { class: Order }
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
in this case the following methods will be defined:
|
36
|
+
* orders, which returns collection of Order
|
37
|
+
* order_ids=, which sets normalized order_ids
|
38
|
+
* orders=(values), which maps collection and sets order_ids
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/psyipm/array_association.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'array_association/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'array_association'
|
10
|
+
spec.version = ArrayAssociation::VERSION
|
11
|
+
spec.authors = ['Igor Malinovskiy']
|
12
|
+
spec.email = ['igor.malinovskiy@netfixllc.org']
|
13
|
+
|
14
|
+
spec.summary = 'ActiveRecord-like association for Postgres Array columns'
|
15
|
+
spec.description = 'This gem defines some helpers to use array columns like assiciated models'
|
16
|
+
spec.homepage = 'https://github.com/psyipm/array_association'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'activerecord', '>= 4.0'
|
30
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.13'
|
31
|
+
|
32
|
+
spec.add_dependency 'activesupport', '>= 4.0'
|
33
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "array_association"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'array_association/version'
|
4
|
+
require 'active_support/concern'
|
5
|
+
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# include ArrayAssociation
|
9
|
+
# array_column :order_ids, :orders, { class: Order }
|
10
|
+
#
|
11
|
+
# in this case some methods will be defined:
|
12
|
+
# orders, which returns collection of Order
|
13
|
+
# order_ids=, which sets normalized order_ids
|
14
|
+
# orders=(values), which maps collection and sets order_ids
|
15
|
+
#
|
16
|
+
module ArrayAssociation
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
|
19
|
+
autoload :Utils, 'array_association/utils'
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def array_column(column, collection, options)
|
23
|
+
define_method collection do
|
24
|
+
options[:class].send(:where, id: send(column))
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method "#{column}=" do |value|
|
28
|
+
ids = Utils.normalize_integer_array(value)
|
29
|
+
write_attribute(column, ids)
|
30
|
+
end
|
31
|
+
|
32
|
+
define_method "#{collection}=" do |values|
|
33
|
+
ids = Array.wrap(values).map(&:id)
|
34
|
+
send "#{column}=", ids
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: array_association
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Malinovskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.3.13
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.3.13
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: activesupport
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '4.0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '4.0'
|
103
|
+
description: This gem defines some helpers to use array columns like assiciated models
|
104
|
+
email:
|
105
|
+
- igor.malinovskiy@netfixllc.org
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".rubocop.yml"
|
113
|
+
- ".travis.yml"
|
114
|
+
- Gemfile
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- array_association.gemspec
|
119
|
+
- bin/console
|
120
|
+
- bin/setup
|
121
|
+
- lib/array_association.rb
|
122
|
+
- lib/array_association/utils.rb
|
123
|
+
- lib/array_association/version.rb
|
124
|
+
homepage: https://github.com/psyipm/array_association
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.5.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: ActiveRecord-like association for Postgres Array columns
|
148
|
+
test_files: []
|