sufia-models 3.2.1 → 3.3.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: 79d76149b1df8f00315c569a3e43db45937c92b7
4
- data.tar.gz: 6bd416eab76f790a73f16a07a2abd337cfcd4e4e
3
+ metadata.gz: c502e9e177160c114e97d7b850a36882f4856d86
4
+ data.tar.gz: d51f3556a0339952d45c88c41fc246c520a5052c
5
5
  SHA512:
6
- metadata.gz: b776c781c53753d4de08fced94345ed0b45117c63012f8b2042fd18a6633d5c4ac1cb9a2c38cf666b7238b2307de0fd2deffda00db2d14721ec06d66ced04131
7
- data.tar.gz: 70e8d9b4d5dc61fac26a93b76a45ca8deb743fec41a396c97b3f51d2a0f705ae5306841f33a9a30717eb1feadf346198dc613abd4f72592e2b4a6176f37e0a89
6
+ metadata.gz: 71e5ffd3b6af3eaf136ae260a90b6f121475bdfbb1e118b9676474b41b2f2f2daa124b131bcd184dba9a3af9375f9036e743ccb72703c7f1b2982edeee9b704d
7
+ data.tar.gz: 7821ecfc6d249c2d1bcfcac3567463942d07f81a7040ae49ba3b15ea7bc8cac058defa121116334a6351e9d840b222610d0b697653865212e6e9bd7731cc3216
@@ -2,5 +2,9 @@ class DomainTerm < ActiveRecord::Base
2
2
  deprecated_attr_accessible :model, :term
3
3
 
4
4
  # TODO we should add an index on this join table and remove the uniq query
5
- has_and_belongs_to_many :local_authorities, :uniq=> true
5
+ if Rails::VERSION::MAJOR > 3
6
+ has_and_belongs_to_many :local_authorities, -> {uniq}
7
+ else
8
+ has_and_belongs_to_many :local_authorities, :uniq=> true
9
+ end
6
10
  end
@@ -2,9 +2,15 @@ require 'rdf'
2
2
  require 'rdf/rdfxml'
3
3
 
4
4
  class LocalAuthority < ActiveRecord::Base
5
- deprecated_attr_accessible :name
6
- # TODO we should add an index on this join table and remove the uniq query
7
- has_and_belongs_to_many :domain_terms, :uniq=> true
5
+ deprecated_attr_accessible :name
6
+
7
+ if Rails::VERSION::MAJOR >= 4
8
+ # TODO we should add an index on this join table and remove the uniq query
9
+ has_and_belongs_to_many :domain_terms, -> { uniq }
10
+ else
11
+ has_and_belongs_to_many :domain_terms, :uniq=> true
12
+ end
13
+
8
14
  has_many :local_authority_entries
9
15
 
10
16
  def self.harvest_rdf(name, sources, opts = {})
@@ -57,7 +63,7 @@ class LocalAuthority < ActiveRecord::Base
57
63
  authority = self.find_by_name(name)
58
64
  return if authority.blank?
59
65
  model = model.to_s.sub(/RdfDatastream$/, '').underscore.pluralize
60
- domain_term = DomainTerm.find_or_create_by_model_and_term(:model => model, :term => term)
66
+ domain_term = DomainTerm.find_or_create_by(model: model, term: term)
61
67
  return if domain_term.local_authorities.include? authority
62
68
  domain_term.local_authorities << authority
63
69
  end
@@ -1,25 +1,44 @@
1
1
  class SingleUseLink < ActiveRecord::Base
2
2
 
3
- deprecated_attr_accessible :downloadKey, :expires, :itemId, :path
3
+ deprecated_attr_accessible :downloadKey, :path, :expires, :itemId
4
4
 
5
-
6
- def self.create_show(item_id)
7
- create_path(item_id, Sufia::Engine.routes.url_helpers.generic_file_path(item_id) )
8
- end
5
+ validate :expiration_date_cannot_be_in_the_past
6
+ validate :cannot_be_destroyed
7
+
8
+ after_initialize :set_defaults
9
9
 
10
- def self.create_download(item_id)
11
- create_path(item_id, Sufia::Engine.routes.url_helpers.download_path(item_id) )
10
+ def create_for_path path
11
+ self.class.create :itemId => itemId, :path => path
12
12
  end
13
-
13
+
14
14
  def expired?
15
- now = DateTime.now
16
- return (now > expires)
15
+ DateTime.now > expires
17
16
  end
18
-
17
+
18
+
19
+ def to_param
20
+ downloadKey
21
+ end
22
+
19
23
  protected
20
- def self.create_path(itemId, path)
21
- expires = DateTime.now.advance(hours:24)
22
- key = Digest::SHA2.new << rand(1000000000).to_s
23
- return create({downloadKey:key.to_s, expires:expires, path:path, itemId:itemId} )
24
+
25
+ def expiration_date_cannot_be_in_the_past
26
+ if expired?
27
+ errors.add(:expires, "can't be in the past")
28
+ end
29
+ end
30
+
31
+ def cannot_be_destroyed
32
+ if destroyed?
33
+ errors[:base] << "Single Use Link has already been used"
34
+ end
24
35
  end
25
- end
36
+
37
+ def set_defaults
38
+ if new_record?
39
+ self.expires ||= DateTime.now.advance(hours:24)
40
+ self.downloadKey ||= (Digest::SHA2.new << rand(1000000000).to_s).to_s
41
+ end
42
+ end
43
+
44
+ end
@@ -1,5 +1,5 @@
1
1
  module Sufia
2
2
  module Models
3
- VERSION = "3.2.1"
3
+ VERSION = "3.3.0"
4
4
  end
5
5
  end
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency 'resque-pool', '0.3.0'
38
38
  spec.add_dependency 'noid', '~> 0.6.6'
39
39
  spec.add_dependency 'mailboxer', '~> 0.11.0'
40
- spec.add_dependency 'acts_as_follower', '0.1.1'
40
+ spec.add_dependency 'acts_as_follower', '>= 0.1.1', '< 0.3'
41
41
  spec.add_dependency 'paperclip', '~> 3.4.0'
42
42
  spec.add_dependency 'zipruby', '0.3.6'
43
43
  spec.add_dependency 'hydra-derivatives', '~> 0.0.5'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sufia-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
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-09-10 00:00:00.000000000 Z
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -174,16 +174,22 @@ dependencies:
174
174
  name: acts_as_follower
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '='
177
+ - - '>='
178
178
  - !ruby/object:Gem::Version
179
179
  version: 0.1.1
180
+ - - <
181
+ - !ruby/object:Gem::Version
182
+ version: '0.3'
180
183
  type: :runtime
181
184
  prerelease: false
182
185
  version_requirements: !ruby/object:Gem::Requirement
183
186
  requirements:
184
- - - '='
187
+ - - '>='
185
188
  - !ruby/object:Gem::Version
186
189
  version: 0.1.1
190
+ - - <
191
+ - !ruby/object:Gem::Version
192
+ version: '0.3'
187
193
  - !ruby/object:Gem::Dependency
188
194
  name: paperclip
189
195
  requirement: !ruby/object:Gem::Requirement
@@ -340,8 +346,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
346
  version: '0'
341
347
  requirements: []
342
348
  rubyforge_project:
343
- rubygems_version: 2.0.3
349
+ rubygems_version: 2.0.5
344
350
  signing_key:
345
351
  specification_version: 4
346
352
  summary: Models and services for sufia
347
353
  test_files: []
354
+ has_rdoc: