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 +4 -4
- data/README.md +23 -1
- data/lib/support_utils/concerns/utils.rb +57 -56
- data/lib/support_utils/version.rb +1 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +8 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e618eda15010ab4a5c8570b2dcd72b34d7d1786d
|
4
|
+
data.tar.gz: e07f9ed204a034bedbab07e55a5ebc94fd86dfe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
9
|
-
|
11
|
+
case
|
12
|
+
when [:date, :datetime, :time, :timestamp].include?(metadata.type.to_s.to_sym)
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
22
|
+
when metadata.type == :integer
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
30
|
+
when [:float, :decimal].include?(metadata.type.to_s.to_sym)
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
44
|
+
when [:string, :text].include?(metadata.type.to_s.to_sym)
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def #{column_name}_format *args, &block
|
47
|
+
options = args.extract_options!
|
48
|
+
case
|
49
|
+
when options[:truncate].present?
|
50
50
|
|
51
|
-
|
52
|
-
|
51
|
+
opts = options[:truncate].is_a?(Hash) ? options[:truncate] : {}
|
52
|
+
utils.h.truncate self.#{column_name}.to_s, opts, &block
|
53
53
|
|
54
|
-
|
54
|
+
when options[:word_wrap].present?
|
55
55
|
|
56
|
-
|
57
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
75
|
+
else
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
def #{column_name}_format *args
|
78
|
+
self.#{column_name}
|
79
|
+
end
|
80
80
|
|
81
|
-
|
81
|
+
end
|
82
82
|
|
83
|
-
|
83
|
+
RUBY
|
84
|
+
end
|
84
85
|
end
|
85
86
|
|
86
87
|
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/test/dummy/log/test.log
CHANGED
@@ -24974,3 +24974,11 @@ Migrating to CreateOrders (20150424032916)
|
|
24974
24974
|
[1m[36m (8.5ms)[0m [1mDELETE FROM sqlite_sequence WHERE name='orders'[0m
|
24975
24975
|
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
24976
24976
|
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
24977
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
24978
|
+
[1m[35mSQL (0.6ms)[0m 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
|
+
[1m[36m (21.6ms)[0m [1mcommit transaction[0m
|
24980
|
+
[1m[35m (0.1ms)[0m begin transaction
|
24981
|
+
[1m[36mSQL (0.2ms)[0m [1mUPDATE "users" SET "email" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["email", "john.doe@example.com"], ["updated_at", "2015-05-08 02:09:03.963887"], ["id", 1001]]
|
24982
|
+
[1m[35m (10.8ms)[0m commit transaction
|
24983
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
24984
|
+
[1m[35m (0.0ms)[0m 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.
|
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-
|
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:
|
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:
|