dm-types-legacy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/Gemfile +147 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +29 -0
- data/dm-types-legacy.gemspec +10 -0
- data/gemspec.yml +19 -0
- data/lib/dm-core/property/legacy.rb +5 -0
- data/lib/dm-core/property/legacy/date_string.rb +67 -0
- data/lib/dm-core/property/legacy/html_text.rb +39 -0
- data/lib/dm-core/property/legacy/numeric_ip_addr.rb +77 -0
- data/lib/dm-core/property/legacy/time_string.rb +68 -0
- data/lib/dm-core/property/legacy/uri_text.rb +39 -0
- data/lib/dm-types/legacy.rb +1 -0
- data/spec/helpers/property.rb +13 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/unit/data_string_spec.rb +66 -0
- data/spec/unit/html_text_spec.rb +39 -0
- data/spec/unit/numeric_ip_addr_spec.rb +62 -0
- data/spec/unit/time_string_spec.rb +70 -0
- data/spec/unit/uri_text_spec.rb +39 -0
- metadata +135 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'dm-types-legacy Documentation' --protected --files ChangeLog.md,LICENSE.txt
|
data/Gemfile
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# If you're working on more than one datamapper gem at a time, then it's
|
2
|
+
# recommended to create a local Gemfile and use this instead of the git
|
3
|
+
# sources. This will make sure that you are developing against your
|
4
|
+
# other local datamapper sources that you currently work on. Gemfile.local
|
5
|
+
# will behave identically to the standard Gemfile apart from the fact that
|
6
|
+
# it fetches the datamapper gems from local paths. This means that you can
|
7
|
+
# use the same environment variables, like ADAPTER(S) or PLUGIN(S) when
|
8
|
+
# running
|
9
|
+
# bundle commands. Gemfile.local is added to .gitignore, so you don't need
|
10
|
+
# to worry about accidentally checking local development paths into git.
|
11
|
+
# In order to create a local Gemfile, all you need to do is run:
|
12
|
+
#
|
13
|
+
# bundle exec rake local_gemfile
|
14
|
+
#
|
15
|
+
# This will give you a Gemfile.local file that points to your local clones
|
16
|
+
# of the various datamapper gems. It's assumed that all datamapper repo
|
17
|
+
# clones reside in the same directory. You can use the Gemfile.local like
|
18
|
+
# so for running any bundle command:
|
19
|
+
#
|
20
|
+
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
21
|
+
#
|
22
|
+
# You can also specify which adapter(s) should be part of the bundle by
|
23
|
+
# setting an environment variable. This of course also works when using the
|
24
|
+
# Gemfile.local
|
25
|
+
#
|
26
|
+
# bundle foo # dm-sqlite-adapter
|
27
|
+
#
|
28
|
+
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
29
|
+
#
|
30
|
+
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter, dm-mysql-adapter
|
31
|
+
#
|
32
|
+
# Of course you can also use the ADAPTER(S) variable when using the
|
33
|
+
# Gemfile.local and running specs against selected adapters.
|
34
|
+
#
|
35
|
+
# For easily working with adapters supported on your machine, it's
|
36
|
+
# recommended that you first install all adapters that you are planning to
|
37
|
+
# use or work on by doing something like
|
38
|
+
#
|
39
|
+
# ADAPTERS=sqlite,mysql,postgres bundle install
|
40
|
+
#
|
41
|
+
# This will clone the various repositories and make them available to
|
42
|
+
# bundler. Once you have them installed you can easily switch between
|
43
|
+
# adapters for the various development tasks. Running something like
|
44
|
+
#
|
45
|
+
# ADAPTER=mysql bundle exec rake spec
|
46
|
+
#
|
47
|
+
# will make sure that the dm-mysql-adapter is part of the bundle, and will
|
48
|
+
# be used when running the specs.
|
49
|
+
#
|
50
|
+
# You can also specify which plugin(s) should be part of the bundle by
|
51
|
+
# setting an environment variable. This also works when using the
|
52
|
+
# Gemfile.local
|
53
|
+
#
|
54
|
+
# bundle foo # dm-migrations
|
55
|
+
#
|
56
|
+
# PLUGINS=dm-validations bundle foo # dm-migrations,
|
57
|
+
# # dm-validations
|
58
|
+
#
|
59
|
+
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations,
|
60
|
+
# # dm-validations,
|
61
|
+
# # dm-types
|
62
|
+
#
|
63
|
+
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run
|
64
|
+
# specs for certain adapter/plugin combinations.
|
65
|
+
#
|
66
|
+
# Finally, to speed up running specs and other tasks, it's recommended to
|
67
|
+
# run
|
68
|
+
#
|
69
|
+
# bundle lock
|
70
|
+
#
|
71
|
+
# after running 'bundle install' for the first time. This will make
|
72
|
+
# 'bundle exec' run a lot faster compared to the unlocked version. With an
|
73
|
+
# unlocked bundle you would typically just run 'bundle install' from time
|
74
|
+
# to time to fetch the latest sources from upstream. When you locked your
|
75
|
+
# bundle, you need to run
|
76
|
+
#
|
77
|
+
# bundle install --relock
|
78
|
+
#
|
79
|
+
# to make sure to fetch the latest updates and then lock the bundle again.
|
80
|
+
# Gemfile.lock is added to the .gitignore file, so you don't need to worry
|
81
|
+
# about accidentally checking it into version control.
|
82
|
+
|
83
|
+
source :rubygems
|
84
|
+
|
85
|
+
DATAMAPPER = 'http://github.com/datamapper'
|
86
|
+
DM_VERSION = '~> 1.0.0'
|
87
|
+
DO_VERSION = '~> 0.10.2'
|
88
|
+
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
89
|
+
RAILS = 'http://github.com/rails/rails.git'
|
90
|
+
|
91
|
+
if ENV['EXTLIB']
|
92
|
+
gem 'extlib', '~> 0.9.15', :git => '#{DATAMAPPER}/extlib.git'
|
93
|
+
else
|
94
|
+
gem 'activesupport', '~> 3.0.0', :git => RAILS,
|
95
|
+
:branch => '3-0-stable',
|
96
|
+
:require => nil
|
97
|
+
end
|
98
|
+
|
99
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
100
|
+
|
101
|
+
group :development do
|
102
|
+
case RUBY_PLATFORM
|
103
|
+
when 'java'
|
104
|
+
gem 'maruku', '~> 0.6.0'
|
105
|
+
else
|
106
|
+
gem 'rdiscount', '~> 1.6.3'
|
107
|
+
end
|
108
|
+
|
109
|
+
gem 'rake', '~> 0.8.7'
|
110
|
+
gem 'ore', '~> 0.2.0'
|
111
|
+
gem 'ore-tasks', '~> 0.1.2'
|
112
|
+
gem 'rspec', '~> 2.0.0'
|
113
|
+
gem 'yard', '~> 0.6.0'
|
114
|
+
end
|
115
|
+
|
116
|
+
group :datamapper do
|
117
|
+
# We need this because we want to pin these dependencies to their git
|
118
|
+
# master sources
|
119
|
+
|
120
|
+
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
121
|
+
adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
|
122
|
+
|
123
|
+
if (do_adapters = DM_DO_ADAPTERS & adapters).any?
|
124
|
+
options = {}
|
125
|
+
options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
|
126
|
+
|
127
|
+
gem 'data_objects', DO_VERSION, options.dup
|
128
|
+
|
129
|
+
do_adapters.each do |adapter|
|
130
|
+
adapter = 'sqlite3' if adapter == 'sqlite'
|
131
|
+
gem "do_#{adapter}", DO_VERSION, options.dup
|
132
|
+
end
|
133
|
+
|
134
|
+
gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
|
135
|
+
end
|
136
|
+
|
137
|
+
adapters.each do |adapter|
|
138
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
139
|
+
end
|
140
|
+
|
141
|
+
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
142
|
+
plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
|
143
|
+
|
144
|
+
plugins.each do |plugin|
|
145
|
+
gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
|
146
|
+
end
|
147
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2010 Hal Brodigan
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# dm-types-legacy
|
2
|
+
|
3
|
+
* [github.com/postmodern/dm-types-legacy](http://github.com/postmodern/dm-types-legacy)
|
4
|
+
* [github.com/postmodern/dm-types-legacy/issues](http://github.com/postmodern/dm-types-legacy/issues)
|
5
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
dm-types-legacy is a collection of legacy data types for working with
|
10
|
+
legacy databases or unsanitized data.
|
11
|
+
|
12
|
+
## Types
|
13
|
+
|
14
|
+
* {DataMapper::Types::Legacy::DateString}: Date values stored as Strings.
|
15
|
+
* {DataMapper::Types::Legacy::TimeString}: Time values stored as Strings.
|
16
|
+
* {DataMapper::Types::Legacy::NumericIPAddr}: IP Addresses stored as
|
17
|
+
Integers.
|
18
|
+
* {DataMapper::Types::Legacy::URIText}: URI escaped text.
|
19
|
+
* {DataMapper::Types::Legacy::HTMLText}: HTML escaped text.
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
* [dm-core](http://github.com/datamapper/dm-core/) ~> 1.0.0
|
24
|
+
|
25
|
+
## Install
|
26
|
+
|
27
|
+
$ sudo gem install dm-types-legacy
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
See {file:LICENSE.txt} for license information.
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
STDERR.puts e.message
|
7
|
+
STDERR.puts "Run `gem install bundler` to install Bundler."
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
STDERR.puts e.message
|
15
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake'
|
20
|
+
|
21
|
+
require 'ore/tasks'
|
22
|
+
Ore::Tasks.new
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new
|
26
|
+
task :default => :spec
|
27
|
+
|
28
|
+
require 'yard'
|
29
|
+
YARD::Rake::YardocTask.new
|
data/gemspec.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
name: dm-types-legacy
|
2
|
+
version: 0.1.0
|
3
|
+
summary: A collection of legacy data types for DataMapper.
|
4
|
+
description:
|
5
|
+
dm-types-legacy is a collection of legacy data types for working with
|
6
|
+
legacy databases or unsanitized data.
|
7
|
+
|
8
|
+
license: MIT
|
9
|
+
authors: Postmodern
|
10
|
+
email: postmodern.mod3@gmail.com
|
11
|
+
homepage: http://github.com/postmodern/dm-types-legacy
|
12
|
+
has_yard: true
|
13
|
+
|
14
|
+
dependencies:
|
15
|
+
dm-core: ~> 1.0.0
|
16
|
+
|
17
|
+
development_dependencies:
|
18
|
+
bundler: ~> 1.0.0
|
19
|
+
yard: ~> 0.6.0
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module DataMapper
|
6
|
+
class Property
|
7
|
+
module Legacy
|
8
|
+
class DateString < String
|
9
|
+
|
10
|
+
#
|
11
|
+
# Parses a date string.
|
12
|
+
#
|
13
|
+
# @param [String] value
|
14
|
+
# The date string.
|
15
|
+
#
|
16
|
+
# @return [Date, nil]
|
17
|
+
# The parsed date.
|
18
|
+
#
|
19
|
+
def load(value)
|
20
|
+
::Date.parse(value) unless (value.nil? || value.empty?)
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Typecasts a date.
|
25
|
+
#
|
26
|
+
# @param [Date, Time, String, nil] value
|
27
|
+
# The date to typecast.
|
28
|
+
#
|
29
|
+
# @return [Date, nil]
|
30
|
+
# The typecasted date.
|
31
|
+
#
|
32
|
+
def typecast(value)
|
33
|
+
if value.kind_of?(::Date)
|
34
|
+
value
|
35
|
+
elsif value.kind_of?(::Time)
|
36
|
+
value.to_date
|
37
|
+
elsif value.kind_of?(::String)
|
38
|
+
::Date.parse(value) unless value.empty?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Dumps a date to a string.
|
44
|
+
#
|
45
|
+
# @param [Date, nil] value
|
46
|
+
# The date to dump.
|
47
|
+
#
|
48
|
+
# @return [String, nil]
|
49
|
+
# The date string.
|
50
|
+
#
|
51
|
+
def dump(value)
|
52
|
+
case value
|
53
|
+
when ::Time
|
54
|
+
value.to_date.to_s
|
55
|
+
when ::Date
|
56
|
+
value.to_s
|
57
|
+
when nil
|
58
|
+
nil
|
59
|
+
else
|
60
|
+
value.to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module DataMapper
|
6
|
+
class Property
|
7
|
+
module Legacy
|
8
|
+
class HTMLText < Text
|
9
|
+
|
10
|
+
#
|
11
|
+
# Unescaped HTML escaped data.
|
12
|
+
#
|
13
|
+
# @param [String, nil] value
|
14
|
+
# The HTML escaped data.
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
17
|
+
# The HTML unescaped data.
|
18
|
+
#
|
19
|
+
def load(value)
|
20
|
+
CGI.unescape_html(value) unless value.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# HTML escapes data.
|
25
|
+
#
|
26
|
+
# @param [String, nil] value
|
27
|
+
# The raw data.
|
28
|
+
#
|
29
|
+
# @return [String, nil]
|
30
|
+
# The HTML escaped data.
|
31
|
+
#
|
32
|
+
def dump(value)
|
33
|
+
CGI.escape_html(value) unless value.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
require 'ipaddr'
|
4
|
+
|
5
|
+
module DataMapper
|
6
|
+
class Property
|
7
|
+
module Legacy
|
8
|
+
class NumericIPAddr < Integer
|
9
|
+
|
10
|
+
#
|
11
|
+
# Loads a numeric IP Address.
|
12
|
+
#
|
13
|
+
# @param [Integer, nil] value
|
14
|
+
# The numeric IP Address.
|
15
|
+
#
|
16
|
+
# @return [IPAddr, nil]
|
17
|
+
# The IP Address.
|
18
|
+
#
|
19
|
+
def load(value)
|
20
|
+
load_integer(value) unless value.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Typecasts an IP Address.
|
25
|
+
#
|
26
|
+
# @param [IPAddr, String, Integer, nil] value
|
27
|
+
# The IP Address.
|
28
|
+
#
|
29
|
+
# @return [IPAddr, nil]
|
30
|
+
# The typecasted IP Address.
|
31
|
+
#
|
32
|
+
def typecast(value)
|
33
|
+
if value.kind_of?(::IPAddr)
|
34
|
+
value
|
35
|
+
elsif value.kind_of?(::String)
|
36
|
+
::IPAddr.new(value) unless value.empty?
|
37
|
+
elsif value.kind_of?(::Integer)
|
38
|
+
load_integer(value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Dumps an IP Address to a numreic value.
|
44
|
+
#
|
45
|
+
# @param [IPAddr, nil] value
|
46
|
+
# The IP Address.
|
47
|
+
#
|
48
|
+
# @return [Integer, nil]
|
49
|
+
# The numeric IP Address.
|
50
|
+
#
|
51
|
+
def dump(value)
|
52
|
+
value.to_i unless value.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
|
57
|
+
#
|
58
|
+
# Loads an IPv4 or IPv6 address from an integer.
|
59
|
+
#
|
60
|
+
# @param [Integer] value
|
61
|
+
# The numeric IP Address.
|
62
|
+
#
|
63
|
+
# @return [IPAddr]
|
64
|
+
# The IPv4 or IPv6 address.
|
65
|
+
#
|
66
|
+
def load_integer(value)
|
67
|
+
if value > 4294967295 # (2 ** 32) - 1
|
68
|
+
::IPAddr.new(value,Socket::AF_INET6)
|
69
|
+
elsif value >= 0
|
70
|
+
::IPAddr.new(value,Socket::AF_INET)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module DataMapper
|
7
|
+
class Property
|
8
|
+
module Legacy
|
9
|
+
class TimeString < String
|
10
|
+
|
11
|
+
#
|
12
|
+
# Parses a time string.
|
13
|
+
#
|
14
|
+
# @param [String] value
|
15
|
+
# The time string.
|
16
|
+
#
|
17
|
+
# @return [Time, nil]
|
18
|
+
# The parsed time.
|
19
|
+
#
|
20
|
+
def load(value)
|
21
|
+
::Time.parse(value) unless (value.nil? || value.empty?)
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Typecasts a time.
|
26
|
+
#
|
27
|
+
# @param [Time, Date, String, nil] value
|
28
|
+
# The time to typecast.
|
29
|
+
#
|
30
|
+
# @return [Time, nil]
|
31
|
+
# The typecasted time.
|
32
|
+
#
|
33
|
+
def typecast(value)
|
34
|
+
if value.kind_of?(::Time)
|
35
|
+
value
|
36
|
+
elsif value.kind_of?(::Date)
|
37
|
+
value.to_time
|
38
|
+
elsif value.kind_of?(::String)
|
39
|
+
::Time.parse(value) unless value.empty?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Dumps a time to a string.
|
45
|
+
#
|
46
|
+
# @param [Time, nil] value
|
47
|
+
# The time to dump.
|
48
|
+
#
|
49
|
+
# @return [String, nil]
|
50
|
+
# The time string.
|
51
|
+
#
|
52
|
+
def dump(value)
|
53
|
+
case value
|
54
|
+
when ::Time
|
55
|
+
value.to_s
|
56
|
+
when ::Date
|
57
|
+
value.to_time.to_s
|
58
|
+
when nil
|
59
|
+
nil
|
60
|
+
else
|
61
|
+
value.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module DataMapper
|
6
|
+
class Property
|
7
|
+
module Legacy
|
8
|
+
class URIText < Text
|
9
|
+
|
10
|
+
#
|
11
|
+
# Unescaped URI escaped data.
|
12
|
+
#
|
13
|
+
# @param [String, nil] value
|
14
|
+
# The URI escaped data.
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
17
|
+
# The URI unescaped data.
|
18
|
+
#
|
19
|
+
def load(value)
|
20
|
+
::URI.unescape(value) unless value.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# URI escapes data.
|
25
|
+
#
|
26
|
+
# @param [String, nil] value
|
27
|
+
# The raw data.
|
28
|
+
#
|
29
|
+
# @return [String, nil]
|
30
|
+
# The URI escaped data.
|
31
|
+
#
|
32
|
+
def dump(value)
|
33
|
+
::URI.escape(value) unless value.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'dm-core/property/legacy'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/property'
|
3
|
+
|
4
|
+
require 'dm-core/property/legacy/date_string'
|
5
|
+
|
6
|
+
describe DataMapper::Property::Legacy::DateString do
|
7
|
+
include Helpers::Property
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
property(DataMapper::Property::Legacy::DateString)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:date_string) { '2010-11-05' }
|
14
|
+
let(:time) { Time.parse(date_string) }
|
15
|
+
let(:date) { Date.parse(date_string) }
|
16
|
+
|
17
|
+
describe "load" do
|
18
|
+
it "should load Date Strings" do
|
19
|
+
@property.load(date_string).should == date
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not load empty-strings" do
|
23
|
+
@property.load('').should be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not load nil" do
|
27
|
+
@property.load(nil).should be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "typecast" do
|
32
|
+
it "should cast Date objects" do
|
33
|
+
@property.typecast(date).should == date
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should cast Time objects" do
|
37
|
+
@property.typecast(time).should == date
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should cast String objects" do
|
41
|
+
@property.typecast(date_string).should == date
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not cast empty-strings" do
|
45
|
+
@property.typecast('').should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not cast nil" do
|
49
|
+
@property.typecast(nil).should be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "dump" do
|
54
|
+
it "should dump a Date object" do
|
55
|
+
@property.dump(date).should == date_string
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should dump a Time object" do
|
59
|
+
@property.dump(time).should == date_string
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not dump nil" do
|
63
|
+
@property.dump(nil).should be_nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/property'
|
3
|
+
|
4
|
+
require 'dm-core/property/legacy/html_text'
|
5
|
+
|
6
|
+
describe DataMapper::Property::Legacy::HTMLText do
|
7
|
+
include Helpers::Property
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
property(DataMapper::Property::Legacy::HTMLText)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:raw_text) { 'one & two' }
|
14
|
+
let(:html_text) { 'one & two' }
|
15
|
+
|
16
|
+
describe "load" do
|
17
|
+
it "should load Date Strings" do
|
18
|
+
@property.load(html_text).should == raw_text
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not load empty-strings" do
|
22
|
+
@property.load('').should be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not load nil" do
|
26
|
+
@property.load(nil).should be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "dump" do
|
31
|
+
it "should dump raw text" do
|
32
|
+
@property.dump(raw_text).should == html_text
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not dump nil" do
|
36
|
+
@property.dump(nil).should be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/property'
|
3
|
+
|
4
|
+
require 'dm-core/property/legacy/numeric_ip_addr'
|
5
|
+
|
6
|
+
describe DataMapper::Property::Legacy::NumericIPAddr do
|
7
|
+
include Helpers::Property
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
property(DataMapper::Property::Legacy::NumericIPAddr)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:ip_string) { '127.0.0.1' }
|
14
|
+
let(:ip) { IPAddr.new(ip_string) }
|
15
|
+
let(:ip_number) { ip.to_i }
|
16
|
+
|
17
|
+
describe "load" do
|
18
|
+
it "should load numeric IP Addresses" do
|
19
|
+
@property.load(ip_number).should == ip
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not load nil" do
|
23
|
+
@property.load(nil).should be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "typecast" do
|
28
|
+
it "should cast IPAddr objects" do
|
29
|
+
@property.typecast(ip).should == ip
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should cast String objects" do
|
33
|
+
@property.typecast(ip_string).should == ip
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should cast Integer objects" do
|
37
|
+
@property.typecast(ip_number).should == ip
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not cast negative numbers" do
|
41
|
+
@property.typecast(-1).should == nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not cast empty-strings" do
|
45
|
+
@property.typecast('').should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not cast nil" do
|
49
|
+
@property.typecast(nil).should be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "dump" do
|
54
|
+
it "should dump an IPAddr object" do
|
55
|
+
@property.dump(ip).should == ip_number
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not dump nil" do
|
59
|
+
@property.dump(nil).should be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/property'
|
3
|
+
|
4
|
+
require 'dm-core/property/legacy/time_string'
|
5
|
+
|
6
|
+
describe DataMapper::Property::Legacy::TimeString do
|
7
|
+
include Helpers::Property
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
property(DataMapper::Property::Legacy::TimeString)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:time_string) { '2010-11-05 00:00:00 -0700' }
|
14
|
+
let(:time) { Time.parse(time_string) }
|
15
|
+
let(:date) { Date.parse(time_string) }
|
16
|
+
|
17
|
+
describe "load" do
|
18
|
+
it "should load Time strings" do
|
19
|
+
@property.load(time_string).should == time
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should load Date strings" do
|
23
|
+
@property.load(time_string).should == time
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not load empty-strings" do
|
27
|
+
@property.load('').should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not load nil" do
|
31
|
+
@property.load(nil).should be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "typecast" do
|
36
|
+
it "should cast Time objects" do
|
37
|
+
@property.typecast(time).should == time
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should cast Date objects" do
|
41
|
+
@property.typecast(date).should == time
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should cast String objects" do
|
45
|
+
@property.typecast(time_string).should == time
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not cast empty-strings" do
|
49
|
+
@property.typecast('').should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not cast nil" do
|
53
|
+
@property.typecast(nil).should be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "dump" do
|
58
|
+
it "should dump a Time object" do
|
59
|
+
@property.dump(time).should == time_string
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should dump a Date object" do
|
63
|
+
@property.dump(date).should == time_string
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not dump nil" do
|
67
|
+
@property.dump(nil).should be_nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/property'
|
3
|
+
|
4
|
+
require 'dm-core/property/legacy/uri_text'
|
5
|
+
|
6
|
+
describe DataMapper::Property::Legacy::URIText do
|
7
|
+
include Helpers::Property
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
property(DataMapper::Property::Legacy::URIText)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:raw_text) { 'one two' }
|
14
|
+
let(:uri_text) { 'one%20two' }
|
15
|
+
|
16
|
+
describe "load" do
|
17
|
+
it "should load Date Strings" do
|
18
|
+
@property.load(uri_text).should == raw_text
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not load empty-strings" do
|
22
|
+
@property.load('').should be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not load nil" do
|
26
|
+
@property.load(nil).should be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "dump" do
|
31
|
+
it "should dump raw text" do
|
32
|
+
@property.dump(raw_text).should == uri_text
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not dump nil" do
|
36
|
+
@property.dump(nil).should be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-types-legacy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Postmodern
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-06 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: dm-core
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: yard
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
- 6
|
60
|
+
- 0
|
61
|
+
version: 0.6.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
description: dm-types-legacy is a collection of legacy data types for working with legacy databases or unsanitized data.
|
66
|
+
email: postmodern.mod3@gmail.com
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- README.md
|
73
|
+
files:
|
74
|
+
- .rspec
|
75
|
+
- .yardopts
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- dm-types-legacy.gemspec
|
81
|
+
- gemspec.yml
|
82
|
+
- lib/dm-core/property/legacy.rb
|
83
|
+
- lib/dm-core/property/legacy/date_string.rb
|
84
|
+
- lib/dm-core/property/legacy/html_text.rb
|
85
|
+
- lib/dm-core/property/legacy/numeric_ip_addr.rb
|
86
|
+
- lib/dm-core/property/legacy/time_string.rb
|
87
|
+
- lib/dm-core/property/legacy/uri_text.rb
|
88
|
+
- lib/dm-types/legacy.rb
|
89
|
+
- spec/helpers/property.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/unit/data_string_spec.rb
|
92
|
+
- spec/unit/html_text_spec.rb
|
93
|
+
- spec/unit/numeric_ip_addr_spec.rb
|
94
|
+
- spec/unit/time_string_spec.rb
|
95
|
+
- spec/unit/uri_text_spec.rb
|
96
|
+
has_rdoc: yard
|
97
|
+
homepage: http://github.com/postmodern/dm-types-legacy
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 1
|
120
|
+
- 3
|
121
|
+
- 6
|
122
|
+
version: 1.3.6
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project: dm-types-legacy
|
126
|
+
rubygems_version: 1.3.7
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: A collection of legacy data types for DataMapper.
|
130
|
+
test_files:
|
131
|
+
- spec/unit/time_string_spec.rb
|
132
|
+
- spec/unit/html_text_spec.rb
|
133
|
+
- spec/unit/numeric_ip_addr_spec.rb
|
134
|
+
- spec/unit/uri_text_spec.rb
|
135
|
+
- spec/unit/data_string_spec.rb
|