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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a27c21a32be7c3319088a1d0af8806fe645ca59
4
- data.tar.gz: 3f3969eaed108ef4a38a686ebd8bc22722aafdc4
3
+ metadata.gz: 3c7260e54e3e58c841d91e5f50c5d17576704e94
4
+ data.tar.gz: 8e10f38ea5ed4eb90b9913997d574bb4b1b7d81c
5
5
  SHA512:
6
- metadata.gz: 517538c37acac5afb957f9a1305ba8d8f171ca9315778bcb33bae3d58684fc84b2c215aaba8eb8407d896bc1f7e8a79177be79badfde1655a506f40d83b3fc37
7
- data.tar.gz: 7d03a846729d39aa6acd946e5c8e705ebaec04738e578cb2fc84c7799aa30546626979d8cb8feb35389801e7b3e86d606d6171284e7ffb3fda9d114f5b8452f7
6
+ metadata.gz: 583c6da1753a9992f590dd16c64336f04e449691acab9ab9cf01fc889a0209305568ed73a80cb53854f6399acfe9405ae3c312ff979dbfffee08296704645c4d
7
+ data.tar.gz: bf551b72dfdf8f0a2a2daeb2206bf406b001f4d7d069109dba0f6d3c67b02e1614b7669aeac790e15aac808a79d14d4db3a82f3757b9d72cf9c6afba3b8df50d
@@ -1,3 +1,3 @@
1
1
  module AttributeExtras
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,4 +1,3 @@
1
- require 'attribute_extras/base_extensions'
2
1
  require 'attribute_extras/extra_builder'
3
2
  require 'attribute_extras/hook_builder'
4
3
  require 'attribute_extras/modifier'
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.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: rails
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