arable 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/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/lib/arable/version.rb +5 -0
- data/lib/arable.rb +76 -0
- data/sig/arable.rbs +4 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6902faa8ab5b48277e24a765c398d433af4dcdcda5ddff07db42e8e27a145481
|
4
|
+
data.tar.gz: c12e4b8086aadac55214f08e792f92f167ea5a055de4eff128e5dd224f81063f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c3db6a6754381c41b0856bebfb8b1d5f48c91c278590e7f3e96a241ad7cc7db8e84553eff5092ed690f22dd59a65f81d60f359d93a642cdb1afc1368b037935
|
7
|
+
data.tar.gz: 28a80481d6fb7bb8a2b2763d1133995150652028b58a44ea3f94b144f4c997a1dd0d86f87941b5527fc3fb54b97021770f8470b038583087234d31df72e2b1c0
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Danielius
|
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,39 @@
|
|
1
|
+
# Arable
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/arable`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'arable'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install arable
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/arable.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/arable.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "arable/version"
|
4
|
+
|
5
|
+
module Arable
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
SKIP_ARABLE_COLUMNS_CLASS_VAR_NAME = :@@skip_arable_columns
|
9
|
+
|
10
|
+
def self.models
|
11
|
+
ApplicationRecord.models.reject { _1.class_variable_defined?(SKIP_ARABLE_COLUMNS_CLASS_VAR_NAME) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.column_names_from_schema(table_name)
|
15
|
+
table_definition_match =
|
16
|
+
File
|
17
|
+
.read('db/schema.rb')
|
18
|
+
.match(/create_table "#{table_name}".*?\n(.*?)\n *end/m)
|
19
|
+
|
20
|
+
columns =
|
21
|
+
table_definition_match[1]
|
22
|
+
.lines
|
23
|
+
.reject { |line| line.include?('t.index') }
|
24
|
+
.map { |line| line.match(/t\.[a-z]* "([a-z_]*)"/)[1] }
|
25
|
+
|
26
|
+
if table_definition_match[0].include?('id: false')
|
27
|
+
columns
|
28
|
+
else
|
29
|
+
['id'] + columns
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included(klass)
|
34
|
+
return if klass.class_variable_defined?(SKIP_ARABLE_COLUMNS_CLASS_VAR_NAME)
|
35
|
+
|
36
|
+
column_names = column_names_from_schema(klass.table_name).map(&:to_sym)
|
37
|
+
illegal_names = column_names & klass.methods
|
38
|
+
|
39
|
+
if illegal_names.any?
|
40
|
+
Rails.logger.warn("#{klass} model has illegal column names: #{illegal_names}. Please rename these columns.")
|
41
|
+
end
|
42
|
+
|
43
|
+
(column_names - illegal_names).each do |name|
|
44
|
+
klass.define_singleton_method(name) do
|
45
|
+
klass.arel_table[name]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module ClassMethods
|
51
|
+
def skip_arable_columns!
|
52
|
+
class_variable_set(SKIP_ARABLE_COLUMNS_CLASS_VAR_NAME, true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def star
|
56
|
+
arel_table[Arel.star]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
ActiveSupport.on_load(:active_record) do |active_record|
|
62
|
+
def inherited(subclass)
|
63
|
+
super
|
64
|
+
|
65
|
+
subclass.extend(Arable::ClassMethods)
|
66
|
+
|
67
|
+
# include Arable only when the class has finished defining itself
|
68
|
+
ActiveSupport.on_load(subclass)
|
69
|
+
TracePoint.trace(:end) do |trace|
|
70
|
+
if subclass == trace.self
|
71
|
+
subclass.include(Arable)
|
72
|
+
trace.disable
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/sig/arable.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danielius Visockas
|
8
|
+
- Lukas Kairevičius
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-05-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- danieliusvisockas@gmail.com
|
17
|
+
- lumzdas@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".rspec"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- CHANGELOG.md
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/arable.rb
|
30
|
+
- lib/arable/version.rb
|
31
|
+
- sig/arable.rbs
|
32
|
+
homepage: https://github.com/dvisockas/arable
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
allowed_push_host: https://rubygems.org
|
37
|
+
homepage_uri: https://github.com/dvisockas/arable
|
38
|
+
source_code_uri: https://github.com/dvisockas/arable
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.6.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.3.7
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Shorthand syntax to acces your arel tables directly
|
58
|
+
test_files: []
|