activeadmin-reform 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fb5f1cb1e6a8849bfe291cb6cf6ae4677ad0b84
4
- data.tar.gz: 1d26346817eae70a0132331bae9ef65f914225c7
3
+ metadata.gz: 8b2545bc177dc4826dabe211d5576f05e73d01f2
4
+ data.tar.gz: 2c5617517929323af7f300e7530b9e42fb6cf932
5
5
  SHA512:
6
- metadata.gz: b54c9baa7fa35c78ff9649a6ad4f209e1185695e1b1816a2a6c7335ec191cca72f487a8070c3ce490eccd565c0ecee03630343e7880eb65ba05f27fb9037f31e
7
- data.tar.gz: 2a3423e2ce7058c30652915c1299c42c22e560484f22f0815a22e53d252b82cd064a240cc878b0564f98f48a34a370b06d716f3da8968cbb1462db1a1663b471
6
+ metadata.gz: 0eb184257154729d4de672a81cb0c24fffba0baff550ae49719f7edb67bbe04f74a6481ffe991c18aecc6611b8295bbe1c16883488462a7554bfc893bc94dc14
7
+ data.tar.gz: 344759c4d353e38ad8e687bc7b852ef7d1862567fc60ad151bd5dc9cbdc5cd34d2a847dd3df9646d72c856f45d22c9ff00d951f43a08ce8f72ba882309457e3a
@@ -4,12 +4,12 @@ rvm:
4
4
  - ruby-head
5
5
  env:
6
6
  matrix:
7
- - RAILS_VERSION=3.2
8
- - RAILS_VERSION=4.2.4
9
- - RAILS_VERSION=master
7
+ - RAILS_VERSION=3.2 ACTIVEADMIN_VERSION=1.0.0.pre3
8
+ - RAILS_VERSION=4.2.4 ACTIVEADMIN_VERSION=1.2.0
9
+ - RAILS_VERSION=master ACTIVEADMIN_VERSION=1.2.0
10
10
  matrix:
11
11
  allow_failures:
12
- - env: RAILS_VERSION=master
12
+ - env: RAILS_VERSION=master ACTIVEADMIN_VERSION=1.2.0
13
13
  - rvm: ruby-head
14
14
  before_install: gem install bundler -v 1.10.6
15
15
  install:
@@ -1,3 +1,7 @@
1
+ # 0.4.0
2
+
3
+ * Support ActiveAdmin 1.2.0
4
+
1
5
  # 0.3.0
2
6
 
3
7
  * Form pre-population from URL parameters in ActiveAdmin controllers
