better_record 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/scaffold.css +80 -0
  3. data/app/controllers/better_record/application_controller.rb +1 -0
  4. data/app/controllers/better_record/table_sizes_controller.rb +28 -0
  5. data/app/helpers/better_record/table_sizes_helper.rb +4 -0
  6. data/app/models/better_record/base.rb +16 -8
  7. data/app/models/better_record/current.rb +5 -0
  8. data/app/models/better_record/{audit.rb → logged_action.rb} +2 -2
  9. data/app/models/better_record/table_size.rb +20 -17
  10. data/{lib/better_record → config/initializers/active_record}/associations.rb +5 -8
  11. data/config/initializers/active_record/reflection.rb +21 -0
  12. data/config/initializers/boolean.rb +11 -0
  13. data/config/initializers/content_security_policy.rb +25 -0
  14. data/config/initializers/filter_parameter_logging.rb +10 -0
  15. data/config/initializers/inflections.rb +21 -0
  16. data/config/initializers/integer.rb +5 -0
  17. data/config/initializers/jazz_fingers.rb +7 -0
  18. data/config/initializers/mime_types.rb +4 -0
  19. data/config/initializers/money_type.rb +32 -0
  20. data/config/routes.rb +2 -0
  21. data/db/migrate/20180725160802_create_better_record_db_functions.rb +94 -0
  22. data/db/migrate/20180725201614_create_better_record_table_sizes.rb +24 -0
  23. data/db/postgres-audit-trigger.psql +347 -0
  24. data/lib/better_record.rb +14 -19
  25. data/lib/better_record/version.rb +1 -1
  26. data/lib/tasks/spec/attributes.rake +42 -0
  27. metadata +95 -9
  28. data/lib/generators/create_helper_functions/USAGE +0 -9
  29. data/lib/generators/create_helper_functions/create_helper_functions_generator.rb +0 -61
  30. data/lib/tasks/db/create_audits.rake +0 -0
data/lib/better_record.rb CHANGED
@@ -1,24 +1,18 @@
1
1
  require "active_support"
2
2
 
3
- class Boolean
4
- def self.parse(value)
5
- ActiveRecord::Type::Boolean.new.cast(value)
6
- end
7
- end
8
-
9
- class Object
10
- def yes_no_to_s
11
- !!self == self ? (self ? 'yes' : 'no') : to_s
12
- end
13
- end
14
-
15
3
  module BetterRecord
16
4
  class << self
17
- attr_accessor :default_polymorphic_method, :db_audit_schema, :has_audits_by_default
5
+ attr_accessor :default_polymorphic_method,
6
+ :db_audit_schema,
7
+ :has_audits_by_default,
8
+ :audit_relation_name,
9
+ :layout_template
18
10
  end
19
11
  self.default_polymorphic_method = :polymorphic_name
20
12
  self.db_audit_schema = ENV.fetch('DB_AUDIT_SCHEMA') { 'auditing' }
21
- self.has_audits_by_default = Boolean.parse(ENV.fetch('BR_ADD_HAS_MANY') { false })
13
+ self.has_audits_by_default = ActiveRecord::Type::Boolean.new.cast(ENV.fetch('BR_ADD_HAS_MANY') { false })
14
+ self.audit_relation_name = (ENV.fetch('BR_AUDIT_RELATION_NAME') { 'audits' }).to_sym
15
+ self.layout_template = (ENV.fetch('BR_LAYOUT_TEMPLATE') { 'better_record/layout' }).to_s
22
16
  end
23
17
 
24
18
  Dir.glob("#{File.expand_path(__dir__)}/better_record/*").each do |d|
@@ -27,11 +21,12 @@ end
27
21
 
28
22
  ActiveSupport.on_load(:active_record) do
29
23
  module ActiveRecord
30
- include BetterRecord::Associations
31
- include BetterRecord::Batches
32
- include BetterRecord::Migration
33
- include BetterRecord::Reflection
34
- include BetterRecord::Relation
24
+ module Batches
25
+ include BetterRecord::Batches
26
+ end
27
+ class Migration
28
+ include BetterRecord::Migration
29
+ end
35
30
  end
