active_presenter 1.1.2 → 1.2.0

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.
data/README CHANGED
@@ -28,6 +28,12 @@ Creating a presenter is as simple as subclassing ActivePresenter::Base. Use the
28
28
  presents :user, :account
29
29
  end
30
30
 
31
+ In the above example, :user will (predictably) become User. If you want to override this behaviour, specify the desired types in a hash, as so:
32
+
33
+ class PresenterWithTwoAddresses < ActivePresenter::Base
34
+ presents :primary_address => Address, :secondary_address => Address
35
+ end
36
+
31
37
  === Instantiation
32
38
 
33
39
  Then, you can instantiate the presenter using either, or both of two forms.
@@ -14,17 +14,25 @@ module ActivePresenter
14
14
  # class SignupPresenter < ActivePresenter::Base
15
15
  # presents :user, :account
16
16
  # end
17
+ #
18
+ # In the above example, :user will (predictably) become User. If you want to override this behaviour, specify the desired types in a hash, as so:
17
19
  #
20
+ # class PresenterWithTwoAddresses < ActivePresenter::Base
21
+ # presents :primary_address => Address, :secondary_address => Address
22
+ # end
18
23
  #
19
24
  def self.presents(*types)
20
- attr_accessor *types
25
+ types_and_classes = types.extract_options!
26
+ types.each { |t| types_and_classes[t] = t.to_s.tableize.classify.constantize }
27
+
28
+ attr_accessor *types_and_classes.keys
21
29
 
22
- types.each do |t|
30
+ types_and_classes.keys.each do |t|
23
31
  define_method("#{t}_errors") do
24
32
  send(t).errors
25
33
  end
26
34
 
27
- presented[t] = t.to_s.tableize.classify.constantize
35
+ presented[t] = types_and_classes[t]
28
36
  end
29
37
  end
30
38
 
@@ -222,7 +230,7 @@ module ActivePresenter
222
230
  presentable = presentable_for(name)
223
231
  return false unless presentable
224
232
  flat_attribute = {flatten_attribute_name(name, presentable) => ''} #remove_att... normally takes a hash, so we use a ''
225
- presentable.to_s.tableize.classify.constantize.new.send(:remove_attributes_protected_from_mass_assignment, flat_attribute).empty?
233
+ presented[presentable].new.send(:remove_attributes_protected_from_mass_assignment, flat_attribute).empty?
226
234
  end
227
235
 
228
236
  def run_callbacks_with_halt(callback)
@@ -1,8 +1,8 @@
1
1
  module ActivePresenter
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 1
5
- TINY = 2
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/base_test.rb CHANGED
@@ -277,4 +277,14 @@ Expectations do
277
277
  expect true do
278
278
  SignupNoNilPresenter.new(:user => nil, :account => Account.new).save!
279
279
  end
280
+
281
+ expect Address do
282
+ PresenterWithTwoAddresses.new.secondary_address
283
+ end
284
+
285
+ expect "123 awesome st" do
286
+ p = PresenterWithTwoAddresses.new(:secondary_address_street => "123 awesome st")
287
+ p.save
288
+ p.secondary_address_street
289
+ end
280
290
  end
data/test/test_helper.rb CHANGED
@@ -39,6 +39,10 @@ class Account < ActiveRecord::Base; end
39
39
  class Address < ActiveRecord::Base; end
40
40
  class AccountInfo < ActiveRecord::Base; end
41
41
 
42
+ class PresenterWithTwoAddresses < ActivePresenter::Base
43
+ presents :address, :secondary_address => Address
44
+ end
45
+
42
46
  class SignupPresenter < ActivePresenter::Base
43
47
  presents :account, :user
44
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Golick & Daniel Haran
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-13 00:00:00 -04:00
12
+ date: 2009-05-17 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15