effective_developer 0.5.4 → 0.5.5

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: 5b1e21ed1c3b2080e07244e8e7d01cb9b611ce045c9c8ffa2073caded089f6c1
4
- data.tar.gz: a0be18c08741489856b6aff27861d4b5408c4db12bd9e33b9e8898f072c47fd6
3
+ metadata.gz: 4e4f396c9ab5a37dfca3a796aa10d204827c3e34de709bf9d1d8ce1db2af5201
4
+ data.tar.gz: 4a6034049262d3f56c850dc6a2bc05de3f29201debd3b26ec3ae22851532bfa7
5
5
  SHA512:
6
- metadata.gz: 8c2822c02d0ce42a2f875ff1efa2dd84df01063e2d18dd14dcbb08b1379e9eaa19bcb6dafa1453943c953b8debaae210054973d6de7d6def7a3a4f0eb22ce6e0
7
- data.tar.gz: a0f964f2d4e70ee5624618cd44819d8a97cd3875e9a3dac2531552fe12484d1a09031d96a12ac1729e28522c4110ece5208c49e9d8765acd0efa649537d2e1e2
6
+ metadata.gz: eaeec872eeb393fe930c08ea2a14d8ebd17af0e9df9a4ac2c7fdb21047b2888386c6d3b4f5afefd2ecd6e78d11dc81816c6ad6ae83e56e5af6877b4a6b903354
7
+ data.tar.gz: ed971e8f872fa301fbb1dde42fac07f704f1e0eec46b53fb1250f634cc67e7787362a829d958f160c9084195f459daedd74d4fae6015f2012759318d33c49c64
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Effective::Profiler.allocations { my_method() }
4
+
5
+ module Effective
6
+ class Profiler
7
+
8
+ def self.allocations(sourcefiles: ['effective_'], &block)
9
+ raise('please install the allocation_stats gem') unless defined?(AllocationStats)
10
+
11
+ # Run block
12
+ retval = nil
13
+ stats = AllocationStats.trace { retval = yield(block) }
14
+
15
+ # Compute Allocations
16
+ allocations = stats.allocations.to_a
17
+
18
+ # Filter
19
+ if sourcefiles.present?
20
+ sourcefiles = Array(sourcefiles)
21
+ allocations = allocations.select! { |allocation| sourcefiles.any? { |str| allocation.sourcefile.include?(str) } }
22
+ end
23
+
24
+ # Sort
25
+ allocations = allocations.sort_by { |allocation| allocation.memsize }
26
+
27
+ # Print
28
+ puts AllocationStats::AllocationsProxy.new(allocations).to_text
29
+
30
+ puts "Total allocations: #{allocations.length}. Total size: #{allocations.sum(&:memsize)}"
31
+
32
+ retval
33
+ end
34
+
35
+
36
+ end
37
+
38
+ end
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.5.4'.freeze
2
+ VERSION = '0.5.5'.freeze
3
3
  end
@@ -1,14 +1,8 @@
1
1
  class <%= resource.namespaced_class_name.pluralize %>Datatable < Effective::Datatable
2
2
 
3
- bulk_actions do
4
- bulk_action 'Delete selected', <%= [resource.namespaces, resource, 'path'].flatten.compact.join('_') %>(:ids), data: { method: :delete, confirm: 'Really delete selected?' }
5
- end
6
-
7
3
  datatable do
8
4
  order :updated_at
9
5
 
10
- bulk_actions_col
11
-
12
6
  col :updated_at, visible: false
13
7
  col :created_at, visible: false
14
8
  col :id, visible: false
@@ -66,25 +66,60 @@ namespace :pg do
66
66
  #
67
67
  # bundle exec rake pg:load => Will replace the current database with latest.dump
68
68
  # bundle exec rake pg:load[something.dump] => Will replace the current database with something.dump
69
+ # bundle exec rake pg:load filename=latest.dump database=example
69
70
  desc 'Loads a postgresql .dump file into the development database (latest.dump by default)'
70
- task :load, [:file_name] => :environment do |t, args|
71
- args.with_defaults(:file_name => 'latest.dump')
71
+ task :load, [:filename] => :environment do |t, args|
72
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }
73
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }
74
+ keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
75
+ args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
76
+
77
+ # Validate filename
78
+ unless File.exists?(Rails.root + args.filename)
79
+ puts "#{args.filename || none} does not exist"; exit
80
+ end
72
81
 
82
+ # Validate Config
73
83
  config = ActiveRecord::Base.configurations[Rails.env]
