dynamic_fields_for_rails 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +87 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +2 -0
  6. data/app/helpers/dynamic_fields_for_helper.rb +14 -9
  7. data/dynamic_fields_for_rails.gemspec +14 -13
  8. data/lib/dynamic_fields_for_rails/version.rb +3 -1
  9. data/lib/dynamic_fields_for_rails.rb +7 -3
  10. data/test/config/active_record.rb +5 -0
  11. data/test/dummy/Rakefile +3 -1
  12. data/test/dummy/app/controllers/application_controller.rb +2 -0
  13. data/test/dummy/app/helpers/application_helper.rb +2 -0
  14. data/test/dummy/app/models/application_record.rb +5 -0
  15. data/test/dummy/app/models/child.rb +3 -1
  16. data/test/dummy/app/models/parent.rb +3 -1
  17. data/test/dummy/config/application.rb +8 -4
  18. data/test/dummy/config/boot.rb +4 -2
  19. data/test/dummy/config/environment.rb +3 -1
  20. data/test/dummy/config/environments/development.rb +2 -0
  21. data/test/dummy/config/environments/production.rb +3 -1
  22. data/test/dummy/config/environments/test.rb +2 -0
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +2 -0
  24. data/test/dummy/config/initializers/inflections.rb +2 -0
  25. data/test/dummy/config/initializers/mime_types.rb +2 -0
  26. data/test/dummy/config/initializers/secret_token.rb +3 -2
  27. data/test/dummy/config/initializers/session_store.rb +2 -0
  28. data/test/dummy/config/routes.rb +2 -0
  29. data/test/dummy/config.ru +2 -0
  30. data/test/dummy/db/migrate/20130423140255_create_parents.rb +2 -0
  31. data/test/dummy/db/migrate/20130423140307_create_children.rb +2 -0
  32. data/test/dummy/db/schema.rb +9 -8
  33. data/test/dummy/log/test.log +694 -0
  34. data/test/dummy/script/rails +4 -2
  35. data/test/dynamic_fields_for_helper_test.rb +3 -1
  36. data/test/link_to_add_fields_test.rb +7 -5
  37. data/test/link_to_delete_fields_test.rb +10 -8
  38. data/test/test_helper.rb +7 -5
  39. metadata +15 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 074819fc94eb72286ba9ac6047f8a849d75043f7
4
- data.tar.gz: 9086d0757152a6c5030d04e7780ceb3b2066abcd
2
+ SHA256:
3
+ metadata.gz: 4fb93a2e2de4bdf5c990fa45f0ef8e1a07ab99564fded98502037a3bf02b92a6
4
+ data.tar.gz: 6aed3f7be5c1a3c47fa6ee45a5fb02bd5a23de836689715b875e55aa0b736606
5
5
  SHA512:
6
- metadata.gz: e29f998a3e97a339c23f85c17e063675321e5056eb52fbc2520c0b4f990869be1362276db006ec5b132ed7e94d18974834a48880ddce158664aaa91929751ca2
7
- data.tar.gz: b9353d60f8b0e85be7ed1031ffc48f9ef10c874719ab47bb172ce5fd45fbf8e0389f54d4aad84834ce0367e6ac406fa834c2ba2c4dff2119ae8db6e737f3c7c3
6
+ metadata.gz: 8b9f8dc2cf26c34a8a160e0471a51766c36fc94f8f489ceeae21eb164d6b668a7af814b3307e36e479787af38bbebf64d90c640d86c11a460e8d55dfca406bd8
7
+ data.tar.gz: 35e0d9745b721606ae77b682546a12c3c466540d4a8e2e655eb906b6e3c808f6dad93208875ae3642c17a084bb6a15b5e5e897d74abc48a11271510d272a607b
data/.rubocop.yml ADDED
@@ -0,0 +1,87 @@
1
+ # https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+ AllCops:
3
+ Exclude:
4
+ - 'node_modules/**/*'
5
+ - 'db/**/*'
6
+ - 'tmp/**/*'
7
+ - 'vendor/**/*'
8
+ - 'bin/**/*'
9
+ - 'log/**/*'
10
+ - 'Brewfile'
11
+ - 'Rakefile'
12
+
13
+ Rails:
14
+ Enabled: true
15
+
16
+ Style/Documentation:
17
+ Enabled: false # for now
18
+
19
+ Style/Lambda:
20
+ Enabled: false
21
+
22
+ Style/RaiseArgs:
23
+ Enabled: false
24
+
25
+ Naming/FileName:
26
+ Enabled: false
27
+
28
+ # User.all.map do |user|
29
+ # [user.name, user.children.map(&:names)]
30
+ # end.flatten.map do |name|
31
+ # name.capitalize
32
+ # end.join(", ")
33
+ Style/MultilineBlockChain:
34
+ Enabled: false
35
+
36
+ # [
37
+ # "foo",
38
+ # "bar",
39
+ # ]
40
+ Style/TrailingCommaInArrayLiteral:
41
+ Enabled: false
42
+
43
+ Style/TrailingCommaInHashLiteral:
44
+ Enabled: false
45
+
46
+ Layout/RescueEnsureAlignment:
47
+ Enabled: false
48
+
49
+ Style/AccessModifierDeclarations:
50
+ EnforcedStyle: inline
51
+
52
+ Metrics/LineLength:
53
+ Enabled: false
54
+
55
+ Metrics/ClassLength:
56
+ Enabled: false
57
+
58
+ Metrics/MethodLength:
59
+ Max: 40
60
+
61
+ Metrics/BlockLength:
62
+ Enabled: false
63
+
64
+ Metrics/AbcSize:
65
+ Enabled: false
66
+
67
+ Metrics/PerceivedComplexity:
68
+ Enabled: false
69
+
70
+ Style/ParallelAssignment:
71
+ Enabled: false
72
+
73
+ Metrics/CyclomaticComplexity:
74
+ Max: 10
75
+
76
+ # `fail` is seldom/never seen in Ruby code.
77
+ # https://github.com/bbatsov/ruby-style-guide/issues/233
78
+ Style/SignalException:
79
+ EnforcedStyle: only_raise
80
+
81
+ # Would complain about `new_record?` otherwise
82
+ Style/TrivialAccessors:
83
+ ExactNameMatch: true
84
+
85
+ Rails/Delegate:
86
+ Exclude:
87
+ - lib/**/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in dynamic_fields_for_rails.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
@@ -1,21 +1,24 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module DynamicFieldsForHelper
3
4
  def link_to_add_fields(form, association, options = {}, &block)
4
5
  partial = options[:partial] || nil
5
6
  name = options[:name] || nil
6
7
  css_classes = options[:class] || nil
7
8
  target = options[:target] || nil
8
-
9
9
  new_object = form.object.send(association).klass.new
10
10
  id = new_object.object_id
11
+
11
12
  fields = form.fields_for(association, new_object, child_index: id) do |builder|
12
13
  if partial
13
- render("#{form.object.class.name.downcase.pluralize}/#{partial}", fields: builder)
14
+ render("#{form.object.class.name.underscore.pluralize}/#{partial}", fields: builder)
14
15
  else
15
- render("#{form.object.class.name.downcase.pluralize}/#{association.to_s.singularize}_fields", fields: builder)
16
+ render("#{form.object.class.name.underscore.pluralize}/#{association.to_s.singularize}_fields", fields: builder)
16
17
  end
17
18
  end
19
+
18
20
  css_classes = css_classes(DynamicFieldsForRails.add_css_classes, css_classes)
21
+
19
22
  if block_given?
20
23
  link_to('#', class: css_classes, data: { id: id, fields: fields.delete("\n"), target: target }, &block)
21
24
  else
@@ -30,20 +33,22 @@ module DynamicFieldsForHelper
30
33
  link = []
31
34
  link << fields.hidden_field(:_destroy) unless fields.object.new_record?
32
35
  css_classes = css_classes(DynamicFieldsForRails.delete_css_classes, css_classes)
36
+
33
37
  link << if block_given?
34
38
  link_to('#', class: css_classes, title: name, &block)
35
39
  else
36
40
  link_to(name, '#', class: css_classes)
37
41
  end
42
+
43
+ # rubocop:disable Rails/OutputSafety
38
44
  link.join('').html_safe
