simpleadmin 1.3.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0675ea91b122e24a24afa25b104acde743d73131
4
- data.tar.gz: cd45192036a06b9ba99e14339b32f31fdc33699e
3
+ metadata.gz: b711f46a984f06aac16634d1204c8698fa5daa3a
4
+ data.tar.gz: 6f87c6c89e6b7cd79525d4497414ec8e178932a4
5
5
  SHA512:
6
- metadata.gz: 6065774f68b225cd6028d1f20a9c2f7ea41a75adfd3d23a8e964ee1c93ac8930afdfb9a696a1696fdbafc42596c79dca84c9dfdbe963b6276848fa0fef98cf6e
7
- data.tar.gz: 929b39f84960a580dd8734d967e8183ecdf406958e4e414ace26b03d692fda526ac8b618bb77f299d2b368488911a9a17c6d3e9291ce1091d7e0e7fcc89d385c
6
+ metadata.gz: 46e480e28143e14c3237c41f535318ce31afabe079cdb8203c0e10e46e690f53ea101c17cc9ab8ce85fb13288314abc3df2f1f91d47635d7a5dea9f1162d09df
7
+ data.tar.gz: e57443cf34ec0b11aa38cd3f7e496363593176f53a53eeb43413e40a030a7b01bb6cee00bed4d509946fb6812cb27c3fcdf446c79b50fcd46158b46934231104
@@ -2,7 +2,12 @@ rvm:
2
2
  - 2.4.1
3
3
  language: ruby
4
4
 
5
+ addons:
6
+ postgresql: 9.4
7
+
5
8
  before_script:
6
9
  - psql -c 'create database example_app_test;' -U postgres
10
+ - gem install rails
11
+ - bundle install
7
12
 
8
13
  script: xvfb-run bundle exec rspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simpleadmin (1.2.7)
4
+ simpleadmin (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://secure.travis-ci.org/getsimpleadmin/simpleadmin.svg?branch=master)](http://travis-ci.org/getsimpleadmin/simpleadmin) [![codecov.io](https://codecov.io/github/getsimpleadmin/simpleadmin/coverage.svg?branch=master)](https://codecov.io/github/getsimpleadmin/simpleadmin?branch=master)[![Gem Version](https://badge.fury.io/rb/simpleadmin.svg)](https://rubygems.org/gems/simpleadmin)[![Maintainability](https://api.codeclimate.com/v1/badges/ca0015b11992514879c5/maintainability)](https://codeclimate.com/github/getsimpleadmin/simpleadmin/maintainability)
1
+ [![Build Status](https://secure.travis-ci.org/getsimpleadmin/simpleadmin-rails.svg?branch=master)](http://travis-ci.org/getsimpleadmin/simpleadmin-rails) [![codecov.io](https://codecov.io/github/getsimpleadmin/simpleadmin-rails/coverage.svg?branch=master)](https://codecov.io/github/getsimpleadmin/simpleadmin-rails?branch=master)[![Gem Version](https://badge.fury.io/rb/simpleadmin.svg)](https://rubygems.org/gems/simpleadmin)[![Maintainability](https://api.codeclimate.com/v1/badges/ca0015b11992514879c5/maintainability)](https://codeclimate.com/github/getsimpleadmin/simpleadmin-rails/maintainability)
2
2
 
3
3
  # [SimpleAdmin](http://getsimpleadmin.com)
4
4
 
@@ -6,7 +6,7 @@ SimpleAdmin is a service for people with no special skills that enables a simple
6
6
 
7
7
  You do not need to waste your time on development and technical support. The Simple Admin team will help you pay focus on the key thing – your Product.
8
8
 
9
- This is small API library to connect your application with SimpleAdmin service.
9
+ This is small API library to connect your application with SimpleAdmin service.
10
10
 
11
11
  [Example Application][demo]
12
12
 
@@ -1,5 +1,7 @@
1
1
  module SimpleAdmin
2
2
  class ResourcesController < BaseController
3
+ before_action :load_models!
4
+
3
5
  def index
4
6
  resource_service = ResourceService.new(model_klass, model_fields)
5
7
 
@@ -51,8 +53,20 @@ module SimpleAdmin
51
53
 
52
54
  private
53
55
 
56
+ def load_models!
57
+ Rails.application.load_models!
58
+ end
59
+
54
60
  def model_klass
55
- params[:model_klass_name].constantize
61
+ model = params[:model_klass_name].safe_constantize
62
+
63
+ if ApplicationRecord.descendants.include?(model)
64
+ model
65
+ elsif model.nil?
66
+ raise ArgumentError
67
+ else
68
+ raise SecurityError
69
+ end
56
70
  end
57
71
 
58
72
  def model_fields
@@ -0,0 +1,13 @@
1
+ module Rails
2
+ class Application
3
+ def load_models!
4
+ load_path = 'app/models'
5
+
6
+ matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
7
+
8
+ Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
9
+ require_dependency file.sub(matcher, '\1')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,7 @@
1
1
  require 'simpleadmin/version'
2
2
  require 'simpleadmin/engine'
3
3
 
4
+ require 'simpleadmin/application'
5
+
4
6
  module Simpleadmin
5
7
  end
@@ -0,0 +1,11 @@
1
+ class Rails::Application
2
+ def load_models!
3
+ load_path = 'app/models'
4
+
5
+ matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
6
+
7
+ Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
8
+ require_dependency file.sub(matcher, '\1')
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Simpleadmin
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Strukov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-19 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,7 +121,9 @@ files:
121
121
  - app/services/resource_service.rb
122
122
  - bin/console
123
123
  - bin/setup
124
+ - lib/rails/application.rb
124
125
  - lib/simpleadmin.rb
126
+ - lib/simpleadmin/application.rb
125
127
  - lib/simpleadmin/engine.rb
126
128
  - lib/simpleadmin/routes.rb
127
129
  - lib/simpleadmin/version.rb