acts_as_splittable 0.0.2
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 +7 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/Gemfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.md +128 -0
- data/Rakefile +27 -0
- data/acts_as_splittable.gemspec +23 -0
- data/lib/acts_as_splittable/version.rb +3 -0
- data/lib/acts_as_splittable.rb +95 -0
- data/lib/tasks/acts_as_splittable_tasks.rake +4 -0
- data/spec/database.yml.sample +3 -0
- data/spec/models/aplittable_with_validation_spec.rb +64 -0
- data/spec/models/splittable_spec.rb +63 -0
- data/spec/models.rb +46 -0
- data/spec/schema.rb +12 -0
- data/spec/spec_helper.rb +37 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50058ee03ea54fe96784f78b9fab607da4f9dcde
|
4
|
+
data.tar.gz: d04d4414b76cbb3d404f84529387ad02fc555595
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e348b339fc458891a206818484dc6c7cb0492360da9f41e50f5e0e5f62e901829d4f75936624f64cae2437c6fc49f3a749aba6475ead80abb0cece633a698e3
|
7
|
+
data.tar.gz: 8356fac51d37d0ca44394aefca88fd8531124963457e709a6c3c42a249d983cee746f965037cff5408787f538c0eca75ea864d3db0c92ece8dc14fc6dcb41677
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in acts_as_splittable.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 tatat
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
ActsAsSplittable
|
2
|
+
====================
|
3
|
+
|
4
|
+
Create virtual attributes.
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
--------------------
|
9
|
+
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class Splittable < ActiveRecord::Base
|
13
|
+
|
14
|
+
acts_as_splittable
|
15
|
+
|
16
|
+
splittable :email, split: ['@', 2], partials: [:email_local, :email_domain], on_join: Proc.new{|partials| partials.join('@') }
|
17
|
+
splittable :postal_code, pattern: /\A(?<postal_code1>[0-9]{3})(?<postal_code2>[0-9]{4})\Z/
|
18
|
+
splittable :phone_number, partials: [:phone_number1, :phone_number2, :phone_number3], on_split: :split_phone_number, on_join: :join_phone_number
|
19
|
+
|
20
|
+
validates :email_local, format: { with: /\A[a-zA-Z0-9_.-]+\Z/ }
|
21
|
+
validates :email_domain, format: { with: /\A(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}\Z/ }
|
22
|
+
validates :postal_code1, format: { with: /\A[0-9]{3}\Z/ }
|
23
|
+
validates :postal_code2, format: { with: /\A[0-9]{4}\Z/ }
|
24
|
+
validates :phone_number1, format: { with: /\A[0-9]{3}\Z/ }
|
25
|
+
validates :phone_number2, format: { with: /\A[0-9]{4}\Z/ }
|
26
|
+
validates :phone_number3, format: { with: /\A[0-9]{4}\Z/ }
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def split_phone_number(value)
|
31
|
+
return if value.nil?
|
32
|
+
[value[0, 3], value[3, 4], value[7, 4]]
|
33
|
+
end
|
34
|
+
|
35
|
+
def join_phone_number(values)
|
36
|
+
values.join
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
then
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
splittable = Splittable.create!(
|
45
|
+
email_local: 'splittable',
|
46
|
+
email_domain: 'example.com',
|
47
|
+
postal_code1: '012',
|
48
|
+
postal_code2: '3456',
|
49
|
+
phone_number1: '012',
|
50
|
+
phone_number2: '3456',
|
51
|
+
phone_number3: '7890',
|
52
|
+
)
|
53
|
+
|
54
|
+
p splittable.email #=> "splittable@example.com"
|
55
|
+
p splittable.postal_code #=> "0123456"
|
56
|
+
p splittable.phone_number #=> "01234567890"
|
57
|
+
```
|
58
|
+
|
59
|
+
or
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
splittable = Splittable.new
|
63
|
+
splittable.email_local = 'splittable'
|
64
|
+
splittable.email_domain = 'example.com'
|
65
|
+
splittable.postal_code1 = '012'
|
66
|
+
splittable.postal_code2 = '3456'
|
67
|
+
splittable.phone_number1 = '012'
|
68
|
+
splittable.phone_number2 = '3456'
|
69
|
+
splittable.phone_number3 = '7890'
|
70
|
+
|
71
|
+
splittable.save!
|
72
|
+
```
|
73
|
+
|
74
|
+
### Manualy
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class Splittable < ActiveRecord::Base
|
78
|
+
|
79
|
+
# callbacks are
|
80
|
+
# after_initialize { new_record? or split_column_values! }
|
81
|
+
# before_save { join_column_values! }
|
82
|
+
acts_as_splittable callbacks: false
|
83
|
+
|
84
|
+
splittable :email, pattern: /\A(?<email_local>[^@]+)@(?<email_domain>[^@]+)\Z/, on_join: Proc.new{|values| values.join('@') }
|
85
|
+
|
86
|
+
validates :email, presence: true
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
then
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
splittable = Splittable.new(
|
94
|
+
email_local: 'splittable',
|
95
|
+
email_domain: 'example.com',
|
96
|
+
)
|
97
|
+
|
98
|
+
p splittable.email #=> nil
|
99
|
+
p splittable.valid? #=> false
|
100
|
+
|
101
|
+
splittable.join_column_values!
|
102
|
+
|
103
|
+
p splittable.email #=> "splittable@example.com"
|
104
|
+
p splittable.valid? #=> true
|
105
|
+
```
|
106
|
+
|
107
|
+
and
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
splittable = Splittable.find(splittable_id)
|
111
|
+
|
112
|
+
p splittable.email_local #=> nil
|
113
|
+
p splittable.email_domain #=> nil
|
114
|
+
|
115
|
+
splittable.split_column_values!
|
116
|
+
|
117
|
+
p splittable.email_local #=> 'splittable'
|
118
|
+
p splittable.email_domain #=> 'example.com'
|
119
|
+
```
|
120
|
+
|
121
|
+
Contributing
|
122
|
+
--------------------
|
123
|
+
|
124
|
+
1. Fork it
|
125
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
126
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
127
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
128
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ActsAsSplittable'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
require 'rspec/core/rake_task'
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
21
|
+
t.rspec_opts = ['-c', '-fs']
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => :spec
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "acts_as_splittable/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "acts_as_splittable"
|
9
|
+
s.version = ActsAsSplittable::VERSION
|
10
|
+
s.authors = ["tatat"]
|
11
|
+
s.email = ["ioiioioloo@gmail.com"]
|
12
|
+
s.homepage = "https://github.com/tatat/acts_as_splittable"
|
13
|
+
s.summary = "Create virtual attributes."
|
14
|
+
s.description = "Create virtual attributes."
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
|
18
|
+
s.add_dependency 'rails', ['>= 3', '< 5']
|
19
|
+
|
20
|
+
s.add_development_dependency "sqlite3"
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "rspec-rails"
|
23
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActsAsSplittable
|
4
|
+
|
5
|
+
def acts_as_splittable(options = {})
|
6
|
+
options.reverse_merge!(
|
7
|
+
callbacks: true,
|
8
|
+
)
|
9
|
+
|
10
|
+
extend ClassMethods
|
11
|
+
include InstanceMethods
|
12
|
+
|
13
|
+
if options[:callbacks]
|
14
|
+
after_initialize { new_record? or split_column_values! }
|
15
|
+
before_save { join_column_values! }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
SPLITTABLE_DEFAULT_JOIN_PROCESS = Proc.new{|values| values.join }
|
21
|
+
|
22
|
+
def splittable_columns
|
23
|
+
@splittable_columns ||= {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def splittable(column, options)
|
27
|
+
column = column.to_sym
|
28
|
+
partials = (options[:partials] || options[:pattern].names).map(&:to_sym)
|
29
|
+
splittable_columns[column] = [options[:split], options[:pattern], partials, options[:on_split], options[:on_join] || SPLITTABLE_DEFAULT_JOIN_PROCESS]
|
30
|
+
|
31
|
+
partials.each do |partial|
|
32
|
+
define_method partial do
|
33
|
+
splittable_partials[partial]
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method :"#{partial}=" do |value|
|
37
|
+
splittable_partials[partial] = value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def inherited(child)
|
43
|
+
super
|
44
|
+
child.splittable_columns.merge! splittable_columns.dup
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module InstanceMethods
|
49
|
+
def split_column_values!(column = nil)
|
50
|
+
if column.nil?
|
51
|
+
self.class.splittable_columns.each_key{|key| send __method__, key }
|
52
|
+
else
|
53
|
+
column = column.to_sym
|
54
|
+
split, pattern, partials, on_split, on_join = self.class.splittable_columns[column]
|
55
|
+
value = send(column)
|
56
|
+
|
57
|
+
values = if on_split
|
58
|
+
on_split.is_a?(Symbol) ? send(on_split, value) : on_split.(value)
|
59
|
+
elsif value
|
60
|
+
if split
|
61
|
+
value.to_s.split *(split.is_a?(Array) ? split : [split])
|
62
|
+
else
|
63
|
+
matches = value.to_s.match(pattern)
|
64
|
+
matches[1..(matches.length - 1)]
|
65
|
+
end
|
66
|
+
end || []
|
67
|
+
|
68
|
+
partials.each_with_index do |partial, index|
|
69
|
+
send :"#{partial}=", values[index]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def join_column_values!(column = nil)
|
77
|
+
if column.nil?
|
78
|
+
self.class.splittable_columns.each_key{|key| send __method__, key }
|
79
|
+
else
|
80
|
+
split, pattern, partials, on_split, on_join = self.class.splittable_columns[column.to_sym]
|
81
|
+
partials = partials.map{|partial| send(partial) }
|
82
|
+
|
83
|
+
send :"#{column}=", on_join.is_a?(Symbol) ? send(on_join, partials) : on_join.(partials)
|
84
|
+
end
|
85
|
+
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def splittable_partials
|
90
|
+
@splittable_partials ||= {}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
ActiveRecord::Base.extend ActsAsSplittable
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SplittableWithValidation do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@splittable = SplittableWithValidation.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should be valid' do
|
10
|
+
@splittable.email_local = 'splittable'
|
11
|
+
@splittable.email_domain = 'example.com'
|
12
|
+
|
13
|
+
@splittable.should be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be invalid' do
|
17
|
+
@splittable.email_local = 'splitt@ble'
|
18
|
+
@splittable.email_domain = 'example.com'
|
19
|
+
|
20
|
+
@splittable.should_not be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe SplittableWithValidationForOriginalColumn do
|
26
|
+
|
27
|
+
describe '#split_column_values!' do
|
28
|
+
before :each do
|
29
|
+
@splittable = SplittableWithValidationForOriginalColumn.create!(email: 'splittable@example.com')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should be nil' do
|
33
|
+
@splittable.email_local.should be_nil
|
34
|
+
@splittable.email_domain.should be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not be nil' do
|
38
|
+
@splittable.split_column_values!
|
39
|
+
@splittable.email_local.should_not be_nil
|
40
|
+
@splittable.email_domain.should_not be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#valid?' do
|
45
|
+
before :each do
|
46
|
+
@splittable = SplittableWithValidationForOriginalColumn.new
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should be valid' do
|
50
|
+
@splittable.email_local = 'splittable'
|
51
|
+
@splittable.email_domain = 'example.com'
|
52
|
+
|
53
|
+
@splittable.join_column_values!.should be_valid
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should be invalid' do
|
57
|
+
@splittable.email_local = 'splitt@ble'
|
58
|
+
@splittable.email_domain = 'example.com'
|
59
|
+
|
60
|
+
@splittable.join_column_values!.should_not be_valid
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
[Splittable, SplittableInherited, SplittableInheritedInherited].each do |klass|
|
4
|
+
describe klass do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@splittable1 = klass.new(name: "#{klass.name} 1")
|
8
|
+
@splittable1.email_local = 'splittable'
|
9
|
+
@splittable1.email_domain = 'example.com'
|
10
|
+
@splittable1.postal_code1 = '012'
|
11
|
+
@splittable1.postal_code2 = '3456'
|
12
|
+
@splittable1.phone_number1 = '012'
|
13
|
+
@splittable1.phone_number2 = '3456'
|
14
|
+
@splittable1.phone_number3 = '7890'
|
15
|
+
@splittable1.save!
|
16
|
+
|
17
|
+
@splittable2 = klass.create!(
|
18
|
+
name: "#{klass.name} 2",
|
19
|
+
email_local: 'splittable',
|
20
|
+
email_domain: 'example.com',
|
21
|
+
postal_code1: '012',
|
22
|
+
postal_code2: '3456',
|
23
|
+
phone_number1: '012',
|
24
|
+
phone_number2: '3456',
|
25
|
+
phone_number3: '7890',
|
26
|
+
)
|
27
|
+
|
28
|
+
@splittables = [@splittable1, @splittable2]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should assign attributes' do
|
32
|
+
@splittables.each do |record|
|
33
|
+
record.assign_attributes(postal_code1: '987', postal_code2: '6543')
|
34
|
+
|
35
|
+
record.postal_code1.should == '987'
|
36
|
+
record.postal_code2.should == '6543'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should join partials before save' do
|
41
|
+
@splittables.each do |record|
|
42
|
+
record.email.should == 'splittable@example.com'
|
43
|
+
record.postal_code.should == '0123456'
|
44
|
+
record.phone_number.should == '01234567890'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should split columns after initialize' do
|
49
|
+
@splittables.each do |record|
|
50
|
+
splittable = Splittable.find(record.id)
|
51
|
+
|
52
|
+
splittable.email_local.should == 'splittable'
|
53
|
+
splittable.email_domain.should == 'example.com'
|
54
|
+
splittable.postal_code1.should == '012'
|
55
|
+
splittable.postal_code2.should == '3456'
|
56
|
+
splittable.phone_number1.should == '012'
|
57
|
+
splittable.phone_number2.should == '3456'
|
58
|
+
splittable.phone_number3.should == '7890'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/spec/models.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
EMAIL_SPLIT_PATTERN = /\A(?<email_local>[^@]+)@(?<email_domain>[^@]+)\Z/
|
2
|
+
EMAIL_JOIN_PROCESS = Proc.new{|values| values.join('@') }
|
3
|
+
|
4
|
+
class Splittable < ActiveRecord::Base
|
5
|
+
|
6
|
+
acts_as_splittable
|
7
|
+
|
8
|
+
splittable :email, split: ['@', 2], partials: [:email_local, :email_domain], on_join: EMAIL_JOIN_PROCESS
|
9
|
+
splittable :postal_code, pattern: /\A(?<postal_code1>[0-9]{3})(?<postal_code2>[0-9]{4})\Z/
|
10
|
+
splittable :phone_number, partials: [:phone_number1, :phone_number2, :phone_number3], on_split: :split_phone_number, on_join: :join_phone_number
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def split_phone_number(value)
|
15
|
+
return if value.nil?
|
16
|
+
[value[0, 3], value[3, 4], value[7, 4]]
|
17
|
+
end
|
18
|
+
|
19
|
+
def join_phone_number(values)
|
20
|
+
values.join
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SplittableInherited < Splittable; end
|
25
|
+
class SplittableInheritedInherited < SplittableInherited; end
|
26
|
+
|
27
|
+
class SplittableWithValidation < ActiveRecord::Base
|
28
|
+
self.table_name = 'splittables'
|
29
|
+
|
30
|
+
acts_as_splittable
|
31
|
+
|
32
|
+
splittable :email, pattern: EMAIL_SPLIT_PATTERN, on_join: EMAIL_JOIN_PROCESS
|
33
|
+
|
34
|
+
validates :email_local, format: { with: /\A[a-zA-Z0-9_.-]+\Z/ }
|
35
|
+
validates :email_domain, format: { with: /\A(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}\Z/ }
|
36
|
+
end
|
37
|
+
|
38
|
+
class SplittableWithValidationForOriginalColumn < ActiveRecord::Base
|
39
|
+
self.table_name = 'splittables'
|
40
|
+
|
41
|
+
acts_as_splittable callbacks: false
|
42
|
+
|
43
|
+
splittable :email, pattern: EMAIL_SPLIT_PATTERN, on_join: EMAIL_JOIN_PROCESS
|
44
|
+
|
45
|
+
validates :email, format: { with: /\A[a-zA-Z0-9_.-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}\Z/ }
|
46
|
+
end
|
data/spec/schema.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'active_support/testing/assertions'
|
9
|
+
require File.expand_path('../../lib/acts_as_splittable', __FILE__)
|
10
|
+
|
11
|
+
ENV['RAILS_ENV'] ||= 'test'
|
12
|
+
|
13
|
+
db_name = ENV['DB'] || 'sqlite3'
|
14
|
+
database_yml = File.expand_path('../database.yml', __FILE__)
|
15
|
+
|
16
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample" unless File.exists?(database_yml)
|
17
|
+
|
18
|
+
ActiveRecord::Base.configurations = YAML.load_file(database_yml)
|
19
|
+
ActiveRecord::Base.establish_connection(db_name)
|
20
|
+
ActiveRecord::Base.connection
|
21
|
+
|
22
|
+
load File.dirname(__FILE__) + '/schema.rb'
|
23
|
+
load File.dirname(__FILE__) + '/models.rb'
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
27
|
+
config.run_all_when_everything_filtered = true
|
28
|
+
config.filter_run :focus
|
29
|
+
|
30
|
+
# Run specs in random order to surface order dependencies. If you find an
|
31
|
+
# order dependency and want to debug it, you can fix the order by providing
|
32
|
+
# the seed, which is printed after each run.
|
33
|
+
# --seed 1234
|
34
|
+
config.order = 'random'
|
35
|
+
|
36
|
+
config.include ActiveSupport::Testing::Assertions
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_splittable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tatat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3'
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-rails
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
description: Create virtual attributes.
|
76
|
+
email:
|
77
|
+
- ioiioioloo@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- .gitignore
|
83
|
+
- .rspec
|
84
|
+
- Gemfile
|
85
|
+
- MIT-LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- acts_as_splittable.gemspec
|
89
|
+
- lib/acts_as_splittable.rb
|
90
|
+
- lib/acts_as_splittable/version.rb
|
91
|
+
- lib/tasks/acts_as_splittable_tasks.rake
|
92
|
+
- spec/database.yml.sample
|
93
|
+
- spec/models.rb
|
94
|
+
- spec/models/aplittable_with_validation_spec.rb
|
95
|
+
- spec/models/splittable_spec.rb
|
96
|
+
- spec/schema.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: https://github.com/tatat/acts_as_splittable
|
99
|
+
licenses: []
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.0.0
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Create virtual attributes.
|
121
|
+
test_files: []
|