active-triples 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e39f588d57dbf6bf017fd8d89be33cc2614cd11
4
- data.tar.gz: 0cc21f34df785724b9551c5365b8c31e5de7cd12
3
+ metadata.gz: 69f4bbb38bbc80b3dcb2f5250390db3a6519f70a
4
+ data.tar.gz: 695a3c37c83a8fd57902dd1d444418f637299208
5
5
  SHA512:
6
- metadata.gz: ad58904cf28803ef6f977792cce6bc8127de400a7b68121e109011e1bb4bde504fe0d56c971fd26ea1bccc444d23894333a24e44ce06a9f3d8c05da0e05ed347
7
- data.tar.gz: 3078779a4860330222361efb8e9857f33d71ed76dca1c8934287d13537aa316f71f1bbf060e1a69848d123ea0e0d2b96c4ad84606f358062c9ea5ddcb1fe719c
6
+ metadata.gz: 6d7e2610c7b7d621d8979ada3384b799dfe4002c62d308416233f15ab05bf3dc09b4f19a621801912d8eec49e3edbb9d6730996aaf03e5082cee90f3731f96ee
7
+ data.tar.gz: ba886577caa4650341a311a0097489875fb4ef557fc69858c17c8058c749c16a710fad5889f3ee1f9f7f8fd2148583897fdb50516d54efdfdb6d2faf0738af2a
@@ -53,9 +53,16 @@ module ActiveTriples
53
53
  # @param [Hash] opts for this property, must include a :predicate
54
54
  # @yield [index] index sets solr behaviors for the property
55
55
  def property(name, opts={}, &block)
56
+ raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name? name
56
57
  reflection = PropertyBuilder.build(self, name, opts, &block)
57
58
  Reflection.add_reflection self, name, reflection
58
59
  end
60
+
61
+ def protected_property_name?(name)
62
+ reject = self.instance_methods.map! { |s| s.to_s.gsub(/=$/, '').to_sym }
63
+ reject -= properties.keys.map { |k| k.to_sym }
64
+ reject.include? name
65
+ end
59
66
 
60
67
  ##
61
68
  # Given a property name or a predicate, return the configuration
@@ -1,3 +1,3 @@
1
1
  module ActiveTriples
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -38,6 +38,22 @@ describe ActiveTriples::Properties do
38
38
  DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => "FakeClassName"
39
39
  expect(DummyProperties.reflect_on_property(:title)[:class_name]).to eq "FakeClassName"
40
40
  end
41
+
42
+ it 'raises error when defining properties that are already methods' do
43
+ DummyProperties.send :define_method, :type, lambda { }
44
+ expect { DummyProperties.property :type, :predicate => RDF::DC.type }.to raise_error ArgumentError
45
+ end
46
+
47
+ it 'raises error when defining properties already have method setters' do
48
+ DummyProperties.send :define_method, :type=, lambda { }
49
+ expect { DummyProperties.property :type, :predicate => RDF::DC.type }.to raise_error ArgumentError
50
+ end
51
+
52
+ it 'allows resetting of properties' do
53
+ DummyProperties.property :title, :predicate => RDF::DC.alternative
54
+ DummyProperties.property :title, :predicate => RDF::DC.title
55
+ expect(DummyProperties.reflect_on_property(:title).predicate).to eq RDF::DC.title
56
+ end
41
57
  end
42
58
 
43
59
  describe '#config_for_term_or_uri' do
@@ -549,7 +549,7 @@ describe ActiveTriples::Resource do
549
549
  before do
550
550
  class DummyPerson < ActiveTriples::Resource
551
551
  configure :type => RDF::URI('http://example.org/Person')
552
- property :name, :predicate => RDF::FOAF.name
552
+ property :foaf_name, :predicate => RDF::FOAF.name
553
553
  property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
554
554
  property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
555
555
  end
@@ -579,13 +579,13 @@ describe ActiveTriples::Resource do
579
579
 
580
580
  let (:person1) do
581
581
  p = DummyPerson.new
582
- p.name = 'Alice'
582
+ p.foaf_name = 'Alice'
583
583
  p
584
584
  end
585
585
 
586
586
  let (:person2) do
587
587
  p = DummyPerson.new
588
- p.name = 'Bob'
588
+ p.foaf_name = 'Bob'
589
589
  p
590
590
  end
591
591
 
@@ -614,7 +614,7 @@ END
614
614
  document2.creator = person1
615
615
  person1.knows = person2
616
616
  subject.item = [document1]
617
- expect(subject.item.first.creator.first.knows.first.name).to eq ['Bob']
617
+ expect(subject.item.first.creator.first.knows.first.foaf_name).to eq ['Bob']
618
618
  end
619
619
  end
620
620
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-triples
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-21 00:00:00.000000000 Z
12
+ date: 2014-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf