support_utils 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0aa086704ed53641c59928f9ec247ea97688b3ad
4
- data.tar.gz: 0ac049d8aa70e95ccdbfc64c1f530b8014098771
3
+ metadata.gz: e618eda15010ab4a5c8570b2dcd72b34d7d1786d
4
+ data.tar.gz: e07f9ed204a034bedbab07e55a5ebc94fd86dfe3
5
5
  SHA512:
6
- metadata.gz: 6577e353ebb8485da58f9c8a0ae7bbd1e0499a8b02a7a48387a39631fc0d317be990acf36385b6405ab249b8a15282e1281643f5504fef0c29772bfcc18275d3
7
- data.tar.gz: e7c53f57883658ba6ba5692a0c5ed80cc5b4677fdd2ca1e3c5dc9d3cbb3f0b1682299bdff51dfc969759b61c92a7543c9b6784531d7b2b3bb5e4a1395a516cd1
6
+ metadata.gz: 5f5f89665cae8053179edf470e977ec9c06b58ad3c67e9112d212af6ce55587575352534f4deea35ea7369172e6c9cbfd378d66c74be42d30b1f4a222f64a5a0
7
+ data.tar.gz: 32d3de460996acd31751246899678870db0097fea7a324c05ec0ee5a47d1c6001fe61a0b3f5bf489151b21ea157b1b6fb1c1a3f372e634bc16db291af513a69e
data/README.md CHANGED
@@ -225,7 +225,29 @@ user.active?
225
225
  ```
226
226
 
227
227
 
228
- ### **`Model.truncate(confirm)`**
228
+ ### **`Model#saved?`**
229
+
230
+ Returns the result after save a record using `save` or `update_attributes`
231
+
232
+
233
+ Example saving the record.
234
+
235
+
236
+ ```
237
+ user = User.new
238
+
239
+ user.saved?
240
+ => nil
241
+
242
+ user.update_attributes(email: "john.doe@example.com")
243
+ => true
244
+
245
+ user.saved?
246
+ => true
247
+
248
+ ```
249
+
250
+ ### **`Model.truncate!(confirm)`**
229
251
 
230
252
  Truncate the table reseting the primary key
231
253
 
@@ -4,83 +4,84 @@ module SupportUtils
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
+ if ActiveRecord::Base.connection.table_exists?(self.table_name)
8
+ self.columns_hash.each do |column_name, metadata|
9
+ self.class_eval <<-RUBY
7
10
 
8
- self.columns_hash.each do |column_name, metadata|
9
- self.class_eval <<-RUBY
11
+ case
12
+ when [:date, :datetime, :time, :timestamp].include?(metadata.type.to_s.to_sym)
10
13
 