45
+ # rubocop:enable Rails/OutputSafety
39
46
  end
40
47
 
41
- protected
42
-
43
- def css_classes(default, css_class)
48
+ protected def css_classes(default, css_class)
44
49
  style_class = []
45
- style_class << default unless default.blank?
46
- style_class << css_class unless css_class.blank?
50
+ style_class << default if default.present?
51
+ style_class << css_class if css_class.present?
47
52
  style_class.join(' ')
48
53
  end
49
54
  end
@@ -1,27 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'dynamic_fields_for_rails/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "dynamic_fields_for_rails"
8
+ spec.name = 'dynamic_fields_for_rails'
8
9
  spec.version = DynamicFieldsForRails::VERSION
9
- spec.authors = ["Marten Klitzke"]
10
- spec.email = ["m.klitzke@gmail.com"]
10
+ spec.authors = ['Marten Klitzke']
11
+ spec.email = ['m.klitzke@gmail.com']
11
12
  spec.description = 'Dynamic fields helper for Rails.'
12
13
  spec.summary = 'Helper for nested forms with dynamic fields.'
13
- spec.homepage = "https://github.com/mortik/dynamic_fields_for_rails"
14
- spec.license = "MIT"
14
+ spec.homepage = 'https://github.com/mortik/dynamic_fields_for_rails'
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake", '~> 0'
23
- spec.add_development_dependency "mocha", '~> 0'
24
- spec.add_development_dependency "sqlite3", '~> 0'
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'mocha', '~> 1'
24
+ spec.add_development_dependency 'rake', '~> 12'
25
+ spec.add_development_dependency 'sqlite3', '~> 1'
25
26
 
26
- spec.add_dependency "rails", '>= 3.0.0', '< 6.0.0'
27
+ spec.add_dependency 'rails', '>= 3.0.0', '< 6.0.0'
27
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DynamicFieldsForRails
2
- VERSION = "0.7.0".freeze
4
+ VERSION = '1.0.0'
3
5
  end
@@ -1,16 +1,20 @@
1
- require "dynamic_fields_for_rails/version"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'dynamic_fields_for_rails/version'
4
+
5
+ # rubocop:disable Style/ClassVars
3
6
  module DynamicFieldsForRails
4
7
  class Engine < Rails::Engine
5
8
  end
6
9
 
7
10
  mattr_accessor :add_css_classes
8
- @@add_css_classes = "add_fields"
11
+ @@add_css_classes = 'add_fields'
9
12
 
10
13
  mattr_accessor :delete_css_classes
11
- @@delete_css_classes = "remove_fields"
14
+ @@delete_css_classes = 'remove_fields'
12
15
 
13
16
  def self.setup
14
17
  yield self
15
18
  end
16
19
  end
20
+ # rubocop:enable Style/ClassVars
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # rubocop:disable ClassAndModuleChildren
4
+ # rubocop:disable Style/ClassVars
2
5
  class ActiveRecord::Base
3
6
  mattr_accessor :shared_connection
4
7
  @@shared_connection = nil
@@ -7,4 +10,6 @@ class ActiveRecord::Base
7
10
  @@shared_connection || retrieve_connection
8
11
  end
9
12
  end
13
+ # rubocop:enable Style/ClassVars
14
+ # rubocop:enable ClassAndModuleChildren
10
15
  ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
data/test/dummy/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
4
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
5
 
4
- require File.expand_path('../config/application', __FILE__)
6
+ require File.expand_path('config/application', __dir__)
5
7
  require 'rake'
6
8
 
7
9
  Dummy::Application.load_tasks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationController < ActionController::Base
2
4
  protect_from_forgery
3
5
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ApplicationHelper
2
4
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
@@ -1,2 +1,4 @@
1
- class Child < ActiveRecord::Base
1
+ # frozen_string_literal: true
2
+
3
+ class Child < ApplicationRecord
2
4
  end
@@ -1,4 +1,6 @@
1
- class Parent < ActiveRecord::Base
1
+ # frozen_string_literal: true
2
+
3
+ class Parent < ApplicationRecord
2
4
  has_many :children
3
5
  accepts_nested_attributes_for :children, allow_destroy: true
4
6
  end
@@ -1,9 +1,11 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
- require "rails/all"
3
+ require File.expand_path('boot', __dir__)
4
+
5
+ require 'rails/all'
4
6
 
5
7
  Bundler.require
6
- require "dynamic_fields_for_rails"
8
+ require 'dynamic_fields_for_rails'
7
9
 
8
10
  module Dummy
9
11
  class Application < Rails::Application
@@ -33,9 +35,11 @@ module Dummy
33
35
  # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
34
36
 
35
37
  # Configure the default encoding used in templates for Ruby 1.9.
36
- config.encoding = "utf-8"
38
+ config.encoding = 'utf-8'
37
39
 
38
40
  # Configure sensitive parameters which will be filtered from the log file.
39
41
  config.filter_parameters += [:password]
42
+
43
+ config.active_record.sqlite3.represent_boolean_as_integer = true
40
44
  end
41
45
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
4
+ gemfile = File.expand_path('../../../Gemfile', __dir__)
3
5
 
4
6
  if File.exist?(gemfile)
5
7
  ENV['BUNDLE_GEMFILE'] = gemfile
@@ -7,4 +9,4 @@ if File.exist?(gemfile)
7
9
  Bundler.setup
8
10
  end
9
11
 
10
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
12
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
4
+ require File.expand_path('application', __dir__)
3
5
 
4
6
  # Initialize the rails application
5
7
  Dummy::Application.initialize!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -11,7 +13,7 @@ Dummy::Application.configure do
11
13
  config.action_controller.perform_caching = true
12
14
 
13
15
  # Specifies the header that your server uses for sending files
14
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
16
+ config.action_dispatch.x_sendfile_header = 'X-Sendfile'
15
17
 
16
18
  # For nginx:
17
19
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Add new inflection rules using the following format
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Add new mime types for use in respond_to blocks:
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Your secret key for verifying the integrity of signed cookies.
4
6
  # If you change this key, all old signed cookies will become invalid!
5
7
  # Make sure the secret is at least 30 characters and all random,
6
8
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = '5d8d9599457d5f2fa50c978d19da955350fa36c215f514e6b572b9d1d843b844d477d70fe02eacec84742e0f252cf4d93339762e5d57fed7146063faad77a030'
8
- Dummy::Application.config.secret_key_base = 'test_secret'
9
+ Dummy::Application.config.secret_key_base = '5d8d9599457d5f2fa50c978d19da955350fa36c215f514e6b572b9d1d843b844d477d70fe02eacec84742e0f252cf4d93339762e5d57fed7146063faad77a030'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.routes.draw do
2
4
  resources :parents
3
5
  # The priority is based upon order of creation:
data/test/dummy/config.ru CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is used by Rack-based servers to start the application.
2
4
 
3
5
  require ::File.expand_path('../config/environment', __FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateParents < ActiveRecord::Migration
2
4
  def change
3
5
  create_table :parents, &:timestamps
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateChildren < ActiveRecord::Migration
2
4
  def change
3
5
  create_table :children do |t|
@@ -1,4 +1,5 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  # This file is auto-generated from the current state of the database. Instead
3
4
  # of editing this file, please use the migrations feature of Active Record to
4
5
  # incrementally modify your database, and then regenerate this schema definition.
@@ -12,14 +13,14 @@
12
13
  # It's strongly recommended to check this file into your version control system.
13
14
 
14
15
  ActiveRecord::Schema.define(version: 20_130_423_140_307) do
15
- create_table "children", force: true do |t|
16
- t.integer "parent_id"
17
- t.datetime "created_at", null: false
18
- t.datetime "updated_at", null: false
16
+ create_table 'children', force: true do |t|
17
+ t.integer 'parent_id'
18
+ t.datetime 'created_at', null: false
19
+ t.datetime 'updated_at', null: false
19
20
  end
20
21
 
21
- create_table "parents", force: true do |t|
22
- t.datetime "created_at", null: false
23
- t.datetime "updated_at", null: false
22
+ create_table 'parents', force: true do |t|
23
+ t.datetime 'created_at', null: false
24
+ t.datetime 'updated_at', null: false
24
25
  end
25
26
  end