large_text_field 0.3.2 → 1.0.2

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
  SHA256:
3
- metadata.gz: 8e861890c561a0042d7fff0ed1c1fd38fb31c521f12162b65a1a5cd2338024eb
4
- data.tar.gz: 15e0cb9262c9da4178ade7adb09356ac822170d99a76f36132f32a56cb13e267
3
+ metadata.gz: 6f32662941052c47f238878093fa9ca751cc85b87cd2247b8bd7de2e88762dc1
4
+ data.tar.gz: d8b1867ae5d565b5203c0e8c0c352d5a8c02256fe14b4c83d84ba41a40cf3885
5
5
  SHA512:
6
- metadata.gz: 4b4a3054d01d685096860b6d50e291319fcfc2627116cc09bdc5955f9d31b3e0f1e57ce446e5d08ed72c21220cd18b746198fb844c100440bf41aaa0c836b37d
7
- data.tar.gz: 8193372b717c0b76ebc6e1082936cbf585830e9f42b863e3013e0ff1a43faebb12f48eb82a165f1d48bcf90843bcdf28921b1c1d34c5f3d1e1811f04332aeca9
6
+ metadata.gz: abd2868895b7a9fb3b0112e88cf6988d079e1685d68ae25aa3ef0c362b0559ffe9695671d6fc1211e64eab7127be81ebcb72fe151acaadc7cbcfb51126eb5ddf
7
+ data.tar.gz: f98433084f56f6c2d8a5f2342eace05c8363b579269fd45de9f07d6b9ff591bf8c78edad8fea314c59ee2fc8afbd7b61fa879057cfe264263aa75e733614f92f
data/README.md CHANGED
@@ -6,7 +6,11 @@ This gem allows any model to be associated with multiple named text fields. Eac
6
6
  characters. Defining new fields on models does not require a database migrations. All text fields are stored in a
7
7
  central table that is polymorphically associated with the model, but they act like a column on on the same model.
8
8
 
9
- # How do I use it?
9
+ ## Dependencies
10
+ * Ruby >= 2.6
11
+ * Rails >= 4.2, < 7
12
+
13
+ ## How do I use it?
10
14
  In you Gemfile add:
11
15
 