36
31
  include BetterRecord::NullifyBlankAttributes
37
32
  end
@@ -1,3 +1,3 @@
1
1
  module BetterRecord
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -0,0 +1,42 @@
1
+ namespace :spec do
2
+ desc 'add attribute comments to model spec'
3
+ task attributes: :environment do |t, args|
4
+ raise 'No Model Given' unless ARGV[1].present?
5
+ model_name = ARGV[1]
6
+ file_path = Rails.root.join('spec', 'models', "#{model_name.underscore}_spec.rb")
7
+ if File.exists?(file_path)
8
+ file = File.read(file_path)
9
+
10
+ model = model_name.constantize
11
+
12
+ attr_line_regex = /([ ]+describe \'Attributes\' do\n)/
13
+
14
+ s_idx = (file =~ attr_line_regex)
15
+
16
+ if s_idx
17
+ e_idx = file.index(/describe/, s_idx) - 1
18
+
19
+ prefix = "#{file[s_idx..e_idx]} "
20
+
21
+ existance_regex = /[ ]+# run \`rails spec:attributes .*?\` to replace this line\n/
22
+
23
+ if file =~ existance_regex
24
+ file.sub!(existance_regex, model.column_comments(prefix))
25
+ else
26
+ attributes = model.column_comments.split("\n")
27
+ attributes.each do |attribute|
28
+ file.sub!(/[ ]*?#{Regexp.escape(attribute)}[ ]*?\n/, '')
29
+ end
30
+ file.sub!(attr_line_regex, "\\0#{model.column_comments(prefix)}")
31
+ end
32
+
33
+ File.open(file_path, 'w') {|f| f.puts file}
34
+ else
35
+ puts 'Attributes section not found'
36
+ end
37
+ else
38
+ puts "#{file_path} not found"
39
+ end
40
+ task ARGV[1].to_sym do ; end
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley
@@ -15,6 +15,9 @@ dependencies:
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 5.2.0
20
23
  type: :runtime
@@ -22,22 +25,91 @@ dependencies:
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.2'
30
+ - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 5.2.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: pg
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 1.0.0
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: store_as_int
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.0.15
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.0.15
73
+ - !ruby/object:Gem::Dependency
74
+ name: pry-rails
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.3'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.6
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.3'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.3.6
93
+ - !ruby/object:Gem::Dependency
94
+ name: table_print
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.5'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.5.6
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.5'
38
110
  - - ">="
39
111
  - !ruby/object:Gem::Version
40
- version: '0'
112
+ version: 1.5.6
41
113
  description: |2
42
114
  This app extends active record to allow you to change the polymorphic type value in relationships.
43
115
  It also extends active record batching functions to be able to order records while batching.
@@ -53,16 +125,32 @@ files:
53
125
  - README.md
54
126
  - Rakefile
55
127
  - app/assets/config/better_record_manifest.js
128
+ - app/assets/stylesheets/scaffold.css
56
129
  - app/controllers/better_record/application_controller.rb
130
+ - app/controllers/better_record/table_sizes_controller.rb
57
131
  - app/helpers/better_record/application_helper.rb
132
+ - app/helpers/better_record/table_sizes_helper.rb
58
133
  - app/jobs/better_record/application_job.rb
59
134
  - app/mailers/better_record/application_mailer.rb
60
- - app/models/better_record/audit.rb
61
135
  - app/models/better_record/base.rb
136
+ - app/models/better_record/current.rb
137
+ - app/models/better_record/logged_action.rb
62
138
  - app/models/better_record/table_size.rb
139
+ - config/initializers/active_record/associations.rb
140
+ - config/initializers/active_record/reflection.rb
141
+ - config/initializers/boolean.rb
142
+ - config/initializers/content_security_policy.rb
143
+ - config/initializers/filter_parameter_logging.rb
144
+ - config/initializers/inflections.rb
145
+ - config/initializers/integer.rb
146
+ - config/initializers/jazz_fingers.rb
147
+ - config/initializers/mime_types.rb
148
+ - config/initializers/money_type.rb
63
149
  - config/routes.rb
150
+ - db/migrate/20180725160802_create_better_record_db_functions.rb
151
+ - db/migrate/20180725201614_create_better_record_table_sizes.rb
152
+ - db/postgres-audit-trigger.psql
64
153
  - lib/better_record.rb
65
- - lib/better_record/associations.rb
66
154
  - lib/better_record/batches.rb
67
155
  - lib/better_record/engine.rb
68
156
  - lib/better_record/migration.rb
@@ -71,9 +159,7 @@ files:
71
159
  - lib/better_record/reflection.rb
72
160
  - lib/better_record/relation.rb
73
161
  - lib/better_record/version.rb
74
- - lib/generators/create_helper_functions/USAGE
75
- - lib/generators/create_helper_functions/create_helper_functions_generator.rb
76
- - lib/tasks/db/create_audits.rake
162
+ - lib/tasks/spec/attributes.rake
77
163
  homepage: https://github.com/SampsonCrowley/multi_app_active_record
78
164
  licenses:
79
165
  - MIT
@@ -94,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
180
  version: '0'
95
181
  requirements: []
96
182
  rubyforge_project:
97
- rubygems_version: 2.7.6
183
+ rubygems_version: 2.7.7
98
184
  signing_key:
99
185
  specification_version: 4
100
186
  summary: Fix functions that are lacking in Active record to be compatible with multi-app
@@ -1,9 +0,0 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- rails generate create_helper_functions --schema_name audit
6
-
7
- This will create:
8
- db/migrate/*_create_database_helper_functions.rb
9
- db/postgres-audit-trigger.psql
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators/active_record'
4
-
5
- class CreateHelperFunctionsGenerator < ActiveRecord::Generators::Base
6
- source_root File.expand_path('templates', __dir__)
7
- argument :name, type: :string, default: 'testes'
8
- class_option :audit_schema, type: :string, default: 'audit'
9
- class_option :eject, type: :boolean, default: false
10
-
11
- def copy_initializer
12
- template 'gitattributes', '.gitattributes'
13
- template 'gitignore', '.gitignore'
14
- template 'jsbeautifyrc', '.jsbeautifyrc'
15
- template 'pryrc', '.pryrc'
16
- template 'ruby-version', '.ruby-version'
17
- template 'postgres-audit-trigger.psql', 'db/postgres-audit-trigger.psql'
18
- if !!options['eject']
19
- template 'initializer.rb', 'config/initializers/better_record.rb'
20
- else
21
- template 'initializer.rb', 'config/initializers/better_record.rb'
22
- end
23
- migration_template "migration.rb", "#{migration_path}/create_database_helper_functions.rb", migration_version: migration_version, force: true
24
- application ''
25
-
26
- eager_line = 'config.eager_load_paths += Dir["#{config.root}/lib/modules/**/"]'
27
-
28
- gsub_file 'config/application.rb', /([ \t]*?#{Regexp.escape(eager_line)}[ \t0-9\.]*?)\n/mi do |match|
29
- ""
30
- end
31
-
32
- gsub_file 'config/application.rb', /#{Regexp.escape("config.load_defaults")}[ 0-9\.]+\n/mi do |match|
33
- "#{match} #{'config.eager_load_paths += Dir["#{config.root}/lib/modules/**/"]'}\n"
34
- end
35
-
36
- gsub_file 'app/models/application_record.rb', /(#{Regexp.escape("class ApplicationRecord < ActiveRecord::Base")})/mi do |match|
37
- p match
38
- "class ApplicationRecord < BetterRecord::Base"
39
- end
40
- end
41
-
42
- def audit_schema
43
- @audit_schema ||= options['audit_schema'].presence || 'audit'
44
- end
45
-
46
- private
47
-
48
- def migration_path
49
- if Rails.version >= '5.0.3'
50
- db_migrate_path
51
- else
52
- @migration_path ||= File.join("db", "migrate")
53
- end
54
- end
55
-
56
- def migration_version
57
- if Rails.version.start_with? '5'
58
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
59
- end
60
- end
61
- end
File without changes