large_text_field 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +25 -17
  4. data/Rakefile +2 -1
  5. data/config/brakeman.ignore +12 -0
  6. data/db/migrate/20110217210640_add_large_text_fields.rb +2 -0
  7. data/lib/large_text_field/application_record.rb +7 -0
  8. data/lib/large_text_field/named_text_value.rb +3 -1
  9. data/lib/large_text_field/owner.rb +22 -6
  10. data/lib/large_text_field/version.rb +1 -1
  11. data/lib/large_text_field.rb +5 -4
  12. metadata +24 -81
  13. data/test/dummy/README.rdoc +0 -261
  14. data/test/dummy/Rakefile +0 -9
  15. data/test/dummy/app/assets/config/manifest.js +0 -1
  16. data/test/dummy/app/models/library.rb +0 -23
  17. data/test/dummy/config/application.rb +0 -54
  18. data/test/dummy/config/boot.rb +0 -12
  19. data/test/dummy/config/database.yml +0 -37
  20. data/test/dummy/config/environment.rb +0 -7
  21. data/test/dummy/config/environments/development.rb +0 -38
  22. data/test/dummy/config/environments/production.rb +0 -71
  23. data/test/dummy/config/environments/test.rb +0 -41
  24. data/test/dummy/config.ru +0 -6
  25. data/test/dummy/db/development.sqlite3 +0 -0
  26. data/test/dummy/db/migrate/20160217033529_create_libraries.rb +0 -13
  27. data/test/dummy/db/schema.rb +0 -29
  28. data/test/dummy/db/test.sqlite3 +0 -0
  29. data/test/dummy/log/development.log +0 -39
  30. data/test/dummy/log/test.log +0 -2893
  31. data/test/dummy/script/rails +0 -8
  32. data/test/dummy/test/fixtures/text_field_owners.yml +0 -11
  33. data/test/fixtures/large_text_field/named_text_values.yml +0 -11
  34. data/test/large_text_field_test.rb +0 -9
  35. data/test/reports/TEST-LargeTextField-LibraryTest.xml +0 -9
  36. data/test/reports/TEST-LargeTextField-NamedTextValueTest.xml +0 -15
  37. data/test/reports/TEST-LargeTextField-OwnerTest.xml +0 -53
  38. data/test/reports/TEST-LargeTextFieldTest.xml +0 -7
  39. data/test/test_helper.rb +0 -46
  40. data/test/unit/dummy/library_test.rb +0 -25
  41. data/test/unit/large_text_field/name_text_value_test.rb +0 -49
  42. data/test/unit/large_text_field/owner_test.rb +0 -317
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f32662941052c47f238878093fa9ca751cc85b87cd2247b8bd7de2e88762dc1
4
- data.tar.gz: d8b1867ae5d565b5203c0e8c0c352d5a8c02256fe14b4c83d84ba41a40cf3885
3
+ metadata.gz: 2ee81575e5c9126667153dcdab05b3c7995f9c7abc9d946481fe72d55aaa4fcd
4
+ data.tar.gz: '0960c44d3511657d46914997ac4841959d171b990d4ca16014ecf93de04929ee'
5
5
  SHA512:
