minimapper 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -265,6 +265,16 @@ class User
265
265
  end
266
266
  ```
267
267
 
268
+ ### Protected attributes
269
+
270
+ We recommend using [strong_parameters](https://github.com/rails/strong_parameters) for attribute security, without including `ActiveModel::ForbiddenAttributesProtection`.
271
+
272
+ Use of `attr_accessible` or `attr_protected` may obstruct the mapper.
273
+
274
+ If you use Minimapper as intended, you only assign attributes on the entity. Once they're on the entity, the mapper will assume they're permitted to be persisted; and once they're in the record, the mapper will assume they are permitted for populating an entity.
275
+
276
+ (FIXME?: There's a ongoing discussion about whether Minimapper should actively bypass attribute protection, or encourage you not to use it, or what.)
277
+
268
278
  ### Associations
269
279
 
270
280
  There is no core support for associations, but we're implementing them in [minimapper-extras](https://github.com/barsoom/minimapper-extras) as we need them.
@@ -8,14 +8,15 @@ module Minimapper
8
8
 
9
9
  # By adding instance methods via an included module,
10
10
  # they become overridable with "super".
11
- instance_method_container = Module.new
11
+ unless @minimapper_instance_method_container
12
+ @minimapper_instance_method_container = Module.new
13
+ include @minimapper_instance_method_container
14
+ end
12
15
 
13
16
  columns.each do |column|
14
- define_reader(column, instance_method_container)
15
- define_writer(column, instance_method_container)
17
+ define_reader(column)
18
+ define_writer(column)
16
19
  end
17
-
18
- include instance_method_container
19
20
  end
20
21
 
21
22
  def attribute(*opts)
@@ -34,16 +35,16 @@ module Minimapper
34
35
  @entity_columns |= list.map { |data| Column.new(data) }
35
36
  end
36
37
 
37
- def define_reader(column, instance_method_container)
38
- instance_method_container.module_eval do
38
+ def define_reader(column)
39
+ @minimapper_instance_method_container.module_eval do
39
40
  define_method(column.name) do
40
41
  attributes[column.name]
41
42
  end
42
43
  end
43
44
  end
44
45
 
45
- def define_writer(column, instance_method_container)
46
- instance_method_container.module_eval do
46
+ def define_writer(column)
47
+ @minimapper_instance_method_container.module_eval do
47
48
  define_method("#{column.name}=") do |value|
48
49
  attributes[column.name] = Convert.new(value).to(column.type)
49
50
  end
@@ -1,3 +1,3 @@
1
1
  module Minimapper
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -33,4 +33,8 @@ describe Minimapper::Entity::Convert do
33
33
  it "does not make false nil" do
34
34
  described_class.new(false).to(:unknown).should eq(false)
35
35
  end
36
+
37
+ it "does not make false nil" do
38
+ described_class.new(false).to(:unknown).should eq(false)
39
+ end
36
40
  end
data/unit/entity_spec.rb CHANGED
@@ -9,6 +9,10 @@ class TestUser
9
9
  attributes :name
10
10
  end
11
11
 
12
+ class TestAgedUser < TestUser
13
+ attributes :age
14
+ end
15
+
12
16
  class TestProject
13
17
  include Minimapper::Entity
14
18
  attributes :title
@@ -87,6 +91,14 @@ describe Minimapper::Entity do
87
91
  entity.attributes[:id].should == 15
88
92
  end
89
93
 
94
+ it "inherits attributes" do
95
+ user = TestAgedUser.new
96
+ user.name = "Name"
97
+ user.age = 123
98
+ user.name.should == "Name"
99
+ user.age.should == 123
100
+ end
101
+
90
102
  it "is possible to override attribute readers with inheritance" do
91
103
  user = OverridingTestUser.new
92
104
  user.name = "pelle"
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.6.1
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-22 00:00:00.000000000 Z
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70347747664260 !ruby/object:Gem::Requirement
16
+ requirement: &70133111671800 !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: *70347747664260
24
+ version_requirements: *70133111671800
25
25
  description: A minimalistic way of separating your models from ORMs like ActiveRecord.
26
26
  email:
27
27
  - joakim.kolsjo@gmail.com
@@ -75,12 +75,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ segments:
79
+ - 0
80
+ hash: -2264146464665909809
78
81
  required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  none: false
80
83
  requirements:
81
84
  - - ! '>='
82
85
  - !ruby/object:Gem::Version
83
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -2264146464665909809
84
90
  requirements: []
85
91
  rubyforge_project:
86
92
  rubygems_version: 1.8.5