activeadmin-reform 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 468418a4cf585ab1bb41b9d60ca56c9cc45e14c9
4
+ data.tar.gz: 8bbaa13bb9623f2d2c2d92fbf0a34400ea9e7b01
5
+ SHA512:
6
+ metadata.gz: 6163667b8130527b769689563994ed204bba99fccf8d098a06cbd47eef1fc2077005f322bd42f11f36cbaf2c9184058ec26f7459fd95309ee7b384c5c0043693
7
+ data.tar.gz: 3b25737954720af266c09e0d20bbf8b467fd29de55d33905d6d81a87bbc06ec4461ae14eb3b4670676fc9b98ce39b48e65fa83261e558c98cf4b40687e0348ef
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/dummy/
10
+ /tmp/
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-10-20 19:09:08 +0300 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ AllCops:
10
+ Exclude:
11
+ - spec/dummy/**/*
12
+
13
+ # Configuration parameters: AllowURI, URISchemes.
14
+ Metrics/LineLength:
15
+ Max: 120
16
+
17
+ Style/FileName:
18
+ Exclude:
19
+ - lib/activeadmin-reform.rb
20
+
21
+ Style/StringLiterals:
22
+ EnforcedStyle: single_quotes
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.2.2
5
+ - ruby-head
6
+ env:
7
+ matrix:
8
+ - RAILS_VERSION=3.2
9
+ - RAILS_VERSION=4.2.4
10
+ - RAILS_VERSION=master
11
+ matrix:
12
+ allow_failures:
13
+ - env: RAILS_VERSION=master
14
+ - rvm: ruby-head
15
+ before_install: gem install bundler -v 1.10.6
16
+ install:
17
+ - bundle install --retry=3
18
+ script:
19
+ - bundle exec rake
20
+ - bundle exec rubocop
21
+
22
+ addons:
23
+ code_climate:
24
+ repo_token: c326cca5984d0e32d2c6b5d9b985756ee9312f63fc6a9480fc9cfa55c454d68a
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,18 @@
1
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
2
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
3
+
4
+ To install this gem onto your local machine, run `bundle exec rake install`.
5
+ To release a new version, update the version number in `activeadmin-reform.gemspec`, and then
6
+ run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags,
7
+ and push the `.gem` file to [rubygems.org](https://rubygems.org).
8
+
9
+ If you need to test against specific rails version run `RAILS_VERSION=4.1.19 rake setup`.
10
+
11
+ 1. Fork it
12
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
13
+ 3. Prepare tests infrastructure (`RAILS_ENV=test bundle exec rake setup`)
14
+ 4. Make your changes and runs specs (`bundle exec rake`)
15
+ 5. Make sure your code stylish enough (`bundle exec rubocop`)
16
+ 6. Commit your changes (git commit -am 'Add some feature')
17
+ 7. Push to the branch (git push origin my-new-feature)
18
+ 8. Create Pull Request
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ require File.expand_path 'spec/support/detect_rails_version', File.dirname(__FILE__)
4
+
5
+ gemspec
6
+ group :test do
7
+ gem 'rails', detect_rails_version
8
+ gem 'activeadmin', github: 'activeadmin'
9
+ gem 'sqlite3'
10
+ gem 'rspec-rails'
11
+ gem 'test-unit', '~> 3.0' # Rails 3.2 support
12
+
13
+ gem 'launchy'
14
+ gem 'database_cleaner'
15
+ gem 'capybara'
16
+
17
+ gem 'codeclimate-test-reporter', require: nil
18
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Artem Bolshakov
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,82 @@
1
+ [![Build Status](https://travis-ci.org/bolshakov/activeadmin-reform.svg?branch=master)](https://travis-ci.org/bolshakov/activeadmin-reform)
2
+ [![Test Coverage](https://codeclimate.com/github/bolshakov/activeadmin-reform/badges/coverage.svg)](https://codeclimate.com/github/bolshakov/activeadmin-reform/coverage)
3
+ [![Code Climate](https://codeclimate.com/github/bolshakov/activeadmin-reform/badges/gpa.svg)](https://codeclimate.com/github/bolshakov/activeadmin-reform)
4
+ [![Gem Version](https://badge.fury.io/rb/activeadmin-reform.svg)](http://badge.fury.io/rb/activeadmin-reform)
5
+
6
+ # ActiveAdmin Reform
7
+
8
+ This gem adds integration between ActiveAdmin and [Reform](https://github.com/apotonick/reform). So you may
9
+ use form objects for your forms.
10
+
11
+ The purpose of this gem is to provide ability to define custom ActiveAdmin-specific validations for
12
+ your models. Using form objects allows you to define such validations without cluttering model's code
13
+ and simplifies building test objects.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'activeadmin-reform'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install activeadmin-reform
30
+
31
+ ## Usage
32
+
33
+ Define your from object
34
+
35
+ ```ruby
36
+ require 'reform'
37
+
38
+ class AuthorForm < Reform::Form
39
+ property :last_name, validates: { presence: true }
40
+ property :name
41
+ end
42
+ ```
43
+
44
+ Specify form class for ActiveAdmin resource:
45
+
46
+ ```ruby
47
+ ActiveAdmin.resource Author do
48
+ form_class AuthorForm
49
+
50
+ form do |f|
51
+ f.semantic_errors(*f.object.errors.keys)
52
+
53
+ f.inputs do
54
+ f.input :name
55
+ f.input :last_name
56
+ end
57
+
58
+ f.actions
59
+ end
60
+ end
61
+ ```
62
+
63
+ Now ActiveAdmin will use Reform form object to validate form.
64
+ Note, you must explicitly define form for resource.
65
+
66
+ By default ActiveAdmin will not use Reform, but if you want to reopen resource and
67
+ disable form object usage, pass `false` instead of class:
68
+
69
+ ```ruby
70
+ ActiveAdmin.resource Author do
71
+ form_class false
72
+ end
73
+ ```
74
+
75
+ ## Contributing
76
+
77
+ The [contributing guide](CONTRIBUTING.md) is a good place to start.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ desc 'Creates a test rails app for the specs to run against'
9
+ task :setup do
10
+ source_path = 'spec/dummy'
11
+ template = 'spec/support/rails_template.rb'
12
+ system <<-BASH
13
+ bundle exec rails new #{source_path} -m #{template} --skip-spring --skip-git --skip-turbolinks --skip-test-unit
14
+ BASH
15
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'activeadmin-reform'
7
+ spec.version = '0.1.1'
8
+ spec.authors = ['Artyom Bolshakov']
9
+ spec.email = ['abolshakov@spbtv.com']
10
+
11
+ spec.summary = 'Integrates ActiveAdmin with Reform'
12
+ spec.description = 'Provides ability to use form object in your ActiveAdmin application'
13
+ spec.homepage = 'https://github.com/bolshakov/activeadmin-reform'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rails', '>= 3.2'
22
+ spec.add_dependency 'reform', '>= 2.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.3'
26
+ spec.add_development_dependency 'rubocop', '~> 0.34.2'
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'activeadmin-reform'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ module ActiveAdmin
2
+ #
3
+ module Reform
4
+ require_relative 'reform/engine'
5
+ end
6
+ end
@@ -0,0 +1,28 @@
1
+ require 'active_support/concern'
2
+ require_relative 'resource'
3
+
4
+ #
5
+ module ActiveAdmin
6
+ #
7
+ module Reform
8
+ # Provide ActiveAdmin DSL for defining form class
9
+ module Dsl
10
+ extend ActiveSupport::Concern
11
+
12
+ # Set form class for ActiveAdmin resource
13
+ # @param form_class [Class, String]
14
+ # @example
15
+ # ActiveAdmin.resource Author do
16
+ # form_class AuthorForm
17
+ # # You can disable form:
18
+ # form_class false
19
+ # end
20
+ #
21
+ def form_class(form_class)
22
+ config.form_class_name = form_class ? "::#{form_class}" : nil
23
+ end
24
+ end
25
+
26
+ ::ActiveAdmin::ResourceDSL.send(:include, Dsl)
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/engine'
2
+
3
+ #
4
+ module ActiveAdmin
5
+ #
6
+ module Reform
7
+ # Need engine to be absolutely sure active admin is already loaded, and run all it's hooks
8
+ class Engine < Rails::Engine
9
+ initializer 'activeadmin-reform' do
10
+ require 'active_admin'
11
+ require_relative 'dsl'
12
+ require_relative 'forms'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'active_support/concern'
2
+ require_relative 'resource_controller/data_access'
3
+
4
+ #
5
+ module ActiveAdmin
6
+ #
7
+ module Reform
8
+ # Reform integration helpers
9
+ module Forms
10
+ extend ActiveSupport::Concern
11
+
12
+ protected
13
+
14
+ # Wrap resource into Reform::Form if needed
15
+ # @param resource [ActiveRecord::Base]
16
+ # @return [ActiveRecord::Base, Reform::Form]
17
+ def apply_form(resource)
18
+ apply_form? ? form_class.new(resource) : resource
19
+ end
20
+
21
+ private
22
+
23
+ def apply_form?
24
+ case action_name
25
+ when 'new', 'edit', 'update', 'create'
26
+ form_class.present?
27
+ end
28
+ end
29
+
30
+ def form_class
31
+ active_admin_config.form_class
32
+ end
33
+ end
34
+
35
+ ::ActiveAdmin::ResourceController.send(:include, Forms)
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/concern'
2
+
3
+ #
4
+ module ActiveAdmin
5
+ #
6
+ module Reform
7
+ # Defines form class accessor
8
+ module Resource
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ attr_accessor :form_class_name
13
+ end
14
+
15
+ # @return [nil, Class<Reform::Form>]
16
+ def form_class
17
+ ActiveSupport::Dependencies.constantize(form_class_name) if form_class_name
18
+ end
19
+ end
20
+
21
+ ::ActiveAdmin::Resource.send(:include, Resource)
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ require 'reform'
2
+ require 'active_support/concern'
3
+
4
+ #
5
+ module ActiveAdmin
6
+ #
7
+ module Reform
8
+ #
9
+ module ResourceController
10
+ # Overrides ActiveAdmin' templates method to wrap model into Reform::Form
11
+ module DataAccess
12
+ extend ActiveSupport::Concern
13
+
14
+ # @param resource [ActiveRecord::Base]
15
+ # @return [ActiveRecord::Base, Reform::Form]
16
+ def apply_decorations(resource)
17
+ resource = super(resource)
18
+ apply_form(resource)
19
+ end
20
+
21
+ # @param resource [ActiveRecord::Base, Reform::Form]
22
+ # @param attributes [(Hash)]
23
+ # @return [ActiveRecord::Base, Reform::Form]
24
+ def assign_attributes(resource, attributes)
25
+ if resource.is_a?(::Reform::Form)
26
+ resource.validate(*attributes) unless action_name == 'new'
27
+ resource
28
+ else
29
+ super(resource, attributes)
30
+ end
31
+ end
32
+ end
33
+
34
+ ::ActiveAdmin::ResourceController.send(:include, DataAccess)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ require_relative 'active_admin/reform'
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-reform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Artyom Bolshakov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-28 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: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: reform
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.34.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.34.2
97
+ description: Provides ability to use form object in your ActiveAdmin application
98
+ email:
99
+ - abolshakov@spbtv.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".hound.yml"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - CONTRIBUTING.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - activeadmin-reform.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/active_admin/reform.rb
119
+ - lib/active_admin/reform/dsl.rb
120
+ - lib/active_admin/reform/engine.rb
121
+ - lib/active_admin/reform/forms.rb
122
+ - lib/active_admin/reform/resource.rb
123
+ - lib/active_admin/reform/resource_controller/data_access.rb
124
+ - lib/activeadmin-reform.rb
125
+ homepage: https://github.com/bolshakov/activeadmin-reform
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.4.8
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Integrates ActiveAdmin with Reform
149
+ test_files: []
150
+ has_rdoc: