representation 0.1.1 → 0.1.2
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.md +2 -2
- data/VERSION +1 -1
- data/lib/representation/active_record.rb +6 -1
- data/representation.gemspec +2 -3
- data/spec/representation_spec.rb +8 -0
- metadata +3 -4
- data/spec/support/representation.sqlite3 +0 -0
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# representation
|
2
2
|
Create different, named representations of a resource for cleaner state representation.
|
3
|
+
See: http://en.wikipedia.org/wiki/Representational_State_Transfer#Central_principle
|
3
4
|
|
4
5
|
## Install
|
5
6
|
|
@@ -9,8 +10,7 @@ Create different, named representations of a resource for cleaner state represen
|
|
9
10
|
## Usage
|
10
11
|
|
11
12
|
```ruby
|
12
|
-
class User < ActiveRecord::Base
|
13
|
-
include Representation
|
13
|
+
class User < ActiveRecord::Base
|
14
14
|
representation :public, :name, :calculated_age
|
15
15
|
representation :internal, :name, :ssn, :age
|
16
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
module Representation
|
4
|
+
|
5
|
+
class UnknownRepresentationError < StandardError; end
|
6
|
+
|
4
7
|
module ActiveRecord
|
5
8
|
extend ActiveSupport::Concern
|
6
9
|
|
@@ -17,6 +20,7 @@ module Representation
|
|
17
20
|
representations.keys
|
18
21
|
end
|
19
22
|
def values_for_representation(name)
|
23
|
+
raise UnknownRepresentationError, "Unknown Representation '#{name}'" unless representation_names.include?(name)
|
20
24
|
representations[name]
|
21
25
|
end
|
22
26
|
end
|
@@ -46,7 +50,8 @@ module Representation
|
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
49
|
-
|
53
|
+
|
54
|
+
alias_method :as, :representation
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
data/representation.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{representation}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Johnson"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-21}
|
13
13
|
s.description = %q{Create different, named representations of a resource for cleaner state representation.}
|
14
14
|
s.email = %q{findchris@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,7 +33,6 @@ Gem::Specification.new do |s|
|
|
33
33
|
"spec/spec_helper.rb",
|
34
34
|
"spec/support/connection.rb",
|
35
35
|
"spec/support/models.rb",
|
36
|
-
"spec/support/representation.sqlite3",
|
37
36
|
"spec/support/schema.rb"
|
38
37
|
]
|
39
38
|
s.homepage = %q{http://github.com/findchris/representation}
|
data/spec/representation_spec.rb
CHANGED
@@ -117,6 +117,14 @@ describe "Representation" do
|
|
117
117
|
public_user.name = 'Tweedle Dee'
|
118
118
|
user.name.should == 'Tweedle Dum'
|
119
119
|
end
|
120
|
+
it "should raise a Representation::UnknownRepresentationError when referencing an unknown representation" do
|
121
|
+
user = User.new(:name => 'Tweedle Dum', :age => 42)
|
122
|
+
lambda { user.representation(:invalid) }.should raise_error Representation::UnknownRepresentationError
|
123
|
+
end
|
124
|
+
it "should allow #representation to be accessed via the #as alias" do
|
125
|
+
user = User.new(:name => 'Tweedle Dum', :age => 42)
|
126
|
+
user.as(:public).inspect.should == user.representation(:public).inspect # hacky equality test
|
127
|
+
end
|
120
128
|
end
|
121
129
|
context "ActiveRecord" do
|
122
130
|
it "should include the Representation module into ActiveRecord" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: representation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Johnson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-21 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -116,7 +116,6 @@ files:
|
|
116
116
|
- spec/spec_helper.rb
|
117
117
|
- spec/support/connection.rb
|
118
118
|
- spec/support/models.rb
|
119
|
-
- spec/support/representation.sqlite3
|
120
119
|
- spec/support/schema.rb
|
121
120
|
has_rdoc: true
|
122
121
|
homepage: http://github.com/findchris/representation
|
@@ -132,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
131
|
requirements:
|
133
132
|
- - ">="
|
134
133
|
- !ruby/object:Gem::Version
|
135
|
-
hash: -
|
134
|
+
hash: -1114165197948906775
|
136
135
|
segments:
|
137
136
|
- 0
|
138
137
|
version: "0"
|
Binary file
|