11
- case
12
- when [:date, :datetime, :time, :timestamp].include?(metadata.type.to_s.to_sym)
13
-
14
- def #{column_name}_format format = :default, *args
15
- options = args.extract_options!
16
- settings = HashWithIndifferentAccess.new({
17
- format: format
18
- }).deep_merge(options)
19
- I18n.l(self.#{column_name}, settings) if #{column_name}
20
- end
14
+ def #{column_name}_format format = :default, *args
15
+ options = args.extract_options!
16
+ settings = HashWithIndifferentAccess.new({
17
+ format: format
18
+ }).deep_merge(options)
19
+ I18n.l(self.#{column_name}, settings) if #{column_name}
20
+ end
21
21
 
22
- when metadata.type == :integer
22
+ when metadata.type == :integer
23
23
 
24
- if metadata.limit.to_i == 1
25
- def #{column_name}? *args
26
- self.#{column_name}.to_i.eql?(1)
24
+ if metadata.limit.to_i == 1
25
+ def #{column_name}? *args
26
+ self.#{column_name}.to_i.eql?(1)
27
+ end
27
28
  end
28
- end
29
29
 
30
- when [:float, :decimal].include?(metadata.type.to_s.to_sym)
30
+ when [:float, :decimal].include?(metadata.type.to_s.to_sym)
31
31
 
32
- def #{column_name}_format *args
33
- options = args.extract_options!
34
- settings = HashWithIndifferentAccess.new({
35
- precision: 2
36
- }).deep_merge(options)
37
- if settings[:currency].present?
38
- utils.h.number_to_currency self.#{column_name}, *[settings]
39
- else
40
- utils.h.number_with_precision self.#{column_name}, *[settings]
32
+ def #{column_name}_format *args
33
+ options = args.extract_options!
34
+ settings = HashWithIndifferentAccess.new({
35
+ precision: 2
36
+ }).deep_merge(options)
37
+ if settings[:currency].present?
38
+ utils.h.number_to_currency self.#{column_name}, *[settings]
39
+ else
40
+ utils.h.number_with_precision self.#{column_name}, *[settings]
41
+ end
41
42
  end
42
- end
43
43
 
44
- when [:string, :text].include?(metadata.type.to_s.to_sym)
44
+ when [:string, :text].include?(metadata.type.to_s.to_sym)
45
45
 
46
- def #{column_name}_format *args, &block
47
- options = args.extract_options!
48
- case
49
- when options[:truncate].present?
46
+ def #{column_name}_format *args, &block
47
+ options = args.extract_options!
48
+ case
49
+ when options[:truncate].present?
50
50
 
51
- opts = options[:truncate].is_a?(Hash) ? options[:truncate] : {}
52
- utils.h.truncate self.#{column_name}.to_s, opts, &block
51
+ opts = options[:truncate].is_a?(Hash) ? options[:truncate] : {}
52
+ utils.h.truncate self.#{column_name}.to_s, opts, &block
53
53
 
54
- when options[:word_wrap].present?
54
+ when options[:word_wrap].present?
55
55
 
56
- opts = options[:word_wrap].is_a?(Hash) ? options[:word_wrap] : {}
57
- utils.h.word_wrap self.#{column_name}.to_s, opts, &block
56
+ opts = options[:word_wrap].is_a?(Hash) ? options[:word_wrap] : {}
57
+ utils.h.word_wrap self.#{column_name}.to_s, opts, &block
58
58
 
59
- when options[:highlight].present?
60
- opts = options[:highlight].is_a?(Hash) ? options[:highlight] : {}
61
- phrases = (opts[:phrases].is_a?(Regexp) || opts[:phrases].is_a?(String) || opts[:phrases].is_a?(Array)) ? opts[:phrases] : ""
62
- utils.h.highlight self.#{column_name}.to_s,phrases, *opts.except(:phrases), &block
59
+ when options[:highlight].present?
60
+ opts = options[:highlight].is_a?(Hash) ? options[:highlight] : {}
61
+ phrases = (opts[:phrases].is_a?(Regexp) || opts[:phrases].is_a?(String) || opts[:phrases].is_a?(Array)) ? opts[:phrases] : ""
62
+ utils.h.highlight self.#{column_name}.to_s,phrases, *opts.except(:phrases), &block
63
63
 
64
- when options[:excerpt].present?
65
- opts = options[:excerpt].is_a?(Hash) ? options[:excerpt] : {}
66
- phrase = (opts[:phrase].is_a?(Regexp) || opts[:phrase].is_a?(String) ) ? opts[:phrase] : ""
67
- utils.h.excerpt(self.#{column_name}.to_s,phrase, opts.except(:phrase), &block).to_s
64
+ when options[:excerpt].present?
65
+ opts = options[:excerpt].is_a?(Hash) ? options[:excerpt] : {}
66
+ phrase = (opts[:phrase].is_a?(Regexp) || opts[:phrase].is_a?(String) ) ? opts[:phrase] : ""
67
+ utils.h.excerpt(self.#{column_name}.to_s,phrase, opts.except(:phrase), &block).to_s
68
68
 
69
- else
70
- html_options = options[:html_options] || {}
71
- utils.h.simple_format(self.#{column_name}, html_options.except(:html_options), options).to_s
69
+ else
70
+ html_options = options[:html_options] || {}
71
+ utils.h.simple_format(self.#{column_name}, html_options.except(:html_options), options).to_s
72
+ end
72
73
  end
73
- end
74
74
 
75
- else
75
+ else
76
76
 
77
- def #{column_name}_format *args
78
- self.#{column_name}
79
- end
77
+ def #{column_name}_format *args
78
+ self.#{column_name}
79
+ end
80
80
 
81
- end
81
+ end
82
82
 
83
- RUBY
83
+ RUBY
84
+ end
84
85
  end
85
86
 
86
87
 
@@ -1,3 +1,3 @@
1
1
  module SupportUtils
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
Binary file
@@ -24974,3 +24974,11 @@ Migrating to CreateOrders (20150424032916)
24974
24974
   (8.5ms) DELETE FROM sqlite_sequence WHERE name='orders'
24975
24975
  User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
24976
24976
  User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
24977
+  (0.1ms) begin transaction
24978
+ SQL (0.6ms) INSERT INTO "users" ("email", "created_at", "updated_at") VALUES (?, ?, ?) [["email", "user.saved?@example.com"], ["created_at", "2015-05-08 02:08:17.750650"], ["updated_at", "2015-05-08 02:08:17.750650"]]
24979
+  (21.6ms) commit transaction
24980
+  (0.1ms) begin transaction
24981
+ SQL (0.2ms) UPDATE "users" SET "email" = ?, "updated_at" = ? WHERE "users"."id" = ? [["email", "john.doe@example.com"], ["updated_at", "2015-05-08 02:09:03.963887"], ["id", 1001]]
24982
+  (10.8ms) commit transaction
24983
+  (0.1ms) begin transaction
24984
+  (0.0ms) commit transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: support_utils
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
  - Emilio Forrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-25 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -234,7 +234,7 @@ files:
234
234
  - test/integration/navigation_test.rb
235
235
  - test/support_utils_test.rb
236
236
  - test/test_helper.rb
237
- homepage: http://www.emilioforrer.com
237
+ homepage: https://github.com/emilioforrer/support_utils
238
238
  licenses:
239
239
  - MIT
240
240
  metadata: {}
@@ -345,4 +345,3 @@ test_files:
345
345
  - test/dummy/test/models/user_test.rb
346
346
  - test/integration/navigation_test.rb
347
347
  - test/test_helper.rb
348
- has_rdoc: