minimapper 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -173,12 +173,12 @@ It gets simpler to maintain if you use shared tests to test both implementations
173
173
 
174
174
  ### Typed attributes
175
175
 
176
- If you specify type, minimapper will attempt to convert into that type. Supported types: Integer and DateTime.
176
+ If you specify type, minimapper will attempt to convert into that type. Supported types: Integer and DateTime (:integer and :date_time).
177
177
 
178
178
  ``` ruby
179
179
  class User
180
180
  include Minimapper::Entity
181
- attributes [ :profile_id, Integer ]
181
+ attributes [ :profile_id, :integer ]
182
182
  end
183
183
 
184
184
  User.new(:profile_id => "10").profile_id # => 10
@@ -198,11 +198,11 @@ class ToDate
198
198
  end
199
199
  end
200
200
 
201
- Minimapper::Entity::Convert.register_converter(Date, ToDate.new)
201
+ Minimapper::Entity::Convert.register_converter(:date, ToDate.new)
202
202
 
203
203
  class User
204
204
  include Minimapper::Entity
205
- attributes [ :profile_id, Date ]
205
+ attributes [ :reminder_on, :date ]
206
206
  end
207
207
 
208
208
  User.new(:reminder_on => "2012-01-01").reminder # => #<Date: 2012-01-01 ...>
@@ -265,7 +265,6 @@ You need mysql and postgres installed (but they do not have to be running) to be
265
265
 
266
266
  ### Next
267
267
 
268
- * Add some way to extend type conversions to keep that part of minimapper small.
269
268
  * Extract entity and model class lookup code from the ar-mapper and reuse it in the memory mapper.
270
269
  * Change the memory mapper to store entity attributes, not entity instances.
271
270
  - Unless this makes it difficult to handle associated data.
@@ -10,7 +10,7 @@ module Minimapper
10
10
 
11
11
  def self.register_converter(type, converter)
12
12
  @@converters ||= {}
13
- @@converters[type.to_s] = converter
13
+ @@converters[type] = converter
14
14
  end
15
15
 
16
16
  def to(type)
@@ -20,13 +20,13 @@ module Minimapper
20
20
  converter_for(type).convert(value)
21
21
  end
22
22
 
23
- register_converter Integer, ToInteger.new
24
- register_converter DateTime, ToDateTime.new
23
+ register_converter :integer, ToInteger.new
24
+ register_converter :date_time, ToDateTime.new
25
25
 
26
26
  private
27
27
 
28
28
  def converter_for(type)
29
- @@converters.fetch(type.to_s, NoOpConverter.new)
29
+ @@converters.fetch(type, NoOpConverter.new)
30
30
  end
31
31
 
32
32
  class NoOpConverter
@@ -19,7 +19,7 @@ module Minimapper
19
19
  def self.included(klass)
20
20
  klass.send(:include, Minimapper::Entity::Rails)
21
21
  klass.send(:extend, Minimapper::Entity::Attributes)
22
- klass.attributes([ :id, :Integer ], [ :created_at, :DateTime ], [ :updated_at, :DateTime ])
22
+ klass.attributes([ :id, :integer ], [ :created_at, :date_time ], [ :updated_at, :date_time ])
23
23
  end
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Minimapper
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,22 +3,22 @@ require 'active_support/core_ext'
3
3
 
4
4
  describe Minimapper::Entity::Convert do
5
5
  it "converts strings into integers" do
6
- described_class.new('10').to(Integer).should == 10
7
- described_class.new(' 10 ').to(Integer).should == 10
6
+ described_class.new('10').to(:integer).should == 10
7
+ described_class.new(' 10 ').to(:integer).should == 10
8
8
  end
9
9
 
10
10
  it "converts datetime strings into datetimes" do
11
- described_class.new('2012-01-01 20:57').to(DateTime).should == DateTime.new(2012, 01, 01, 20, 57)
11
+ described_class.new('2012-01-01 20:57').to(:date_time).should == DateTime.new(2012, 01, 01, 20, 57)
12
12
  end
13
13
 
14
14
  it "make it nil when it can't convert" do
15
- described_class.new(' ').to(Integer).should be_nil
16
- described_class.new(' ').to(DateTime).should be_nil
17
- described_class.new('garbage').to(Integer).should be_nil
18
- described_class.new('garbage').to(DateTime).should be_nil
15
+ described_class.new(' ').to(:integer).should be_nil
16
+ described_class.new(' ').to(:date_time).should be_nil
17
+ described_class.new('garbage').to(:integer).should be_nil
18
+ described_class.new('garbage').to(:date_time).should be_nil
19
19
  end
20
20
 
21
21
  it "returns the value as-is when it does not know how to convert it" do
22
- described_class.new('foobar').to(Kernel).should == 'foobar'
22
+ described_class.new('foobar').to(:unknown).should == 'foobar'
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minimapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70178508749460 !ruby/object:Gem::Requirement
16
+ requirement: &70328752668500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70178508749460
24
+ version_requirements: *70328752668500
25
25
  description: A minimalistic way of separating your models from ORMs like ActiveRecord.
26
26
  email:
27
27
  - joakim.kolsjo@gmail.com
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: 3127199441283205218
80
+ hash: -4540271108059572460
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: 3127199441283205218
89
+ hash: -4540271108059572460
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.5