active_fedora-registered_attributes 0.0.4 → 0.0.5

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: 442d6b54af6a2c2152ba369fa9073f1feaffb702
4
- data.tar.gz: 83cb1a9300bc968d97d9be7663b00de3550f6b67
3
+ metadata.gz: a1756c151adf167f02b7a6b31deba661e7b84c66
4
+ data.tar.gz: 37e4c184025058ac8b3cc3ad1230350caa175ab6
5
5
  SHA512:
6
- metadata.gz: 78328051c5f19089a7de690781026cea8451dd67cc753b3d5adf6e622d6813c809ff0b7f233ff3775af185db18e29792b05d70bb322b9fa7fee54abfd09339cb
7
- data.tar.gz: a30772aaa59fe59667d531f794cb6f33e05f7ce08fb087e0e2c166d5f8439a0cd1628775f39501bfb8701f2b2574429e7209ae6b839edc6c8141e3b395edc171
6
+ metadata.gz: 53f179779e1e5de46e1033ddb603a6fb74afaa08b9fc6b823ed6dcb0253748d170d2cc1976492cf4c4a8a6d0692da810e1982e8fd8759bafd5eed9a134666968
7
+ data.tar.gz: 60f3f297a80e959a68edc97d05eca788c4d6e7ea547b3be3d7ad0af2773a7bacbb39d6319c5d27b96157d029f92f5e3b13c98872183ab9a3a010b7386ff93439
data/README.md CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
 
28
28
  ## Usage
29
29
 
30
- class Foo < ActiveRecord::Base
30
+ class Foo < ActiveFedora::Base
31
31
  include ActiveFedora::RegisteredAttributes
32
32
 
33
33
  has_metadata name: "descMetadata", type: FooMetadataDatastream
@@ -17,6 +17,8 @@ module ActiveFedora
17
17
  # @option options [Boolean] :displayable (true)
18
18
  # @option options [Boolean] :editable (true)
19
19
  # By marking this attribute :editable
20
+ # @option options [Boolean] :skip_accessor (false)
21
+ # Don't attempt to create the setter/getter if there is no :datastream option
20
22
  # @option options [Hash] :form
21
23
  # Additional options for a form builder (i.e. class, id, data-attribute)
22
24
  # @option options [Symbol, String, Nil, Hash] :datastream
@@ -37,9 +39,9 @@ module ActiveFedora
37
39
  # @option options [#to_s] :hint
38
40
  # A supplement to the Attribute's :label
39
41
  def initialize(context_class, name, options = {})
40
- @context_class = context_class
41
42
  @options = options.symbolize_keys
42
- @options.assert_valid_keys(:default, :displayable, :editable, :form, :datastream, :validates, :multiple, :writer, :reader, :label, :hint)
43
+ @options.assert_valid_keys(:default, :displayable, :editable, :form, :datastream, :validates, :multiple, :writer, :reader, :label, :hint, :skip_accessor)
44
+ @context_class = context_class
43
45
  @datastream = @options.fetch(:datastream, false)
44
46
  @name = name
45
47
  @options[:multiple] = false unless @options.key?(:multiple)
@@ -64,16 +66,25 @@ module ActiveFedora
64
66
  end
65
67
 
66
68
  def with_delegation_options
67
- yield(name, options_for_delegation) if datastream
69
+ yield(name, options_for_delegation) if with_delegation?
68
70
  end
71
+ def with_delegation?; datastream; end
72
+ private :with_delegation?
69
73
 
70
74
  def with_validation_options
71
- yield(name, options[:validates]) if options[:validates]
75
+ yield(name, options[:validates]) if with_validation?
72
76
  end
77
+ def with_validation?; options[:validates]; end
78
+ private :with_validation?
73
79
 
74
80
  def with_accession_options
75
- yield(name, {}) if !datastream
81
+ yield(name, {}) if with_accession?
82
+ end
83
+ def with_accession?
84
+ return false if options[:skip_accessor]
85
+ !datastream
76
86
  end
87
+ private :with_accession?
77
88
 
78
89
  def options_for_input(overrides = {})
79
90
  options[:form].tap {|hash|
@@ -1,5 +1,5 @@
1
1
  module ActiveFedora
2
2
  module RegisteredAttributes
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ describe ActiveFedora::RegisteredAttributes::Attribute do
6
6
  let(:field_name) { :title }
7
7
  let(:datastream) { 'properties' }
8
8
  let(:validation_options) {{ presence: true }}
9
+ let(:skip_accessor) { false }
9
10
  let(:options) {
10
11
  {
11
12
  datastream: datastream, hint: 'Your title',
@@ -120,6 +121,7 @@ describe ActiveFedora::RegisteredAttributes::Attribute do
120
121
  end
121
122
 
122
123
  describe '#with_accession_options' do
124
+ let(:options) { { datastream: 'hello' } }
123
125
  describe 'with a datastream' do
124
126
  it 'does not yield name nor options' do
125
127
  @yielded = false
@@ -131,7 +133,7 @@ describe ActiveFedora::RegisteredAttributes::Attribute do
131
133
  end
132
134
 
133
135
  describe 'without datastream' do
134
- let(:datastream) { nil }
136
+ let(:options) { { datastream: nil } }
135
137
  it 'yields name and options for #accession' do
136
138
  @yielded = false
137
139
  subject.with_accession_options {|name,opts|
@@ -142,6 +144,18 @@ describe ActiveFedora::RegisteredAttributes::Attribute do
142
144
  expect(@yielded).to eq(true)
143
145
  end
144
146
  end
147
+
148
+ describe 'without datastream and skipping accessor' do
149
+ let(:options) { {datastream: nil, skip_accessor: true} }
150
+ it 'does not yield accession options' do
151
+ @yielded = false
152
+ puts subject.send(:options)
153
+ subject.with_accession_options {|name,opts|
154
+ @yielded = true
155
+ }
156
+ expect(@yielded).to eq(false)
157
+ end
158
+ end
145
159
  end
146
160
 
147
161
  describe '#options_for_input' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fedora-registered_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
11
+ date: 2013-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active-fedora