acts_as_splittable 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -2
- data/lib/acts_as_splittable/version.rb +1 -1
- data/lib/acts_as_splittable.rb +18 -14
- data/spec/models/splittable_spec.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4595fb64c43327405f29ae3530fe069a772599
|
4
|
+
data.tar.gz: e40f06000ded452b21769446530453e8eba7243d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1ccfc10ca315b1b35d733c767c54b241c1c19996d30d1a0e5ccb6f0a2d88b50c966eaf4f723e704678fe25587d821025846a8b8eaf1888bae6e8a92d9bd814
|
7
|
+
data.tar.gz: 61a3e79425cad2336247816305eaaf51dec3e7579d4237a0fd46f5027df5d15cc728ae433617ac6f8a6d6e23560fe7e108b75e772cf43e634e2bed79d7379635
|
data/README.md
CHANGED
@@ -3,6 +3,27 @@ ActsAsSplittable
|
|
3
3
|
|
4
4
|
Create virtual attributes.
|
5
5
|
|
6
|
+
Installation
|
7
|
+
--------------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'acts_as_splittable'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ gem install acts_as_splittable
|
25
|
+
```
|
26
|
+
|
6
27
|
|
7
28
|
Usage
|
8
29
|
--------------------
|
@@ -114,8 +135,8 @@ p splittable.email_domain #=> nil
|
|
114
135
|
|
115
136
|
splittable.split_column_values!
|
116
137
|
|
117
|
-
p splittable.email_local #=>
|
118
|
-
p splittable.email_domain #=>
|
138
|
+
p splittable.email_local #=> "splittable"
|
139
|
+
p splittable.email_domain #=> "example.com"
|
119
140
|
```
|
120
141
|
|
121
142
|
Contributing
|
data/lib/acts_as_splittable.rb
CHANGED
@@ -54,19 +54,21 @@ module ActsAsSplittable
|
|
54
54
|
split, pattern, partials, on_split, on_join = self.class.splittable_columns[column]
|
55
55
|
value = send(column)
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
unless value.nil?
|
58
|
+
values = if on_split
|
59
|
+
on_split.is_a?(Symbol) ? send(on_split, value) : on_split.(value)
|
60
|
+
elsif value
|
61
|
+
if split
|
62
|
+
value.to_s.split *(split.is_a?(Array) ? split : [split])
|
63
|
+
else
|
64
|
+
matches = value.to_s.match(pattern)
|
65
|
+
matches[1..(matches.length - 1)]
|
66
|
+
end
|
67
|
+
end || []
|
68
|
+
|
69
|
+
partials.each_with_index do |partial, index|
|
70
|
+
send :"#{partial}=", values[index]
|
65
71
|
end
|
66
|
-
end || []
|
67
|
-
|
68
|
-
partials.each_with_index do |partial, index|
|
69
|
-
send :"#{partial}=", values[index]
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
@@ -80,7 +82,9 @@ module ActsAsSplittable
|
|
80
82
|
split, pattern, partials, on_split, on_join = self.class.splittable_columns[column.to_sym]
|
81
83
|
partials = partials.map{|partial| send(partial) }
|
82
84
|
|
83
|
-
|
85
|
+
unless partials.any?(&:nil?)
|
86
|
+
send :"#{column}=", on_join.is_a?(Symbol) ? send(on_join, partials) : on_join.(partials)
|
87
|
+
end
|
84
88
|
end
|
85
89
|
|
86
90
|
self
|
@@ -92,4 +96,4 @@ module ActsAsSplittable
|
|
92
96
|
end
|
93
97
|
end
|
94
98
|
|
95
|
-
ActiveRecord::Base.extend ActsAsSplittable
|
99
|
+
ActiveRecord::Base.extend ActsAsSplittable
|
@@ -59,5 +59,32 @@ require 'spec_helper'
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
context 'when nil includes in partials or value of column is nil' do
|
63
|
+
before :each do
|
64
|
+
@splittable1 = klass.new(name: "#{klass.name} 1")
|
65
|
+
@splittable1.save!
|
66
|
+
|
67
|
+
@splittable2 = klass.create!(
|
68
|
+
name: "#{klass.name} 2"
|
69
|
+
)
|
70
|
+
|
71
|
+
@splittables = [@splittable1, @splittable2]
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should not join partials before save' do
|
75
|
+
@splittables.each do |record|
|
76
|
+
record.email.should be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should not split columns after initialize' do
|
81
|
+
@splittables.each do |record|
|
82
|
+
splittable = Splittable.find(record.id)
|
83
|
+
|
84
|
+
splittable.email_local.should be_nil
|
85
|
+
splittable.email_domain.should be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
62
89
|
end
|
63
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_splittable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tatat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|