bitia-rails 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/checks.yml +35 -0
- data/.github/workflows/publish_gem.yml +17 -0
- data/.gitignore +7 -0
- data/.rspec +4 -0
- data/.rubocop.yml +17 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +186 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +22 -0
- data/app/controllers/bitia/api_controller.rb +164 -0
- data/app/controllers/concerns/resourceable.rb +41 -0
- data/app/views/bitia/api/create.json.jbuilder +13 -0
- data/app/views/bitia/api/destroy.json.jbuilder +12 -0
- data/app/views/bitia/api/index.json.jbuilder +7 -0
- data/app/views/bitia/api/new.json.jbuilder +7 -0
- data/app/views/bitia/api/show.json.jbuilder +7 -0
- data/app/views/bitia/api/update.json.jbuilder +12 -0
- data/bin/rails +25 -0
- data/bitia-rails.gemspec +25 -0
- data/config/routes.rb +2 -0
- data/lib/bitia.rb +5 -0
- data/lib/bitia/engine.rb +11 -0
- data/lib/bitia/version.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 24c398854bca6c786ff70c898d741a3bde2bc2d2ba95849fc526fb1dd5a5288c
|
|
4
|
+
data.tar.gz: 4a5ec03ff2efb4ac6881ea802c8c2e7ce32b545ad5a1936e09319ffefb9bf337
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b38c419c7e5362fad376fe1c6a70a368b2af21ce77243b73014556100c8fd20b88d253dd6830754683582f5a2510f0d417b95d095fed374c25ce6b476fff5a10
|
|
7
|
+
data.tar.gz: ad1ca766fa2fceefa74e368b1e5e33174ab86070a87d626318eb2fd4d2f03b1be356412de7c5cff1c3d1b0dbe7f95a5c520b04512fb2d5622f822285c3bda5fd
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Checks
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v2
|
|
11
|
+
- name: Set up dependencies
|
|
12
|
+
run: |
|
|
13
|
+
sudo apt-get update -y
|
|
14
|
+
sudo apt-get install -y libsqlite3-dev
|
|
15
|
+
- name: Set up Ruby 2.7
|
|
16
|
+
uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: 2.7
|
|
19
|
+
- name: Cache gems
|
|
20
|
+
uses: actions/cache@v1
|
|
21
|
+
with:
|
|
22
|
+
path: vendor/bundle
|
|
23
|
+
key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
|
|
24
|
+
restore-keys: |
|
|
25
|
+
${{ runner.os }}-rubocop-
|
|
26
|
+
- name: Install gems
|
|
27
|
+
run: |
|
|
28
|
+
bundle config path vendor/bundle
|
|
29
|
+
bundle install --jobs 4 --retry 3
|
|
30
|
+
- name: Run RuboCop
|
|
31
|
+
run: bundle exec rubocop --parallel
|
|
32
|
+
- name: Prepare to RSpec
|
|
33
|
+
run: bundle exec rake db:create db:schema:load RAILS_ENV=test
|
|
34
|
+
- name: Run RSpec
|
|
35
|
+
run: bundle exec rspec
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: "Build and publish gem"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v1
|
|
13
|
+
- name: Build and publish gem
|
|
14
|
+
uses: jstastny/publish-gem-to-github@v1.0
|
|
15
|
+
with:
|
|
16
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
17
|
+
owner: bitia-ru
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Style/FrozenStringLiteralComment: { Enabled: false }
|
|
2
|
+
Layout/LineLength:
|
|
3
|
+
Max: 100
|
|
4
|
+
Metrics/MethodLength: { Enabled: false }
|
|
5
|
+
Metrics/ModuleLength: { Enabled: false }
|
|
6
|
+
Metrics/BlockLength: { Enabled: false }
|
|
7
|
+
Metrics/AbcSize: { Enabled: false }
|
|
8
|
+
Metrics/CyclomaticComplexity: { Enabled: false }
|
|
9
|
+
Metrics/PerceivedComplexity: { Enabled: false }
|
|
10
|
+
Metrics/BlockNesting: { Enabled: false }
|
|
11
|
+
Metrics/ClassLength: { Enabled: false }
|
|
12
|
+
Style/Documentation: { Enabled: false }
|
|
13
|
+
Style/NumericPredicate: { Enabled: false }
|
|
14
|
+
Style/ClassAndModuleChildren: { Enabled: false }
|
|
15
|
+
Style/SpecialGlobalVars: { Enabled: false }
|
|
16
|
+
Style/AndOr: { Enabled: false }
|
|
17
|
+
Style/Lambda: { Enabled: false }
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
bitia-rails (0.3.0)
|
|
5
|
+
rails (~> 5.2.4, >= 5.2.4.3)
|
|
6
|
+
responders
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actioncable (5.2.4.3)
|
|
12
|
+
actionpack (= 5.2.4.3)
|
|
13
|
+
nio4r (~> 2.0)
|
|
14
|
+
websocket-driver (>= 0.6.1)
|
|
15
|
+
actionmailer (5.2.4.3)
|
|
16
|
+
actionpack (= 5.2.4.3)
|
|
17
|
+
actionview (= 5.2.4.3)
|
|
18
|
+
activejob (= 5.2.4.3)
|
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
|
20
|
+
rails-dom-testing (~> 2.0)
|
|
21
|
+
actionpack (5.2.4.3)
|
|
22
|
+
actionview (= 5.2.4.3)
|
|
23
|
+
activesupport (= 5.2.4.3)
|
|
24
|
+
rack (~> 2.0, >= 2.0.8)
|
|
25
|
+
rack-test (>= 0.6.3)
|
|
26
|
+
rails-dom-testing (~> 2.0)
|
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
28
|
+
actionview (5.2.4.3)
|
|
29
|
+
activesupport (= 5.2.4.3)
|
|
30
|
+
builder (~> 3.1)
|
|
31
|
+
erubi (~> 1.4)
|
|
32
|
+
rails-dom-testing (~> 2.0)
|
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
34
|
+
activejob (5.2.4.3)
|
|
35
|
+
activesupport (= 5.2.4.3)
|
|
36
|
+
globalid (>= 0.3.6)
|
|
37
|
+
activemodel (5.2.4.3)
|
|
38
|
+
activesupport (= 5.2.4.3)
|
|
39
|
+
activerecord (5.2.4.3)
|
|
40
|
+
activemodel (= 5.2.4.3)
|
|
41
|
+
activesupport (= 5.2.4.3)
|
|
42
|
+
arel (>= 9.0)
|
|
43
|
+
activestorage (5.2.4.3)
|
|
44
|
+
actionpack (= 5.2.4.3)
|
|
45
|
+
activerecord (= 5.2.4.3)
|
|
46
|
+
marcel (~> 0.3.1)
|
|
47
|
+
activesupport (5.2.4.3)
|
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
49
|
+
i18n (>= 0.7, < 2)
|
|
50
|
+
minitest (~> 5.1)
|
|
51
|
+
tzinfo (~> 1.1)
|
|
52
|
+
arel (9.0.0)
|
|
53
|
+
ast (2.4.1)
|
|
54
|
+
builder (3.2.4)
|
|
55
|
+
coderay (1.1.3)
|
|
56
|
+
concurrent-ruby (1.1.6)
|
|
57
|
+
crass (1.0.6)
|
|
58
|
+
diff-lcs (1.4.4)
|
|
59
|
+
erubi (1.9.0)
|
|
60
|
+
factory_bot (6.0.2)
|
|
61
|
+
activesupport (>= 5.0.0)
|
|
62
|
+
factory_bot_rails (6.0.0)
|
|
63
|
+
factory_bot (~> 6.0.0)
|
|
64
|
+
railties (>= 5.0.0)
|
|
65
|
+
globalid (0.4.2)
|
|
66
|
+
activesupport (>= 4.2.0)
|
|
67
|
+
i18n (1.8.3)
|
|
68
|
+
concurrent-ruby (~> 1.0)
|
|
69
|
+
jbuilder (2.10.0)
|
|
70
|
+
activesupport (>= 5.0.0)
|
|
71
|
+
loofah (2.6.0)
|
|
72
|
+
crass (~> 1.0.2)
|
|
73
|
+
nokogiri (>= 1.5.9)
|
|
74
|
+
mail (2.7.1)
|
|
75
|
+
mini_mime (>= 0.1.1)
|
|
76
|
+
marcel (0.3.3)
|
|
77
|
+
mimemagic (~> 0.3.2)
|
|
78
|
+
method_source (1.0.0)
|
|
79
|
+
mimemagic (0.3.5)
|
|
80
|
+
mini_mime (1.0.2)
|
|
81
|
+
mini_portile2 (2.4.0)
|
|
82
|
+
minitest (5.14.1)
|
|
83
|
+
nio4r (2.5.2)
|
|
84
|
+
nokogiri (1.10.10)
|
|
85
|
+
mini_portile2 (~> 2.4.0)
|
|
86
|
+
parallel (1.19.2)
|
|
87
|
+
parser (2.7.1.4)
|
|
88
|
+
ast (~> 2.4.1)
|
|
89
|
+
pry (0.13.1)
|
|
90
|
+
coderay (~> 1.1)
|
|
91
|
+
method_source (~> 1.0)
|
|
92
|
+
rack (2.2.3)
|
|
93
|
+
rack-test (1.1.0)
|
|
94
|
+
rack (>= 1.0, < 3)
|
|
95
|
+
rails (5.2.4.3)
|
|
96
|
+
actioncable (= 5.2.4.3)
|
|
97
|
+
actionmailer (= 5.2.4.3)
|
|
98
|
+
actionpack (= 5.2.4.3)
|
|
99
|
+
actionview (= 5.2.4.3)
|
|
100
|
+
activejob (= 5.2.4.3)
|
|
101
|
+
activemodel (= 5.2.4.3)
|
|
102
|
+
activerecord (= 5.2.4.3)
|
|
103
|
+
activestorage (= 5.2.4.3)
|
|
104
|
+
activesupport (= 5.2.4.3)
|
|
105
|
+
bundler (>= 1.3.0)
|
|
106
|
+
railties (= 5.2.4.3)
|
|
107
|
+
sprockets-rails (>= 2.0.0)
|
|
108
|
+
rails-dom-testing (2.0.3)
|
|
109
|
+
activesupport (>= 4.2.0)
|
|
110
|
+
nokogiri (>= 1.6)
|
|
111
|
+
rails-html-sanitizer (1.3.0)
|
|
112
|
+
loofah (~> 2.3)
|
|
113
|
+
railties (5.2.4.3)
|
|
114
|
+
actionpack (= 5.2.4.3)
|
|
115
|
+
activesupport (= 5.2.4.3)
|
|
116
|
+
method_source
|
|
117
|
+
rake (>= 0.8.7)
|
|
118
|
+
thor (>= 0.19.0, < 2.0)
|
|
119
|
+
rainbow (3.0.0)
|
|
120
|
+
rake (13.0.1)
|
|
121
|
+
regexp_parser (1.7.1)
|
|
122
|
+
responders (3.0.1)
|
|
123
|
+
actionpack (>= 5.0)
|
|
124
|
+
railties (>= 5.0)
|
|
125
|
+
rexml (3.2.4)
|
|
126
|
+
rspec-core (3.9.2)
|
|
127
|
+
rspec-support (~> 3.9.3)
|
|
128
|
+
rspec-expectations (3.9.2)
|
|
129
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
130
|
+
rspec-support (~> 3.9.0)
|
|
131
|
+
rspec-mocks (3.9.1)
|
|
132
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
133
|
+
rspec-support (~> 3.9.0)
|
|
134
|
+
rspec-rails (4.0.1)
|
|
135
|
+
actionpack (>= 4.2)
|
|
136
|
+
activesupport (>= 4.2)
|
|
137
|
+
railties (>= 4.2)
|
|
138
|
+
rspec-core (~> 3.9)
|
|
139
|
+
rspec-expectations (~> 3.9)
|
|
140
|
+
rspec-mocks (~> 3.9)
|
|
141
|
+
rspec-support (~> 3.9)
|
|
142
|
+
rspec-support (3.9.3)
|
|
143
|
+
rubocop (0.88.0)
|
|
144
|
+
parallel (~> 1.10)
|
|
145
|
+
parser (>= 2.7.1.1)
|
|
146
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
147
|
+
regexp_parser (>= 1.7)
|
|
148
|
+
rexml
|
|
149
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
|
150
|
+
ruby-progressbar (~> 1.7)
|
|
151
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
152
|
+
rubocop-ast (0.1.0)
|
|
153
|
+
parser (>= 2.7.0.1)
|
|
154
|
+
ruby-progressbar (1.10.1)
|
|
155
|
+
sprockets (4.0.2)
|
|
156
|
+
concurrent-ruby (~> 1.0)
|
|
157
|
+
rack (> 1, < 3)
|
|
158
|
+
sprockets-rails (3.2.1)
|
|
159
|
+
actionpack (>= 4.0)
|
|
160
|
+
activesupport (>= 4.0)
|
|
161
|
+
sprockets (>= 3.0.0)
|
|
162
|
+
sqlite3 (1.4.2)
|
|
163
|
+
thor (1.0.1)
|
|
164
|
+
thread_safe (0.3.6)
|
|
165
|
+
tzinfo (1.2.7)
|
|
166
|
+
thread_safe (~> 0.1)
|
|
167
|
+
unicode-display_width (1.7.0)
|
|
168
|
+
websocket-driver (0.7.3)
|
|
169
|
+
websocket-extensions (>= 0.1.0)
|
|
170
|
+
websocket-extensions (0.1.5)
|
|
171
|
+
|
|
172
|
+
PLATFORMS
|
|
173
|
+
ruby
|
|
174
|
+
|
|
175
|
+
DEPENDENCIES
|
|
176
|
+
bitia-rails!
|
|
177
|
+
factory_bot_rails
|
|
178
|
+
jbuilder
|
|
179
|
+
pry
|
|
180
|
+
responders
|
|
181
|
+
rspec-rails
|
|
182
|
+
rubocop
|
|
183
|
+
sqlite3
|
|
184
|
+
|
|
185
|
+
BUNDLED WITH
|
|
186
|
+
1.17.3
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2020 ALev
|
|
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.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Bitia'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
19
|
+
|
|
20
|
+
load 'rails/tasks/statistics.rake'
|
|
21
|
+
|
|
22
|
+
require 'bundler/gem_tasks'
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Bitia::ApiController < ActionController::Base
|
|
4
|
+
include ActionController::MimeResponds
|
|
5
|
+
|
|
6
|
+
respond_to :json
|
|
7
|
+
|
|
8
|
+
include Resourceable
|
|
9
|
+
|
|
10
|
+
before_action :purable_initialize_metavars
|
|
11
|
+
before_action :purable_prepare_resources
|
|
12
|
+
|
|
13
|
+
def index
|
|
14
|
+
all = resources.count
|
|
15
|
+
if params.include? :offset
|
|
16
|
+
instance_variable_set("@#{resources_name}", resources.offset(params[:offset]))
|
|
17
|
+
end
|
|
18
|
+
if params.include? :limit
|
|
19
|
+
instance_variable_set("@#{resources_name}", resources.limit(Integer(params[:limit])))
|
|
20
|
+
end
|
|
21
|
+
@metadata[:all] = all unless @metadata[:all]
|
|
22
|
+
|
|
23
|
+
render
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def new
|
|
27
|
+
authorize resource
|
|
28
|
+
render
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def show
|
|
32
|
+
authorize resource
|
|
33
|
+
render
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def create
|
|
37
|
+
pure_create_or_update
|
|
38
|
+
render
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def update
|
|
42
|
+
pure_create_or_update
|
|
43
|
+
render
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def destroy
|
|
47
|
+
authorize resource
|
|
48
|
+
resource.destroy!
|
|
49
|
+
|
|
50
|
+
render
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def pure_filter(param)
|
|
54
|
+
return unless params[param].present?
|
|
55
|
+
|
|
56
|
+
instance_variable_get("@#{resources_name}").where!(param => params[param])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
helper_method :pure_filter
|
|
60
|
+
|
|
61
|
+
def purable_model
|
|
62
|
+
self.class.send(:purable_model)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
helper_method :purable_model
|
|
66
|
+
|
|
67
|
+
def purable_model_chain
|
|
68
|
+
self.class.send(:purable_model_chain)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
helper_method :purable_model
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
def purable_initialize_metavars
|
|
76
|
+
@resource = purable_model.name.underscore.to_sym
|
|
77
|
+
@metadata ||= {}
|
|
78
|
+
nil
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def purable_prepare_resources
|
|
82
|
+
@current_user = User.find(params[:user_id]) if params.include? :user_id
|
|
83
|
+
|
|
84
|
+
if params[:action] == 'index'
|
|
85
|
+
instance_variable_set("@#{resources_name}", purable_relation.all)
|
|
86
|
+
elsif params[:action] == 'show'
|
|
87
|
+
id = params[:id].present? ? params[:id] : purable_param_id
|
|
88
|
+
|
|
89
|
+
instance_variable_set(
|
|
90
|
+
"@#{resource_name}", id ? purable_relation.find(id) : purable_relation.new
|
|
91
|
+
)
|
|
92
|
+
elsif purable_resource_params.is_a?(Array)
|
|
93
|
+
resources = purable_resource_params.map do |params|
|
|
94
|
+
if params[:id].present? && params[:id] != 'self'
|
|
95
|
+
purable_relation.find(params[:id]).tap { |r| r.assign_attributes(params) }
|
|
96
|
+
else
|
|
97
|
+
purable_relation.new(params)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
instance_variable_set("@#{resources_name}", resources)
|
|
102
|
+
else
|
|
103
|
+
resource = purable_relation.new(purable_resource_params)
|
|
104
|
+
instance_variable_set("@#{resource_name}", resource)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def purable_param_id
|
|
109
|
+
purable_resource_params[:id]
|
|
110
|
+
rescue StandardError
|
|
111
|
+
nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def purable_relation
|
|
115
|
+
purable_model_chain.inject(nil) do |m, pm|
|
|
116
|
+
if m.nil?
|
|
117
|
+
pm.singularize.classify.constantize
|
|
118
|
+
elsif params.include?("#{m.to_s.underscore}_id")
|
|
119
|
+
m.find(params["#{m.to_s.underscore}_id"]).send(pm.to_sym) # TODO: uncovered
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def pure_create_or_update
|
|
125
|
+
if resources.present?
|
|
126
|
+
purable_model.transaction { resources.each(&:save!) }
|
|
127
|
+
else
|
|
128
|
+
resource.save!
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def purable_resource_params
|
|
133
|
+
send :"#{resource_name}_params"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def self.purable_model_chain
|
|
137
|
+
controller_path = self.controller_path.dup
|
|
138
|
+
|
|
139
|
+
if defined?(controller_prefix) and controller_prefix.present?
|
|
140
|
+
prefix_s = controller_prefix.map(&:to_s).join('/')
|
|
141
|
+
raise StandardError, 'Bad prefix' if controller_path.index(prefix_s) != 0
|
|
142
|
+
|
|
143
|
+
controller_path.sub! "#{prefix_s}/", ''
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
controller_path.split('/')
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
private_class_method :purable_model_chain
|
|
150
|
+
|
|
151
|
+
def self.purable_model
|
|
152
|
+
purable_model_chain.last.singularize.classify.constantize
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private_class_method :purable_model
|
|
156
|
+
|
|
157
|
+
def self.inherited(klass)
|
|
158
|
+
resource_accessor_name = klass.send(:purable_model).name.underscore.to_sym
|
|
159
|
+
klass.define_method(resource_accessor_name) { resource }
|
|
160
|
+
klass.helper_method resource_accessor_name
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
private_class_method :inherited
|
|
164
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Resourceable
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
helper_method :resource_name
|
|
6
|
+
|
|
7
|
+
def resource_name
|
|
8
|
+
@resource
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
helper_method :resources_name
|
|
12
|
+
|
|
13
|
+
def resources_name
|
|
14
|
+
@resource.to_s.pluralize.to_sym
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
helper_method :resource
|
|
18
|
+
|
|
19
|
+
def resource
|
|
20
|
+
instance_variable_get(:"@#{resource_name}")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
helper_method :resources
|
|
24
|
+
|
|
25
|
+
def resources
|
|
26
|
+
instance_variable_get(:"@#{resources_name}")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.controller_prefix
|
|
30
|
+
@@controller_prefix ||= [] # rubocop:disable Style/ClassVars
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.controller_prefix_push(prefix)
|
|
34
|
+
controller_prefix.push(*prefix.to_s.split('/').map(&:to_sym))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def controller_prefix
|
|
38
|
+
self.class.controller_prefix
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
json.metadata do
|
|
2
|
+
json.merge! @metadata
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
if resources.present?
|
|
6
|
+
json.payload do
|
|
7
|
+
json.array!(resources, partial: "api/v1/#{resources_name}/#{resource_name}", as: resource_name)
|
|
8
|
+
end
|
|
9
|
+
else
|
|
10
|
+
json.payload do
|
|
11
|
+
json.partial! "api/v1/#{resources_name}/#{resource_name}", locals: { resource_name => resource }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
json.metadata do
|
|
2
|
+
json.merge! @metadata
|
|
3
|
+
end
|
|
4
|
+
if resources.present?
|
|
5
|
+
json.payload do
|
|
6
|
+
json.array!(resources, partial: "api/v1/#{resources_name}/#{resource_name}", as: resource_name)
|
|
7
|
+
end
|
|
8
|
+
else
|
|
9
|
+
json.payload do
|
|
10
|
+
json.partial! "api/v1/#{resources_name}/#{resource_name}", locals: { resource_name => resource }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
json.metadata do
|
|
2
|
+
json.merge! @metadata
|
|
3
|
+
end
|
|
4
|
+
if resources.present?
|
|
5
|
+
json.payload do
|
|
6
|
+
json.array!(resources, partial: "api/v1/#{resources_name}/#{resource_name}", as: resource_name)
|
|
7
|
+
end
|
|
8
|
+
else
|
|
9
|
+
json.payload do
|
|
10
|
+
json.partial! "api/v1/#{resources_name}/#{resource_name}", locals: { resource_name => resource }
|
|
11
|
+
end
|
|
12
|
+
end
|
data/bin/rails
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
|
+
# installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/bitia/engine', __dir__)
|
|
7
|
+
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
|
|
8
|
+
|
|
9
|
+
# Set up gems listed in the Gemfile.
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
12
|
+
|
|
13
|
+
require 'rails'
|
|
14
|
+
# Pick the frameworks you want:
|
|
15
|
+
require 'active_model/railtie'
|
|
16
|
+
require 'active_job/railtie'
|
|
17
|
+
require 'active_record/railtie'
|
|
18
|
+
require 'active_storage/engine'
|
|
19
|
+
require 'action_controller/railtie'
|
|
20
|
+
require 'action_mailer/railtie'
|
|
21
|
+
require 'action_view/railtie'
|
|
22
|
+
require 'action_cable/engine'
|
|
23
|
+
require 'sprockets/railtie'
|
|
24
|
+
# require "rails/test_unit/railtie"
|
|
25
|
+
require 'rails/engine/commands'
|
data/bitia-rails.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
$:.push File.expand_path('lib', __dir__)
|
|
2
|
+
|
|
3
|
+
require 'bitia/version'
|
|
4
|
+
|
|
5
|
+
# Describe your gem and declare its dependencies:
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'bitia-rails'
|
|
8
|
+
spec.version = Bitia::VERSION
|
|
9
|
+
spec.authors = ['Artem Levenkov']
|
|
10
|
+
spec.email = ['alev@bitia.ru']
|
|
11
|
+
spec.summary = 'Common modules for Bitia’s Rails projects'
|
|
12
|
+
spec.homepage = 'https://github.com/bitia-ru/bitia-rails'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
spec.add_dependency 'rails', '~> 5.2.4', '>= 5.2.4.3'
|
|
20
|
+
spec.add_dependency 'responders'
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency 'factory_bot_rails'
|
|
23
|
+
spec.add_development_dependency 'rspec-rails'
|
|
24
|
+
spec.add_development_dependency 'sqlite3'
|
|
25
|
+
end
|
data/config/routes.rb
ADDED
data/lib/bitia.rb
ADDED
data/lib/bitia/engine.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bitia-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.4.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Artem Levenkov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 5.2.4
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 5.2.4.3
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 5.2.4
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 5.2.4.3
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: responders
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: factory_bot_rails
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rspec-rails
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: sqlite3
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
description:
|
|
90
|
+
email:
|
|
91
|
+
- alev@bitia.ru
|
|
92
|
+
executables: []
|
|
93
|
+
extensions: []
|
|
94
|
+
extra_rdoc_files: []
|
|
95
|
+
files:
|
|
96
|
+
- ".github/workflows/checks.yml"
|
|
97
|
+
- ".github/workflows/publish_gem.yml"
|
|
98
|
+
- ".gitignore"
|
|
99
|
+
- ".rspec"
|
|
100
|
+
- ".rubocop.yml"
|
|
101
|
+
- Gemfile
|
|
102
|
+
- Gemfile.lock
|
|
103
|
+
- MIT-LICENSE
|
|
104
|
+
- Rakefile
|
|
105
|
+
- app/controllers/bitia/api_controller.rb
|
|
106
|
+
- app/controllers/concerns/resourceable.rb
|
|
107
|
+
- app/views/bitia/api/create.json.jbuilder
|
|
108
|
+
- app/views/bitia/api/destroy.json.jbuilder
|
|
109
|
+
- app/views/bitia/api/index.json.jbuilder
|
|
110
|
+
- app/views/bitia/api/new.json.jbuilder
|
|
111
|
+
- app/views/bitia/api/show.json.jbuilder
|
|
112
|
+
- app/views/bitia/api/update.json.jbuilder
|
|
113
|
+
- bin/rails
|
|
114
|
+
- bitia-rails.gemspec
|
|
115
|
+
- config/routes.rb
|
|
116
|
+
- lib/bitia.rb
|
|
117
|
+
- lib/bitia/engine.rb
|
|
118
|
+
- lib/bitia/version.rb
|
|
119
|
+
homepage: https://github.com/bitia-ru/bitia-rails
|
|
120
|
+
licenses:
|
|
121
|
+
- MIT
|
|
122
|
+
metadata: {}
|
|
123
|
+
post_install_message:
|
|
124
|
+
rdoc_options: []
|
|
125
|
+
require_paths:
|
|
126
|
+
- lib
|
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
requirements: []
|
|
138
|
+
rubygems_version: 3.0.8
|
|
139
|
+
signing_key:
|
|
140
|
+
specification_version: 4
|
|
141
|
+
summary: Common modules for Bitia’s Rails projects
|
|
142
|
+
test_files: []
|