data/Gemfile CHANGED
@@ -5,9 +5,10 @@ require File.expand_path 'spec/support/detect_rails_version', File.dirname(__FIL
5
5
  gemspec
6
6
  group :test do
7
7
  gem 'rails', detect_rails_version
8
- gem 'activeadmin', github: 'activeadmin', ref: 'ba285ea2fc23ade108ed582134cae8c641f910a4'
8
+ gem 'activeadmin', ENV['ACTIVEADMIN_VERSION']
9
+ gem 'jquery-ui-rails', '5.0.5'
9
10
  gem 'sqlite3', '~> 1.3.11'
10
- gem 'rspec-rails', '~> 3.4.0'
11
+ gem 'rspec-rails'
11
12
  gem 'test-unit', '~> 3.0' # Rails 3.2 support
12
13
 
13
14
  gem 'launchy', '~> 2.4.3'
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'activeadmin-reform'
7
- spec.version = '0.3.0'
7
+ spec.version = '0.4.0'
8
8
  spec.authors = ['Artyom Bolshakov']
9
9
  spec.email = ['abolshakov@spbtv.com']
10
10
 
@@ -6,6 +6,6 @@ module ActiveAdmin
6
6
  module Reform
7
7
  require_relative 'reform/engine'
8
8
  require_relative 'reform/active_record'
9
- require_relative 'reform/form_builder'
9
+ require_relative 'reform/reflection'
10
10
  end
11
11
  end
@@ -27,6 +27,12 @@ module ActiveAdmin
27
27
  included do
28
28
  include ::Reform::Form::ModelReflections
29
29
  include ::Reform::Form::ActiveRecord
30
+
31
+ def self.reflect_on_association(name)
32
+ reflection = model_class.reflect_on_association(name) || return
33
+ property = definitions[name.to_s]
34
+ (@reflections ||= {})[name] ||= Reflection.new(reflection, (property[:nested] if property))
35
+ end
30
36
  end
31
37
 
32
38
  # Those methods are being used by activeadmin and are proxied to an inferred from name model
@@ -10,8 +10,6 @@ module ActiveAdmin
10
10
  require 'active_admin'
11
11
  require_relative 'dsl'
12
12
  require_relative 'forms'
13
-
14
- ActiveAdmin::FormBuilder.prepend FormBuilder
15
13
  end
16
14
  end
17
15
  end
@@ -0,0 +1,39 @@
1
+ module ActiveAdmin
2
+ module Reform
3
+ # Decorates `ActiveRecord::Reflection` instances.
4
+ # `ActiveAdmin::FormBuilder#has_many(name)` uses `object.class.reflect_on_association(name).klass.new`
5
+ # to build nested records.
6
+ class Reflection < SimpleDelegator
7
+ # @param reflection [ActiveRecord::Reflection]
8
+ # @param form_class [Class<ActiveAdmin::Reform::ActiveRecord>, nil]
9
+ def initialize(reflection, form_class)
10
+ super(reflection)
11
+ @form_class = form_class
12
+ end
13
+
14
+ # @return [Klass]
15
+ def klass
16
+ Klass.new(super, @form_class)
17
+ end
18
+
19
+ # Decorates `ActiveRecord::Base` subclasses.
20
+ class Klass < SimpleDelegator
21
+ # @param klass [Class<ActiveRecord::Base>]
22
+ # @param form_class [Class<ActiveAdmin::Reform::ActiveRecord>, nil]
23
+ def initialize(klass, form_class)
24
+ super(klass)
25
+ @form_klass = form_class
26
+ end
27
+
28
+ # @return [ActiveAdmin::Reform::ActiveRecord]
29
+ def new(*)
30
+ if @form_klass
31
+ @form_klass.new(super).tap(&:prepopulate!)
32
+ else
33
+ super
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom Bolshakov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2017-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -150,8 +150,8 @@ files:
150
150
  - lib/active_admin/reform/active_record.rb
151
151
  - lib/active_admin/reform/dsl.rb
152
152
  - lib/active_admin/reform/engine.rb
153
- - lib/active_admin/reform/form_builder.rb
154
153
  - lib/active_admin/reform/forms.rb
154
+ - lib/active_admin/reform/reflection.rb
155
155
  - lib/active_admin/reform/resource.rb
156
156
  - lib/active_admin/reform/resource_controller/data_access.rb
157
157
  - lib/activeadmin-reform.rb
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubyforge_project:
178
- rubygems_version: 2.5.1
178
+ rubygems_version: 2.5.2.1
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Integrates ActiveAdmin with Reform
@@ -1,47 +0,0 @@
1
- require 'reform/form/active_model/model_reflections'
2
-
3
- module ActiveAdmin
4
- module Reform
5
- # Patching ActiveAdmin::FormBuilder#js_for_has_many to provide nested forms support
6
- # https://github.com/activeadmin/activeadmin/blob/539fa4b/lib/active_admin/form_builder.rb#L123
7
- module FormBuilder
8
- private
9
-
10
- # Capture the ADD JS
11
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
12
- def js_for_has_many(assoc, form_block, template, new_record, class_string)
13
- assoc_reflection = object.class.reflect_on_association assoc
14
- assoc_name = assoc_reflection.klass.model_name
15
- placeholder = "NEW_#{assoc_name.to_s.underscore.upcase.gsub(%r{/}, '_')}_RECORD"
16
- opts = {
17
- for: [assoc, nested_object(assoc)],
18
- class: class_string,
19
- for_options: { child_index: placeholder },
20
- }
21
- html = template.capture { inputs_for_nested_attributes opts, &form_block }
22
- text = new_record.is_a?(String) ? new_record : I18n.t('active_admin.has_many_new', model: assoc_name.human)
23
-
24
- template.link_to text, '#', class: 'button has_many_add', data: {
25
- html: CGI.escapeHTML(html).html_safe, placeholder: placeholder
26
- }
27
- end
28
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
29
-
30
- def nested_form_class(assoc)
31
- if object.is_a?(::Reform::Form) && (property = object.class.definitions[assoc.to_s]) &&
32
- (nested_form = property[:nested]) < ::Reform::Form
33
- nested_form
34
- end
35
- end
36
-
37
- def nested_object(assoc)
38
- assoc_reflection = object.class.reflect_on_association assoc
39
- if (nested_form = nested_form_class(assoc))
40
- nested_form.new(assoc_reflection.klass.new).tap(&:prepopulate!)
41
- else
42
- assoc_reflection.klass.new
43
- end
44
- end
45
- end
46
- end
47
- end