activeadmin_active_resource 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 584701cd42eaef807c228819c00353358776a9cb
4
+ data.tar.gz: 5097463f09f5324a91cca9cb82f044c558126ca5
5
+ SHA512:
6
+ metadata.gz: 9b23e1c46e61285cb669612137df26c33137eeff216fdf8650fe1eda100f145a9cad5c062b2120a483b60784efb29580911d1c604e4f1099183aed6a3a80a860
7
+ data.tar.gz: 1c0e5e687dc4ff6de579d4d6b7e7aadb7ee2bcbc1998215368425e798a235f38ea768b2b655103f3988d50a8dae2f54aead18028831071a5316c97284be77c24
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ _misc/
2
+ Gemfile.lock
3
+ *.orig
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 Mattia Roccoberton
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/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # ActiveAdmin Active Resource [![Gem Version](https://badge.fury.io/rb/activeadmin_active_resource.svg)](https://badge.fury.io/rb/activeadmin_active_resource)
2
+
3
+ An Active Admin plugin to use Active Resource.
4
+
5
+ Data is fetched from an external API.
6
+
7
+ WARNING: this component is a Beta version, some Active Admin functionalities don't work as expected:
8
+
9
+ - Batch Action: not currently supported
10
+ - Filters: partially supported (see example)
11
+ - Edit: fields must be configured explicitly
12
+
13
+ ## Install
14
+
15
+ - Add to your Gemfile:
16
+ `gem 'activeadmin_active_resource'`
17
+ - Execute bundle
18
+
19
+ ## Example
20
+
21
+ - Post model:
22
+
23
+ ```rb
24
+ class Post < ActiveResource::Base
25
+ self.site = 'http://localhost:3000'
26
+
27
+ self.schema = {
28
+ id: :integer,
29
+ title: :string,
30
+ description: :text,
31
+ author_id: :integer,
32
+ category: :string,
33
+ dt: :datetime,
34
+ position: :float,
35
+ published: :boolean,
36
+ created_at: :datetime,
37
+ updated_at: :datetime,
38
+ }
39
+ end
40
+ ```
41
+
42
+ - Post admin config:
43
+
44
+ ```rb
45
+ ActiveAdmin.register Post do
46
+ # config.filters = false
47
+
48
+ filter :title_cont
49
+
50
+ controller do
51
+ def permitted_params
52
+ params.permit!
53
+ end
54
+ end
55
+
56
+ form do |f|
57
+ f.inputs do
58
+ f.input :id, as: :hidden unless f.object.new_record?
59
+ f.input :title
60
+ end
61
+ f.actions
62
+ end
63
+ end
64
+ ```
65
+
66
+ ## Do you like it? Star it!
67
+
68
+ If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
69
+
70
+ Take a look at [other ActiveAdmin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious.
71
+
72
+ ## Contributors
73
+
74
+ - [Mattia Roccoberton](http://blocknot.es) - creator, maintainer
75
+
76
+ ## License
77
+
78
+ [MIT](LICENSE.txt)
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'activeadmin/active_resource/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'activeadmin_active_resource'
7
+ spec.version = ActiveAdmin::ActiveResource::VERSION
8
+ spec.summary = 'Active Resource for ActiveAdmin'
9
+ spec.description = 'An Active Admin plugin to use Active Resource'
10
+ spec.license = 'MIT'
11
+ spec.authors = ['Mattia Roccoberton']
12
+ spec.email = 'mat@blocknot.es'
13
+ spec.homepage = 'https://github.com/blocknotes/activeadmin_active_resource'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_runtime_dependency 'activeadmin', '~> 1.0'
19
+ spec.add_runtime_dependency 'activeresource', '~> 5.0'
20
+ end
@@ -0,0 +1,104 @@
1
+ require 'active_admin'
2
+
3
+ class ActiveAdmin::ActiveResource::Engine < ::Rails::Engine
4
+ engine_name 'activeadmin_active_resource'
5
+ end
6
+
7
+ ::ActiveResource::Base.class_eval do
8
+ attr_writer :inheritance_column
9
+
10
+ self.collection_parser = ActiveAdmin::ActiveResource::Results
11
+
12
+ class << self
13
+ def _ransackers
14
+ {}
15
+ end
16
+
17
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-column_names
18
+ def column_names
19
+ @column_names ||= columns.map(&:name)
20
+ end
21
+
22
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-columns
23
+ def columns
24
+ @columns ||= self.known_attributes.map { |col| OpenStruct.new( name: col ) }
25
+ end
26
+
27
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaCache.html#method-i-columns_hash
28
+ # def columns_hash
29
+ # # { 'title' => OpenStruct.new( type: :string ) }
30
+ # {}
31
+ # end
32
+
33
+ def find_all( options = {} )
34
+ prefix_options, query_options = split_options(options[:params])
35
+ path = collection_path(prefix_options, query_options)
36
+ @connection_response = connection.get(path, headers)
37
+ instantiate_collection( (format.decode( @connection_response.body ) || []), query_options, prefix_options )
38
+ end
39
+
40
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-find_by
41
+ def find_by( arg, *args )
42
+ arg && arg['id'] ? self.find( arg['id'] ) : self.find( :first, arg )
43
+ end
44
+
45
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-inheritance_column
46
+ def inheritance_column
47
+ ( @inheritance_column ||= nil ) || 'type'
48
+ end
49
+
50
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-quoted_table_name
51
+ def quoted_table_name
52
+ @quoted_table_name ||= "\"#{self.to_s.tableize}\""
53
+ end
54
+
55
+ def page( page )
56
+ @page = page.to_i
57
+ @page = 1 if @page < 1
58
+ # results = find_all params: {page: page, per_page: 10, order: @order}
59
+ # results.current_page = page ? page.to_i : 1
60
+ # results.limit_value = @connection_response['pagination-limit'].to_i
61
+ # results.total_count = @connection_response['pagination-totalcount'].to_i
62
+ # results.total_pages = ( results.total_count.to_f / results.limit_value ).ceil
63
+ # results
64
+ self
65
+ end
66
+
67
+ def per( page_count )
68
+ @page_count = page_count.to_i
69
+ # self
70
+ results
71
+ end
72
+
73
+ def ransack( params = {}, options = {} )
74
+ @ransack_params = params.blank? ? {} : params.permit!.to_h
75
+ OpenStruct.new( conditions: {}, object: OpenStruct.new( klass: self ), result: self )
76
+ end
77
+
78
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/Reflection/ClassMethods.html#method-i-reflect_on_all_associations
79
+ def reflect_on_all_associations( macro = nil )
80
+ []
81
+ end
82
+
83
+ # -> http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-reorder
84
+ def reorder( sql )
85
+ @order = sql
86
+ self
87
+ end
88
+
89
+ def results
90
+ results = find_all params: {page: @page, per_page: @page_count, order: @order, q: @ransack_params}
91
+ results.current_page = @page
92
+ results.limit_value = @connection_response['pagination-limit'].to_i
93
+ results.total_count = @connection_response['pagination-totalcount'].to_i
94
+ results.total_pages = ( results.total_count.to_f / results.limit_value ).ceil
95
+ results
96
+ end
97
+ end
98
+ end
99
+
100
+ ::ActiveResource::Connection.class_eval do
101
+ def quote_column_name( column_name )
102
+ column_name
103
+ end
104
+ end
@@ -0,0 +1,19 @@
1
+ class ActiveAdmin::ActiveResource::Results < ActiveResource::Collection
2
+ attr_accessor :current_page, :limit_value, :total_count, :total_pages
3
+
4
+ def initialize( elements = [] )
5
+ super elements
6
+ @limit_value = ActiveAdmin.application.default_per_page
7
+ @total_count = 0
8
+ @total_pages = 1
9
+ @current_page = 1
10
+ end
11
+
12
+ def except( *params )
13
+ self
14
+ end
15
+
16
+ def group_values
17
+ nil
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveAdmin
2
+ module ActiveResource
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'activeadmin/active_resource/results'
2
+ require 'activeadmin/active_resource/engine'
@@ -0,0 +1,2 @@
1
+ require 'active_resource'
2
+ require 'activeadmin/active_resource'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin_active_resource
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mattia Roccoberton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activeresource
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ description: An Active Admin plugin to use Active Resource
42
+ email: mat@blocknot.es
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - activeadmin_active_resource.gemspec
53
+ - lib/activeadmin/active_resource.rb
54
+ - lib/activeadmin/active_resource/engine.rb
55
+ - lib/activeadmin/active_resource/results.rb
56
+ - lib/activeadmin/active_resource/version.rb
57
+ - lib/activeadmin_active_resource.rb
58
+ homepage: https://github.com/blocknotes/activeadmin_active_resource
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Active Resource for ActiveAdmin
82
+ test_files: []