6
- metadata.gz: abd2868895b7a9fb3b0112e88cf6988d079e1685d68ae25aa3ef0c362b0559ffe9695671d6fc1211e64eab7127be81ebcb72fe151acaadc7cbcfb51126eb5ddf
7
- data.tar.gz: f98433084f56f6c2d8a5f2342eace05c8363b579269fd45de9f07d6b9ff591bf8c78edad8fea314c59ee2fc8afbd7b61fa879057cfe264263aa75e733614f92f
6
+ metadata.gz: 4b4b5149dabedec119f5dace3a36c7274f6a106ac315f60f6da43b05fab26159a0d942806d8d97d789fb1bcf16e0734ea9bb2ec23d4ca7590ea7869848b03757
7
+ data.tar.gz: 1ba44d365770a9003d53e26a224939df4755a704d2ddd6c572a4456c2a051f512f009ee97f51ca7424080e5fa5308932ccabccccae0a6e359f80e34eefdef489
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016 YOURNAME
1
+ Copyright 2016 Invoca
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,44 +1,52 @@
1
- [![Build Status](https://semaphoreci.com/api/v1/projects/3d5b004f-ce96-4e9a-9591-79ccc52d2b1f/704179/badge.svg)](https://semaphoreci.com/invoca-inc/large_text_field)
2
-
3
1
  # LargeTextField
4
2
 
5
- This gem allows any model to be associated with multiple named text fields. Each field can hold up to 5 million UTF8
6
- characters. Defining new fields on models does not require a database migrations. All text fields are stored in a
7
- central table that is polymorphically associated with the model, but they act like a column on on the same model.
3
+ This gem allows any model to be associated with multiple named text fields. Each field can hold up to 5 million UTF8
4
+ characters. Defining new fields on models does not require database migrations. All text fields are stored in a
5
+ central table that is polymorphically associated with the model, but they act like a column on the same model.
8
6
 
9
7
  ## Dependencies
10
- * Ruby >= 2.6
11
- * Rails >= 4.2, < 7
8
+ * Ruby >= 2.7
9
+ * Rails >= 6.0
12
10
 
13
11
  ## How do I use it?
14
12
  In you Gemfile add:
15
13
 
16
14
  ```
17
- gem large_text_fields
15
+ gem large_text_field
18
16
  ```
19
17
 
20
18
  There will be database migration you need to run to define the table, so go ahead and run that...
21
19
 
22
- Any class that wants to define a large text field should include **LargeTextField::Owner**, and then define text fields by calling the **large_text_field** macro. For example the following is a library class that has text fields for notes and description.
20
+ Any class that wants to define a large text field should include **::LargeTextField::Owner**,
21
+ and then define text fields by calling the **large_text_field** macro.
22
+
23
+ For example the following is a `Library` class that has large text fields for `notes` and `description`.
23
24
 
24
25
  ```ruby
25
- class Library < ActiveRecord::Base
26
- include LargeTextField::Owner
26
+ class Library < ApplicationRecord
27
+ include ::LargeTextField::Owner
28
+
27
29
  large_text_field :notes
28
30
  large_text_field :description
29
31
  end
30
32
  ```
31
33
 
32
- That's it! You can then access notes and description as if they were columns on your class.
34
+ That's it! You can then access `notes` and `description` as if they were columns on your class.
33
35
 
34
- The large_text_field macro takes the following options...
36
+ The `large_text_field` macro takes the following options...
35
37
 
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.
37
- * **singularize_errors:** - should validation messages be singularized.
38
+ * **maximum: number** - The maximum length of a large text field. By default this is 5,000,000 characters,
39
+ but it can be set to less using this option.
40
+ * **singularize_errors: boolean** - should validation messages be singularized.
38
41
 
39
- Large text fields default to an empty string. You cannot store nil in a large text field.
42
+ Large text fields defaults to an empty string. You cannot store `nil` in a large text field.
40
43
 
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...
44
+ **Please note:** Large text field uses the *before_save* callback on the class that is the owner for book-keeping.
45
+ Callbacks are great, but if there are multiple handlers for the same callback the order in which they are called is
46
+ not predictable. If you want to make changes to large_text_field values in the before_save callback, use the
47
+ **large_text_field_save** callback instead. This will be called before the large text field book-keeping so your
48
+ changes will be saved. For example, this will call the `save_preprocess` method on your class before the large text
49
+ fields are saved...
42
50
 
43
51
  ```ruby
44
52
  set_callback(:large_text_field_save, :before, :save_preprocess)
data/Rakefile CHANGED
@@ -27,6 +27,7 @@ end
27
27
 
28
28
  APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
29
29
  load 'rails/tasks/engine.rake'
30
+ load "rails/tasks/statistics.rake"
30
31
 
31
32
  require 'rake/testtask'
32
33
  require 'rubocop/rake_task'
@@ -47,6 +48,6 @@ end
47
48
  task default: %i[test rubocop]
48
49
 
49
50
  desc 'Run rubocop'
50
- task :rubocop do
51
+ task rubocop: [:environment] do
51
52
  RuboCop::RakeTask.new
52
53
  end
@@ -0,0 +1,12 @@
1
+ {
2
+ "ignored_warnings": [
3
+ {
4
+ "fingerprint": "9a3951031616a07c8e02c86652f537e92c08685da97f5ec2b12d5d3602b55bb8",
5
+ "message": "Support for Ruby 2.7.5 ended on 2023-03-31",
6
+ "file": "Gemfile.lock",
7
+ "line": 137,
8
+ "confidence": "High",
9
+ "note": "To allow for consumers of the gem that are still using Ruby 2.7.5"
10
+ }
11
+ ]
12
+ }
@@ -2,12 +2,14 @@
2
2
 
3
3
  class AddLargeTextFields < (Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
4
4
  def self.up
5
+ # rubocop:disable Rails/CreateTableWithTimestamps
5
6
  create_table :large_text_fields do |t|
6
7
  t.string :field_name, null: false
7
8
  t.text :value, char_limit: 5_592_405, limit: 16_777_215
8
9
  t.integer :owner_id, null: false
9
10
  t.string :owner_type, null: false
10
11
  end
12
+ # rubocop:enable Rails/CreateTableWithTimestamps
11
13
  add_index :large_text_fields, %i[owner_type owner_id field_name], unique: true, name: 'large_text_field_by_owner_field'
12
14
  end
13
15
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LargeTextField
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'application_record'
4
+
3
5
  module LargeTextField
4
- class NamedTextValue < ActiveRecord::Base
6
+ class NamedTextValue < ApplicationRecord
5
7
  # Schema
6
8
  # field_name :string, :limit => 255
7
9
  # value :text, :null=>true, :limit => MYSQL_MEDIUM_TEXT_UTF8_LIMIT
@@ -8,7 +8,14 @@ module LargeTextField
8
8
  include ActiveSupport::Callbacks
9
9
 
10
10
  included do
11
- has_many :large_text_fields, class_name: "LargeTextField::NamedTextValue", as: :owner, autosave: true, dependent: :destroy, inverse_of: :owner
11
+ has_many(
12
+ :large_text_fields,
13
+ class_name: "LargeTextField::NamedTextValue",
14
+ as: :owner,
15
+ autosave: true,
16
+ dependent: :destroy,
17
+ inverse_of: :owner
18
+ )
12
19
  validate :validate_large_text_fields
13
20
  before_save :write_large_text_field_changes
14
21
  define_callbacks :large_text_field_save
@@ -22,13 +29,14 @@ module LargeTextField
22
29
 
23
30
  result._clear_text_field_on_dup
24
31
 
25
- large_text_field_options.keys.each { |k| result.set_text_field(k, get_text_field(k)) }
32
+ large_text_field_options.each_key { |key| result.set_text_field(key, get_text_field(key)) }
26
33
 
27
34
  result
28
35
  end
29
36
 
30
37
  def reload(options = nil)
31
38
  super(options)
39
+
32
40
  @text_field_hash = nil
33
41
  self
34
42
  end
@@ -61,21 +69,29 @@ module LargeTextField
61
69
  text_field_hash_loaded? && @text_field_hash[field_name]&.changes&.any?
62
70
  end
63
71
 
72
+ # rubocop:disable Metrics/CyclomaticComplexity
64
73
  def validate_large_text_fields
65
74
  if text_field_hash_loaded?
66
- large_text_field_options.each do |k, options|
67
- value = text_field_hash[k]&.value
75
+ large_text_field_options.each do |key, options|
76
+ value = text_field_hash[key]&.value
68
77
  conjugation = options[:singularize_errors] ? "is" : "are"
69
78
  maximum = options[:maximum] || MAX_LENGTH
70
- errors.add k, "#{conjugation} too long (maximum is #{self.class.formatted_integer_value(maximum)} characters)" if value.present? && value.size > maximum
79
+
80
+ if value.present? && value.size > maximum
81
+ errors.add(
82
+ key,
83
+ "#{conjugation} too long (maximum is #{self.class.formatted_integer_value(maximum)} characters)"
84
+ )
85
+ end
71
86
  end
72
87
  end
73
88
  end
89
+ # rubocop:enable Metrics/CyclomaticComplexity
74
90
 
75
91
  def write_large_text_field_changes
76
92
  run_callbacks(:large_text_field_save)
77
93
 
78
- @text_field_hash = text_field_hash.compact.select { |_k, v| v.value.presence }
94
+ @text_field_hash = text_field_hash.compact.select { |_key, value| value.value.presence }
79
95
  self.large_text_fields = text_field_hash.values.compact
80
96
  true
81
97
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LargeTextField
4
- VERSION = "1.0.2"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  require "rails"
4
4
 
5
+ require "large_text_field/engine"
6
+ require "large_text_field/named_text_value"
7
+ require "large_text_field/owner"
8
+ require "large_text_field/version"
9
+
5
10
  module LargeTextField
6
11
  MAX_LENGTH = 5_000_000
7
12
  end
8
-
9
- require "large_text_field/engine"
10
- require "large_text_field/owner"
11
- require "large_text_field/named_text_value"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: large_text_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2023-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: invoca-utils
@@ -30,23 +30,17 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '7'
33
+ version: '5.2'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
- version: '4.2'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '7'
47
- description: Large text fields are kept in a central table, and polymorphically associated
48
- with your models. Access and assignment should behave as if it was a column on
49
- the same table.
40
+ version: '5.2'
41
+ description: |
42
+ Large text fields are kept in a central table, and polymorphically associated with your models.
43
+ Access and assignment should behave as if it was a column on the same table.
50
44
  email:
51
45
  - development@invoca.com
52
46
  executables: []
@@ -56,47 +50,26 @@ files:
56
50
  - MIT-LICENSE
57
51
  - README.md
58
52
  - Rakefile
53
+ - config/brakeman.ignore
59
54
  - db/migrate/20110217210640_add_large_text_fields.rb
60
55
  - lib/large_text_field.rb
56
+ - lib/large_text_field/application_record.rb
61
57
  - lib/large_text_field/engine.rb
62
58
  - lib/large_text_field/named_text_value.rb
63
59
  - lib/large_text_field/owner.rb
64
60
  - lib/large_text_field/version.rb
65
- - test/dummy/README.rdoc
66
- - test/dummy/Rakefile
67
- - test/dummy/app/assets/config/manifest.js
68
- - test/dummy/app/models/library.rb
69
- - test/dummy/config.ru
70
- - test/dummy/config/application.rb
71
- - test/dummy/config/boot.rb
72
- - test/dummy/config/database.yml
73
- - test/dummy/config/environment.rb
74
- - test/dummy/config/environments/development.rb
75
- - test/dummy/config/environments/production.rb
76
- - test/dummy/config/environments/test.rb
77
- - test/dummy/db/development.sqlite3
78
- - test/dummy/db/migrate/20160217033529_create_libraries.rb
79
- - test/dummy/db/schema.rb
80
- - test/dummy/db/test.sqlite3
81
- - test/dummy/log/development.log
82
- - test/dummy/log/test.log
83
- - test/dummy/script/rails
84
- - test/dummy/test/fixtures/text_field_owners.yml
85
- - test/fixtures/large_text_field/named_text_values.yml
86
- - test/large_text_field_test.rb
87
- - test/reports/TEST-LargeTextField-LibraryTest.xml
88
- - test/reports/TEST-LargeTextField-NamedTextValueTest.xml
89
- - test/reports/TEST-LargeTextField-OwnerTest.xml
90
- - test/reports/TEST-LargeTextFieldTest.xml
91
- - test/test_helper.rb
92
- - test/unit/dummy/library_test.rb
93
- - test/unit/large_text_field/name_text_value_test.rb
94
- - test/unit/large_text_field/owner_test.rb
95
- homepage: http://github.com/invoca
96
- licenses: []
61
+ homepage: https://github.com/invoca/large_text_field
62
+ licenses:
63
+ - MIT
97
64
  metadata:
98
65
  allowed_push_host: https://rubygems.org
99
- post_install_message:
66
+ rubygems_mfa_required: 'true'
67
+ homepage_uri: https://github.com/invoca/large_text_field
68
+ source_code_uri: https://github.com/invoca/large_text_field
69
+ documentation_uri: https://github.com/invoca/large_text_field
70
+ changelog_uri: https://github.com/invoca/large_text_field/blob/master/CHANGELOG.md
71
+ bug_tracker_uri: https://github.com/invoca/large_text_field/issues
72
+ post_install_message:
100
73
  rdoc_options: []
101
74
  require_paths:
102
75
  - lib
@@ -104,45 +77,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
77
  requirements:
105
78
  - - ">="
106
79
  - !ruby/object:Gem::Version
107
- version: '0'
80
+ version: 2.7.5
108
81
  required_rubygems_version: !ruby/object:Gem::Requirement
109
82
  requirements:
110
83
  - - ">="
111
84
  - !ruby/object:Gem::Version
112
85
  version: '0'
113
86
  requirements: []
114
- rubygems_version: 3.0.1
115
- signing_key:
87
+ rubygems_version: 3.4.13
88
+ signing_key:
116
89
  specification_version: 4
117
90
  summary: Add large text fields to models without database migrations
118
- test_files:
119
- - test/unit/dummy/library_test.rb
120
- - test/unit/large_text_field/name_text_value_test.rb
121
- - test/unit/large_text_field/owner_test.rb
122
- - test/dummy/app/models/library.rb
123
- - test/dummy/app/assets/config/manifest.js
124
- - test/dummy/test/fixtures/text_field_owners.yml
125
- - test/dummy/config/environments/production.rb
126
- - test/dummy/config/environments/development.rb
127
- - test/dummy/config/environments/test.rb
128
- - test/dummy/config/environment.rb
129
- - test/dummy/config/application.rb
130
- - test/dummy/config/database.yml
131
- - test/dummy/config/boot.rb
132
- - test/dummy/config.ru
133
- - test/dummy/script/rails
134
- - test/dummy/Rakefile
135
- - test/dummy/db/schema.rb
136
- - test/dummy/db/test.sqlite3
137
- - test/dummy/db/migrate/20160217033529_create_libraries.rb
138
- - test/dummy/db/development.sqlite3
139
- - test/dummy/log/test.log
140
- - test/dummy/log/development.log
141
- - test/dummy/README.rdoc
142
- - test/large_text_field_test.rb
143
- - test/fixtures/large_text_field/named_text_values.yml
144
- - test/test_helper.rb
145
- - test/reports/TEST-LargeTextField-OwnerTest.xml
146
- - test/reports/TEST-LargeTextField-NamedTextValueTest.xml
147
- - test/reports/TEST-LargeTextField-LibraryTest.xml
148
- - test/reports/TEST-LargeTextFieldTest.xml
91
+ test_files: []
@@ -1,261 +0,0 @@
1
- == Welcome to Rails
2
-
3
- Rails is a web-application framework that includes everything needed to create
4
- database-backed web applications according to the Model-View-Control pattern.
5
-
6
- This pattern splits the view (also called the presentation) into "dumb"
7
- templates that are primarily responsible for inserting pre-built data in between
8
- HTML tags. The model contains the "smart" domain objects (such as Account,
9
- Product, Person, Post) that holds all the business logic and knows how to
10
- persist themselves to a database. The controller handles the incoming requests
11
- (such as Save New Account, Update Product, Show Post) by manipulating the model
12
- and directing data to the view.
13
-
14
- In Rails, the model is handled by what's called an object-relational mapping
15
- layer entitled Active Record. This layer allows you to present the data from
16
- database rows as objects and embellish these data objects with business logic
17
- methods. You can read more about Active Record in
18
- link:files/vendor/rails/activerecord/README.html.
19
-
20
- The controller and view are handled by the Action Pack, which handles both
21
- layers by its two parts: Action View and Action Controller. These two layers
22
- are bundled in a single package due to their heavy interdependence. This is
23
- unlike the relationship between the Active Record and Action Pack that is much
24
- more separate. Each of these packages can be used independently outside of
25
- Rails. You can read more about Action Pack in
26
- link:files/vendor/rails/actionpack/README.html.
27
-
28
-
29
- == Getting Started
30
-
31
- 1. At the command prompt, create a new Rails application:
32
- <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
-
34
- 2. Change directory to <tt>myapp</tt> and start the web server:
35
- <tt>cd myapp; rails server</tt> (run with --help for options)
36
-
37
- 3. Go to http://localhost:3000/ and you'll see:
38
- "Welcome aboard: You're riding Ruby on Rails!"
39
-
40
- 4. Follow the guidelines to start developing your application. You can find
41
- the following resources handy:
42
-
43
- * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
- * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
-
46
-
47
- == Debugging Rails
48
-
49
- Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
- will help you debug it and get it back on the rails.
51
-
52
- First area to check is the application log files. Have "tail -f" commands
53
- running on the server.log and development.log. Rails will automatically display
54
- debugging and runtime information to these files. Debugging info will also be
55
- shown in the browser on requests from 127.0.0.1.
56
-
57
- You can also log your own messages directly into the log file from your code
58
- using the Ruby logger class from inside your controllers. Example:
59
-
60
- class WeblogController < ActionController::Base
61
- def destroy
62
- @weblog = Weblog.find(params[:id])
63
- @weblog.destroy
64
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
- end
66
- end
67
-
68
- The result will be a message in your log file along the lines of:
69
-
70
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
-
72
- More information on how to use the logger is at http://www.ruby-doc.org/core/
73
-
74
- Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
- several books available online as well:
76
-
77
- * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
- * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
-
80
- These two books will bring you up to speed on the Ruby language and also on
81
- programming in general.
82
-
83
-
84
- == Debugger
85
-
86
- Debugger support is available through the debugger command when you start your
87
- Mongrel or WEBrick server with --debugger. This means that you can break out of
88
- execution at any point in the code, investigate and change the model, and then,
89
- resume execution! You need to install ruby-debug to run the server in debugging
90
- mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
-
92
- class WeblogController < ActionController::Base
93
- def index
94
- @posts = Post.all
95
- debugger
96
- end
97
- end
98
-
99
- So the controller will accept the action, run the first line, then present you
100
- with a IRB prompt in the server window. Here you can do things like:
101
-
102
- >> @posts.inspect
103
- => "[#<Post:0x14a6be8
104
- @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
- #<Post:0x14a6620
106
- @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
- >> @posts.first.title = "hello from a debugger"
108
- => "hello from a debugger"
109
-
110
- ...and even better, you can examine how your runtime objects actually work:
111
-
112
- >> f = @posts.first
113
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
- >> f.
115
- Display all 152 possibilities? (y or n)
116
-
117
- Finally, when you're ready to resume execution, you can enter "cont".
118
-
119
-
120
- == Console
121
-
122
- The console is a Ruby shell, which allows you to interact with your
123
- application's domain model. Here you'll have all parts of the application
124
- configured, just like it is when the application is running. You can inspect
125
- domain models, change values, and save to the database. Starting the script
126
- without arguments will launch it in the development environment.
127
-
128
- To start the console, run <tt>rails console</tt> from the application
129
- directory.
130
-
131
- Options:
132
-
133
- * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
- made to the database.
135
- * Passing an environment name as an argument will load the corresponding
136
- environment. Example: <tt>rails console production</tt>.
137
-
138
- To reload your controllers and models after launching the console run
139
- <tt>reload!</tt>
140
-
141
- More information about irb can be found at:
142
- link:http://www.rubycentral.org/pickaxe/irb.html
143
-
144
-
145
- == dbconsole
146
-
147
- You can go to the command line of your database directly through <tt>rails
148
- dbconsole</tt>. You would be connected to the database with the credentials
149
- defined in database.yml. Starting the script without arguments will connect you
150
- to the development database. Passing an argument will connect you to a different
151
- database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
- PostgreSQL and SQLite 3.
153
-
154
- == Description of Contents
155
-
156
- The default directory structure of a generated Ruby on Rails application:
157
-
158
- |-- app
159
- | |-- assets
160
- | | |-- images
161
- | | |-- javascripts
162
- | | `-- stylesheets
163
- | |-- controllers
164
- | |-- helpers
165
- | |-- mailers
166
- | |-- models
167
- | `-- views
168
- | `-- layouts
169
- |-- config
170
- | |-- environments
171
- | |-- initializers
172
- | `-- locales
173
- |-- db
174
- |-- doc
175
- |-- lib
176
- | |-- assets
177
- | `-- tasks
178
- |-- log
179
- |-- public
180
- |-- script
181
- |-- test
182
- | |-- fixtures
183
- | |-- functional
184
- | |-- integration
185
- | |-- performance
186
- | `-- unit
187
- |-- tmp
188
- | `-- cache
189
- | `-- assets
190
- `-- vendor
191
- |-- assets
192
- | |-- javascripts
193
- | `-- stylesheets
194
- `-- plugins
195
-
196
- app
197
- Holds all the code that's specific to this particular application.
198
-
199
- app/assets
200
- Contains subdirectories for images, stylesheets, and JavaScript files.
201
-
202
- app/controllers
203
- Holds controllers that should be named like weblogs_controller.rb for
204
- automated URL mapping. All controllers should descend from
205
- ApplicationController which itself descends from ActionController::Base.
206
-
207
- app/models
208
- Holds models that should be named like post.rb. Models descend from
209
- ActiveRecord::Base by default.
210
-
211
- app/views
212
- Holds the template files for the view that should be named like
213
- weblogs/index.html.erb for the WeblogsController#index action. All views use
214
- eRuby syntax by default.
215
-
216
- app/views/layouts
217
- Holds the template files for layouts to be used with views. This models the
218
- common header/footer method of wrapping views. In your views, define a layout
219
- using the <tt>layout :default</tt> and create a file named default.html.erb.
220
- Inside default.html.erb, call <% yield %> to render the view using this
221
- layout.
222
-
223
- app/helpers
224
- Holds view helpers that should be named like weblogs_helper.rb. These are
225
- generated for you automatically when using generators for controllers.
226
- Helpers can be used to wrap functionality for your views into methods.
227
-
228
- config
229
- Configuration files for the Rails environment, the routing map, the database,
230
- and other dependencies.
231
-
232
- db
233
- Contains the database schema in schema.rb. db/migrate contains all the
234
- sequence of Migrations for your schema.
235
-
236
- doc
237
- This directory is where your application documentation will be stored when
238
- generated using <tt>rake doc:app</tt>
239
-
240
- lib
241
- Application specific libraries. Basically, any kind of custom code that
242
- doesn't belong under controllers, models, or helpers. This directory is in
243
- the load path.
244
-
245
- public
246
- The directory available for the web server. Also contains the dispatchers and the
247
- default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
- server.
249
-
250
- script
251
- Helper scripts for automation and generation.
252
-
253
- test
254
- Unit and functional tests along with fixtures. When using the rails generate
255
- command, template test files will be generated for you and placed in this
256
- directory.
257
-
258
- vendor
259
- External libraries that the application depends on. Also includes the plugins
260
- subdirectory. If the app has frozen rails, those gems also go here, under
261
- vendor/rails/. This directory is in the load path.
data/test/dummy/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env rake
2
- # frozen_string_literal: true
3
-
4
- # Add your own tasks in files placed in lib/tasks ending in .rake,
5
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
6
-
7
- require File.expand_path('config/application', __dir__)
8
-
9
- Dummy::Application.load_tasks