liaison 0.0.3 → 0.0.4
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/ChangeLog +10 -0
- data/NEWS +5 -0
- data/lib/liaison/presenter.rb +14 -5
- data/lib/liaison/version.rb +1 -1
- data/spec/presenter_spec.rb +16 -0
- metadata +5 -5
data/ChangeLog
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2011-11-07 Mike Burns <mburns@thoughtbot.com>
|
2
|
+
|
3
|
+
* presenter.rb, presenter_spec.rb: Define the model_name per-instance
|
4
|
+
instead of per-class. Suggestion by Peter Suschlik.
|
5
|
+
|
6
|
+
2011-11-07 Peter Suschlik
|
7
|
+
|
8
|
+
* presenter.rb, presenter_spec.rb: Define the field accessors per-instance
|
9
|
+
instead of per-class.
|
10
|
+
|
1
11
|
2011-10-20 Mike Burns <mburns@thoughtbot.com>
|
2
12
|
|
3
13
|
* presenter.rb, presenter_spec.rc: Don't name the struct so that we can
|
data/NEWS
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
New in 0.0.4:
|
2
|
+
|
3
|
+
* Field accessors and model_name now work per-instance instead of per-class, so
|
4
|
+
you can have more than one presenter in your system without it causing issues.
|
5
|
+
|
1
6
|
New in 0.0.3:
|
2
7
|
|
3
8
|
* Take care of a warning based on using a struct for the model_name.
|
data/lib/liaison/presenter.rb
CHANGED
@@ -17,19 +17,28 @@ class Presenter
|
|
17
17
|
# :fields => [:account_name, :email, :password],
|
18
18
|
# :validator => SignUpValidator)
|
19
19
|
def initialize(model_name, opts = {})
|
20
|
-
|
20
|
+
@model_name = model_name
|
21
21
|
|
22
22
|
@validator = opts[:validator]
|
23
23
|
@fields = opts[:fields]
|
24
24
|
|
25
|
-
|
25
|
+
if @fields && !@fields.empty?
|
26
|
+
(class << self; self; end).send(:attr_accessor, *@fields)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
# This only exists for ActiveModel::Naming
|
29
|
-
def
|
30
|
-
|
31
|
-
|
31
|
+
def class_with_model_name # :nodoc:
|
32
|
+
self.class_without_model_name.tap do |c|
|
33
|
+
c.instance_variable_set('@_model_name', @model_name)
|
34
|
+
(class << c; self; end).send(:define_method,:model_name) do
|
35
|
+
model_namer = Struct.new(:name).new(self.instance_variable_get('@_model_name'))
|
36
|
+
ActiveModel::Name.new(model_namer)
|
37
|
+
end
|
38
|
+
end
|
32
39
|
end
|
40
|
+
alias class_without_model_name class
|
41
|
+
alias class class_with_model_name
|
33
42
|
|
34
43
|
# This only exists for ActiveModel::Constructs
|
35
44
|
def persisted? # :nodoc:
|
data/lib/liaison/version.rb
CHANGED
data/spec/presenter_spec.rb
CHANGED
@@ -20,6 +20,22 @@ describe Presenter do
|
|
20
20
|
Presenter.new("another_model_name").class.model_name
|
21
21
|
# The result is that this should have no warning in the test output
|
22
22
|
end
|
23
|
+
|
24
|
+
it "sets attributes accessor per instance" do
|
25
|
+
foo = Presenter.new("foo", :fields => [:foo])
|
26
|
+
bar = Presenter.new("bar", :fields => [:bar])
|
27
|
+
foo.should respond_to(:foo)
|
28
|
+
bar.should respond_to(:bar)
|
29
|
+
foo.should_not respond_to(:bar)
|
30
|
+
bar.should_not respond_to(:foo)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets model name per instance" do
|
34
|
+
foo = Presenter.new("foo")
|
35
|
+
bar = Presenter.new("bar")
|
36
|
+
foo.class.model_name.should == "foo"
|
37
|
+
bar.class.model_name.should == "bar"
|
38
|
+
end
|
23
39
|
end
|
24
40
|
|
25
41
|
describe Presenter, 'validations' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liaison
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Burns
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activemodel
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements: []
|
114
114
|
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
116
|
+
rubygems_version: 1.8.10
|
117
117
|
signing_key:
|
118
118
|
specification_version: 3
|
119
119
|
summary: A Rails presenter class.
|