fedora_lens 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16b83b0c8b5f99413f3eec0f08a0b75609f35a7c
4
- data.tar.gz: dec9a72626b9c00511782586aa8b904f63558380
3
+ metadata.gz: c7eaf60a6e220490635c6c9eef2c99cbe7453eaf
4
+ data.tar.gz: a0e300edb02fbd2abfdeee0c5368e43df86a35e1
5
5
  SHA512:
6
- metadata.gz: 07dd2afaa5f9c46f2ecdbeba122c0aee828edf3240f2f52c37c3ecee72ad7ffef3a1a636389bfd6329b6997eb9b53cfcf4dd35681e0f64771a061d2294e25582
7
- data.tar.gz: 7c9928a40da331750b368189327bef44f446c82a9ea05ccf50f5be08682bf811e17927e2e2cb2de3d5f67d37265feed71f87231c87f87f2625bce683a40d35c6
6
+ metadata.gz: 4bd613f55ea525abba224a54ad39df2fcb0e8779bdbd4f95238c81e3c5b74dde7aeffb771e56b1d0bfdacdd2b3ce902db62747854b8cc4dfc682977f5eab7d06
7
+ data.tar.gz: 75a8cf0ac3f5d4ce1f7f26d3877e1cb64cc5d7bdd419458156cb84177d1ae2601cb6dbc6c3a40f9bb7fc2c2ff6029c126e81fcb39d077c5a643bb32fd93725b0
@@ -39,6 +39,18 @@ module FedoraLens
39
39
  included do
40
40
  class_attribute :attributes_as_lenses
41
41
  self.attributes_as_lenses = {}.with_indifferent_access
42
+ class << self
43
+ def inherited_with_lenses(kls) #:nodoc:
44
+ ## Do some inheritance logic that doesn't override Base.inherited
45
+ inherited_without_lenses kls
46
+ # each subclass should get a copy of the parent's attributes_as_lenses table,
47
+ # it should not add to the parent's definition table.
48
+ kls.attributes_as_lenses = kls.attributes_as_lenses.dup
49
+ end
50
+ alias_method_chain :inherited, :lenses
51
+ end
52
+
53
+
42
54
 
43
55
  initialize_generated_modules
44
56
  include Read
@@ -1,3 +1,3 @@
1
1
  module FedoraLens
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/fedora_lens.rb CHANGED
@@ -69,7 +69,6 @@ module FedoraLens
69
69
  end
70
70
 
71
71
  def save
72
- @orm = self.class.orm_to_hash.put(@orm, @attributes)
73
72
  new_record? ? create_record : update_record
74
73
  end
75
74
 
@@ -111,12 +110,14 @@ module FedoraLens
111
110
  end
112
111
 
113
112
  def create_record
113
+ push_attributes_to_orm
114
114
  orm.resource.create
115
115
  @new_record = false
116
116
  true
117
117
  end
118
118
 
119
119
  def update_record
120
+ push_attributes_to_orm
120
121
  # Fedora errors out when you try to set the rdf:type
121
122
  # see https://github.com/cbeer/ldp/issues/2
122
123
  orm.graph.delete([@orm.resource.subject_uri,
@@ -129,6 +130,10 @@ module FedoraLens
129
130
 
130
131
  private
131
132
 
133
+ def push_attributes_to_orm
134
+ @orm = self.class.orm_to_hash.put(@orm, @attributes)
135
+ end
136
+
132
137
  def get_attributes_from_orm(orm)
133
138
  self.class.orm_to_hash.get(orm).with_indifferent_access
134
139
  end
@@ -6,6 +6,7 @@ describe FedoraLens do
6
6
  class TestClass
7
7
  include FedoraLens
8
8
  attribute :title, [RDF::DC11.title, Lenses.single, Lenses.literal_to_string]
9
+ attribute :size, [RDF::DC11.subject, Lenses.single, Lenses.literal_to_string]
9
10
  # attribute :xml_title, [RDF::DC11.title, Lenses.single]
10
11
  end
11
12
 
@@ -16,6 +17,13 @@ describe FedoraLens do
16
17
 
17
18
  subject { TestClass.new }
18
19
 
20
+ # before do
21
+ # require 'logger'
22
+ # Ldp.logger = Logger.new(STDOUT).tap do |l|
23
+ # l.level = Logger::DEBUG
24
+ # end
25
+ # end
26
+
19
27
  describe ".find" do
20
28
  context "when the object doesn't exist" do
21
29
  it "should raise an error" do
@@ -42,12 +50,14 @@ describe FedoraLens do
42
50
 
43
51
  describe ".create" do
44
52
  subject { TestClass.create(attributes) }
53
+
45
54
  context "with a hash" do
46
55
  let(:attributes) { { title: "created resource" } }
47
56
  it "creates a resource" do
48
57
  expect(TestClass.find(subject.id).title).to eq "created resource"
49
58
  end
50
59
  end
60
+
51
61
  context "with nil" do
52
62
  let(:attributes) { nil }
53
63
  it "creates a resource" do
@@ -95,7 +105,9 @@ describe FedoraLens do
95
105
  describe ".attribute" do
96
106
  it "makes a setter/getter" do
97
107
  subject.title = "foo"
108
+ subject.size = "bar"
98
109
  expect(subject.title).to eq "foo"
110
+ expect(subject.size).to eq "bar"
99
111
  end
100
112
 
101
113
  it "should return nil if it hasn't been set" do
@@ -112,5 +124,35 @@ describe FedoraLens do
112
124
 
113
125
  it "mixes rdf and xml" do
114
126
  end
127
+
128
+ context "that are inherited" do
129
+ class TestSubclass < TestClass
130
+ attribute :description, [RDF::DC11.description, Lenses.single, Lenses.literal_to_string]
131
+ end
132
+
133
+ subject { TestSubclass.new }
134
+
135
+ it "should have accessor methods defined by the parent" do
136
+ subject.title = "foo"
137
+ subject.description = "bar"
138
+ expect(subject.title).to eq "foo"
139
+ expect(subject.description).to eq "bar"
140
+ end
141
+
142
+ context "a sibling class" do
143
+ class TestAnotherSubclass < TestClass
144
+ end
145
+
146
+ subject { TestAnotherSubclass }
147
+
148
+ it "instances should not have accessor methods defined by the other sibling" do
149
+ expect { subject.new.description }.to raise_error NoMethodError
150
+ end
151
+
152
+ it "should not have attribute lenses defined by the other sibling" do
153
+ expect(TestAnotherSubclass.attributes_as_lenses.keys).to_not include "description"
154
+ end
155
+ end
156
+ end
115
157
  end
116
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedora_lens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne