minimapper 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,28 +4,46 @@ module Minimapper
4
4
  module Entity
5
5
  module Attributes
6
6
  def attributes(*list)
7
- list.each do |attribute|
8
- type = nil
7
+ columns = add_columns(list)
8
+ columns.each do |column|
9
+ define_reader(column)
10
+ define_writer(column)
11
+ end
12
+ end
9
13
 
10
- if attribute.is_a?(Array)
11
- attribute, type = attribute
12
- end
14
+ def column_names
15
+ @entity_columns.map(&:name).map(&:to_s)
16
+ end
13
17
 
14
- define_method(attribute) do
15
- attributes[attribute]
16
- end
18
+ private
17
19
 
18
- define_method("#{attribute}=") do |value|
19
- attributes[attribute] = Convert.new(value).to(type)
20
- end
20
+ def add_columns(list)
21
+ @entity_columns ||= []
22
+ @entity_columns |= list.map { |data| Column.new(data) }
23
+ end
24
+
25
+ def define_reader(column)
26
+ define_method(column.name) do
27
+ attributes[column.name]
21
28
  end
29
+ end
22
30
 
23
- @@column_names ||= []
24
- @@column_names |= list
31
+ def define_writer(column)
32
+ define_method("#{column.name}=") do |value|
33
+ attributes[column.name] = Convert.new(value).to(column.type)
34
+ end
25
35
  end
26
36
 
27
- def column_names
28
- @@column_names.map { |column| column.is_a?(Array) ? column.first : column }.map(&:to_s)
37
+ class Column
38
+ attr_reader :name, :type
39
+
40
+ def initialize(data)
41
+ if data.is_a?(Array)
42
+ @name, @type = data
43
+ else
44
+ @name = data
45
+ end
46
+ end
29
47
  end
30
48
  end
31
49
  end
@@ -1,3 +1,3 @@
1
1
  module Minimapper
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/unit/entity_spec.rb CHANGED
@@ -9,6 +9,11 @@ class TestUser
9
9
  attributes :name
10
10
  end
11
11
 
12
+ class TestProject
13
+ include Minimapper::Entity
14
+ attributes :title
15
+ end
16
+
12
17
  describe Minimapper::Entity do
13
18
  it "handles base attributes" do
14
19
  entity = TestEntity.new
@@ -82,4 +87,8 @@ describe Minimapper::Entity, "self.column_names" do
82
87
  # used by some rails plugins
83
88
  TestUser.column_names.should == [ "id", "created_at", "updated_at", "name" ]
84
89
  end
90
+
91
+ it "does not leak between different models" do
92
+ TestProject.column_names.should == [ "id", "created_at", "updated_at", "title" ]
93
+ end
85
94
  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.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70350098645360 !ruby/object:Gem::Requirement
16
+ requirement: &70245281835840 !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: *70350098645360
24
+ version_requirements: *70245281835840
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: 4282956153133681718
80
+ hash: -1233947130064928400
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: 4282956153133681718
89
+ hash: -1233947130064928400
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.5