attribute_extras 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attribute_extras/version.rb +1 -1
- data/lib/attribute_extras.rb +0 -1
- data/test/test_helper.rb +0 -15
- metadata +2 -3
- data/lib/attribute_extras/base_extensions.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c7260e54e3e58c841d91e5f50c5d17576704e94
|
4
|
+
data.tar.gz: 8e10f38ea5ed4eb90b9913997d574bb4b1b7d81c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583c6da1753a9992f590dd16c64336f04e449691acab9ab9cf01fc889a0209305568ed73a80cb53854f6399acfe9405ae3c312ff979dbfffee08296704645c4d
|
7
|
+
data.tar.gz: bf551b72dfdf8f0a2a2daeb2206bf406b001f4d7d069109dba0f6d3c67b02e1614b7669aeac790e15aac808a79d14d4db3a82f3757b9d72cf9c6afba3b8df50d
|
data/lib/attribute_extras.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,25 +1,10 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
|
-
begin
|
4
|
-
require 'bundler/inline'
|
5
|
-
rescue LoadError => e
|
6
|
-
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
|
7
|
-
raise e
|
8
|
-
end
|
9
|
-
|
10
|
-
gemfile(true) do
|
11
|
-
source 'https://rubygems.org'
|
12
|
-
gem 'activerecord'
|
13
|
-
gem 'sqlite3'
|
14
|
-
end
|
15
|
-
|
16
3
|
require 'active_record'
|
17
4
|
require 'minitest/autorun'
|
18
|
-
require 'logger'
|
19
5
|
require 'attribute_extras'
|
20
6
|
|
21
7
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
22
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
23
8
|
ActiveSupport.test_order = :sorted
|
24
9
|
|
25
10
|
require 'test_classes'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_extras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">"
|
@@ -49,7 +49,6 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- lib/attribute_extras.rb
|
52
|
-
- lib/attribute_extras/base_extensions.rb
|
53
52
|
- lib/attribute_extras/extra_builder.rb
|
54
53
|
- lib/attribute_extras/hook_builder.rb
|
55
54
|
- lib/attribute_extras/modifier.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module AttributeExtras
|
2
|
-
module BaseExtensions
|
3
|
-
|
4
|
-
# overrides the writer to truncate if that value is blank
|
5
|
-
def truncate_attributes(*attributes, validator: false, writer: true)
|
6
|
-
string_columns = self.columns.select { |column| column.type == :string && !column.limit.nil? }.map(&:name)
|
7
|
-
if self.table_exists? and (non_attributes = attributes.map(&:to_s) - string_columns).any?
|
8
|
-
raise ArgumentError, <<-MSG.squish
|
9
|
-
Invalid attributes passed to truncate_attributes: #{non_attributes.join(', ')};
|
10
|
-
attributes must be string columns that have a set limit
|
11
|
-
MSG
|
12
|
-
end
|
13
|
-
|
14
|
-
include ::AttributeExtras::TruncateAttributes
|
15
|
-
|
16
|
-
truncated_attributes
|
17
|
-
attributes.each do |attribute|
|
18
|
-
limit = self.columns_hash[attribute.to_s].limit
|
19
|
-
|
20
|
-
if validator
|
21
|
-
validates attribute, length: { maximum: limit }
|
22
|
-
end
|
23
|
-
|
24
|
-
if writer
|
25
|
-
define_method("#{attribute}=") do |value|
|
26
|
-
write_attribute(attribute, ::AttributeExtras::TruncateAttributes::FUNCTION[value, limit: limit])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
truncated_attributes << Modifier.new(attribute, limit: limit)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
ActiveRecord::Base.extend AttributeExtras::BaseExtensions
|