12
16
  ```
@@ -32,7 +36,7 @@ The large_text_field macro takes the following options...
32
36
  * **maximum:** - The maximum length of a large text field. By default this is 5,000,000 characters, but it can be set to less using this option.
33
37
  * **singularize_errors:** - should validation messages be singularized.
34
38
 
35
- Large text fields default to an empty string. You cannot store nil in a large text field.
39
+ Large text fields default to an empty string. You cannot store nil in a large text field.
36
40
 
37
41
  **Please note:** Large text field uses the *before_save* callback on the class that is the owner for book-keeping. Callbacks are great, but if there are multiple handlers for the same callback the order in which they are called is not predictable. If you want to make changes to large_text_field values in the before_save callback, use the **large_text_field_save** callback instead. This will be called before the large text field book-keeping so your changes will be saved. For example, this will call the save_preprocess method on your class before the large text fields are saved...
38
42
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddLargeTextFields < ActiveRecord::Migration
4
-
3
+ class AddLargeTextFields < (Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
5
4
  def self.up
6
5
  create_table :large_text_fields do |t|
7
6
  t.string :field_name, null: false
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "protected_attributes"
4
-
5
3
  module LargeTextField
6
4
  class NamedTextValue < ActiveRecord::Base
7
5
  # Schema
@@ -10,8 +8,6 @@ module LargeTextField
10
8
  #
11
9
  # index [ :owner_type, :owner_id, :field_name ], :name => 'large_text_field_by_owner_field', :unique=>true
12
10
 
13
- attr_accessible :field_name, :value, :owner_type, :owner_id, :owner
14
-
15
11
  belongs_to :owner, polymorphic: true, inverse_of: :large_text_fields
16
12
 
17
13
  self.table_name = "large_text_fields"
@@ -27,8 +27,8 @@ module LargeTextField
27
27
  result
28
28
  end
29
29
 
30
- def reload
31
- super
30
+ def reload(options = nil)
31
+ super(options)
32
32
  @text_field_hash = nil
33
33
  self
34
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LargeTextField
4
- VERSION = "0.3.2"
4
+ VERSION = "1.0.2"
5
5
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "protected_attributes"
4
-
5
3
  require "rails"
6
4
 
7
5
  module LargeTextField
@@ -5,7 +5,6 @@ class Library < ActiveRecord::Base
5
5
 
6
6
  # Schema
7
7
  # name :string, :limit => 255
8
- attr_accessible :name, :description, :catalog, :notes
9
8
 
10
9
  large_text_field :description, singularize_errors: true
11
10
  large_text_field :catalog, maximum: 500, singularize_errors: true
@@ -12,11 +12,23 @@ development:
12
12
  # Warning: The database defined as "test" will be erased and
13
13
  # re-generated from your development database when you run "rake".
14
14
  # Do not set this db to the same as development or production.
15
+ <% if ENV["USE_MYSQL_DB"] %>
16
+ test:
17
+ adapter: mysql2
18
+ encoding: utf8
19
+ reconnect: false
20
+ database: large_text_field_test
21
+ pool: 5
22
+ username: <%= ENV['DATABASE_MYSQL_USERNAME'] || 'root' %>
23
+ password: <%= ENV['DATABASE_MYSQL_PASSWORD'] || '' %>
24
+ host: <%= ENV['DATABASE_MYSQL_HOST'] || 'localhost' %>
25
+ <% else %>
15
26
  test:
16
27
  adapter: sqlite3
17
- database: db/test.sqlite3
28
+ database: <%= ENV['TEST_DB'].presence || 'db/test.sqlite3' %>
18
29
  pool: 5
19
30
  timeout: 5000
31
+ <% end %>
20
32
 
21
33
  production:
22
34
  adapter: sqlite3
@@ -24,9 +24,6 @@ Dummy::Application.configure do
24
24
  # Only use best-standards-support built into browsers
25
25
  config.action_dispatch.best_standards_support = :builtin
26
26
 
27
- # Raise exception on mass assignment protection for Active Record models
28
- config.active_record.mass_assignment_sanitizer = :strict
29
-
30
27
  # Log the query plan for queries taking more than this (works
31
28
  # with SQLite, MySQL, and PostgreSQL)
32
29
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
@@ -31,9 +31,6 @@ Dummy::Application.configure do
31
31
  # ActionMailer::Base.deliveries array.
32
32
  config.action_mailer.delivery_method = :test
33
33
 
34
- # Raise exception on mass assignment protection for Active Record models
35
- config.active_record.mass_assignment_sanitizer = :strict
36
-
37
34
  # Print deprecation notices to the stderr
38
35
  config.active_support.deprecation = :stderr
39
36
 
Binary file
@@ -1,5 +1,4 @@
1
- # frozen_string_literal: true
2
-
1
+ # encoding: UTF-8
3
2
  # This file is auto-generated from the current state of the database. Instead
4
3
  # of editing this file, please use the migrations feature of Active Record to
5
4
  # incrementally modify your database, and then regenerate this schema definition.
@@ -12,17 +11,19 @@
12
11
  #
13
12
  # It's strongly recommended that you check this file into your version control system.
14
13
 
15
- ActiveRecord::Schema.define(version: 20_160_217_033_529) do
14
+ ActiveRecord::Schema.define(version: 20160217033529) do
15
+
16
16
  create_table "large_text_fields", force: :cascade do |t|
17
- t.string "field_name", null: false
18
- t.text "value", limit: 16_777_215
19
- t.integer "owner_id", null: false
20
- t.string "owner_type", null: false
17
+ t.string "field_name", limit: 255, null: false
18
+ t.text "value", limit: 16777215
19
+ t.integer "owner_id", limit: 4, null: false
20
+ t.string "owner_type", limit: 255, null: false
21
21
  end
22
22
 
23
- add_index "large_text_fields", %w[owner_type owner_id field_name], name: "large_text_field_by_owner_field", unique: true
23
+ add_index "large_text_fields", ["owner_type", "owner_id", "field_name"], name: "large_text_field_by_owner_field", unique: true, using: :btree
24
24
 
25
25
  create_table "libraries", force: :cascade do |t|
26
- t.string "name", null: false
26
+ t.string "name", limit: 255, null: false
27
27
  end
28
+
28
29
  end
Binary file
@@ -1,19 +1,39 @@
1
-  (1.7ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
1
+  (2.3ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
2
2
   (0.1ms) select sqlite_version(*)
3
-  (1.4ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
4
-  (1.6ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
5
-  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3
+  (1.7ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
4
+  (1.7ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
5
+  (1.5ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
6
6
   (1.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
7
7
   (0.1ms) SELECT version FROM "schema_migrations"
8
-  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20160217033529')
9
-  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110217210640')
10
-  (1.4ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL)
8
+  (1.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20160217033529')
9
+  (1.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20110217210640')
10
+  (1.8ms) DROP TABLE "large_text_fields"
11
+  (1.4ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
12
+  (0.1ms) select sqlite_version(*)
13
+  (6.1ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
14
+  (1.3ms) DROP TABLE "libraries"
15
+  (1.6ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) 
16
+  (0.1ms) SELECT version FROM "schema_migrations"
17
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
18
+  (1.6ms) DROP TABLE "large_text_fields"
19
+  (1.1ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL)
11
20
   (0.0ms) select sqlite_version(*)
12
21
   (1.2ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
13
-  (1.4ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) 
14
-  (1.3ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
15
-  (1.3ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
22
+  (1.2ms) DROP TABLE "libraries"
23
+  (1.0ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
24
+  (0.3ms) SELECT version FROM "schema_migrations"
25
+  (1.2ms) DROP TABLE "large_text_fields"
26
+  (1.2ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL) 
27
+  (0.0ms) select sqlite_version(*)
28
+  (1.1ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
29
+  (1.1ms) DROP TABLE "libraries"
30
+  (1.2ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL) 
16
31
   (0.1ms) SELECT version FROM "schema_migrations"
17
-  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20160217033529')
18
-  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20110217210640')
19
32
  ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
33
+  (1.4ms) DROP TABLE "large_text_fields"
34
+  (1.2ms) CREATE TABLE "large_text_fields" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "field_name" varchar NOT NULL, "value" text(16777215), "owner_id" integer NOT NULL, "owner_type" varchar NOT NULL)
35
+  (0.0ms) select sqlite_version(*)
36
+  (1.1ms) CREATE UNIQUE INDEX "large_text_field_by_owner_field" ON "large_text_fields" ("owner_type", "owner_id", "field_name")
37
+  (1.1ms) DROP TABLE "libraries"
38
+  (0.9ms) CREATE TABLE "libraries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)
39
+  (0.1ms) SELECT version FROM "schema_migrations"