84
+ configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
85
+
86
+ if configs.length > 1 && args.database.blank?
87
+ puts "Multiple database configs exist for #{Rails.env} environment."
88
+ puts "Please run bundle exec rake pg:load database=x"
89
+ puts "Where x is one of: #{configs.map { |config| config.name }.to_sentence}"
90
+ exit
91
+ end
92
+
93
+ if configs.length > 1 && args.database.present?
94
+ config = configs.find { |config| config.name == args.database }
95
+ end
96
+
97
+ if config.blank?
98
+ puts "Unable to find Rails database config for #{Rails.env}. Exiting."; exit
99
+ end
100
+
101
+ config = config.configuration_hash if config.respond_to?(:configuration_hash)
102
+ config = config.stringify_keys
103
+
74
104
  db = { username: (config['username'] || `whoami`), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
75
105
  db.transform_values! { |v| v.respond_to?(:chomp) ? v.chomp : v }
76
106
 
77
- puts "=== Loading #{args.file_name} into local '#{db[:database]}' database"
107
+ puts "=== Loading #{args.filename} into local '#{db[:database]}' database"
78
108
 
79
109
  # bin/rails db:environment:set RAILS_ENV=development
80
110
  if Rails.env != 'production'
81
111
  ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1'
82
112
  end
83
113
 
84
- Rake::Task['db:drop'].invoke
85
- Rake::Task['db:create'].invoke
114
+ if configs.length > 1
115
+ Rake::Task["db:drop:#{args.database}"].invoke
116
+ Rake::Task["db:create:#{args.database}"].invoke
117
+ else
118
+ Rake::Task['db:drop'].invoke
119
+ Rake::Task['db:create'].invoke
120
+ end
86
121
 
87
- if system("export PGPASSWORD=#{db[:password]}; pg_restore --no-acl --no-owner --clean --if-exists -h #{db[:host]} -U #{db[:username]} -d #{db[:database]} #{args.file_name}")
122
+ if system("export PGPASSWORD=#{db[:password]}; pg_restore --no-acl --no-owner --clean --if-exists -h #{db[:host]} -U #{db[:username]} -d #{db[:database]} #{args.filename}")
88
123
  puts "Loading database completed"
89
124
  else
90
125
  abort "Error loading database"
@@ -94,8 +129,11 @@ namespace :pg do
94
129
  # bundle exec rake pg:save => Will dump the database to latest.dump
95
130
  # bundle exec rake pg:save[something.dump] => Will dump the database to something.dump
96
131
  desc 'Saves the development database to a postgresql .dump file (latest.dump by default)'
97
- task :save, [:file_name] => :environment do |t, args|
98
- args.with_defaults(:file_name => 'latest.dump')
132
+ task :save, [:filename] => :environment do |t, args|
133
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }
134
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }
135
+ keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
136
+ args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
99
137
 
100
138
  db = if ENV['DATABASE_URL'].to_s.length > 0
101
139
  uri = URI.parse(ENV['DATABASE_URL']) rescue nil
@@ -103,15 +141,36 @@ namespace :pg do
103
141
 
104
142
  { username: uri.user, password: uri.password, host: uri.host, port: (uri.port || 5432), database: uri.path.sub('/', '') }
105
143
  else
144
+ # Validate Config
106
145
  config = ActiveRecord::Base.configurations[Rails.env]
146
+ configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
147
+
148
+ if configs.length > 1 && args.database.blank?
149
+ puts "Multiple database configs exist for #{Rails.env} environment."
150
+ puts "Please run bundle exec rake pg:save database=x"
151
+ puts "Where x is one of: #{configs.map { |config| config.name }.to_sentence}"
152
+ exit
153
+ end
154
+
155
+ if configs.length > 1 && args.database.present?
156
+ config = configs.find { |config| config.name == args.database }
157
+ end
158
+
159
+ if config.blank?
160
+ puts "Unable to find Rails database config for #{Rails.env}. Exiting."; exit
161
+ end
162
+
163
+ config = config.configuration_hash if config.respond_to?(:configuration_hash)
164
+ config = config.stringify_keys
165
+
107
166
  { username: (config['username'] || `whoami`.chomp), password: config['password'], host: config['host'], port: (config['port'] || 5432), database: config['database'] }
108
167
  end
109
168
 
110
169
  db.transform_values! { |v| v.respond_to?(:chomp) ? v.chomp : v }
111
170
 
112
- puts "=== Saving local '#{db[:database]}' database to #{args.file_name}"
171
+ puts "=== Saving local '#{db[:database]}' database to #{args.filename}"
113
172
 
114
- if system("export PGPASSWORD=#{db[:password]}; pg_dump -Fc --no-acl --no-owner -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} #{db[:database]} > #{args.file_name}")
173
+ if system("export PGPASSWORD=#{db[:password]}; pg_dump -Fc --no-acl --no-owner -h #{db[:host]} -p #{db[:port]} -U #{db[:username]} #{db[:database]} > #{args.filename}")
115
174
  puts "Saving database completed"
116
175
  else
117
176
  abort "Error saving database"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2021-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,6 +51,7 @@ files:
51
51
  - app/models/effective/code_writer.rb
52
52
  - app/models/effective/csv_importer.rb
53
53
  - app/models/effective/live_generator.rb
54
+ - app/models/effective/profiler.rb
54
55
  - config/effective_developer.rb
55
56
  - lib/effective_developer.rb
56
57
  - lib/effective_developer/engine.rb