Module: FedoraLens

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Included in:
TestClass
Defined in:
lib/fedora_lens.rb,
lib/fedora_lens/lens.rb,
lib/fedora_lens/errors.rb,
lib/fedora_lens/lenses.rb,
lib/fedora_lens/version.rb,
lib/fedora_lens/lens_tests.rb,
lib/fedora_lens/attribute_methods.rb,
lib/fedora_lens/attribute_methods/read.rb,
lib/fedora_lens/attribute_methods/write.rb,
lib/fedora_lens/attribute_methods/declarations.rb

Defined Under Namespace

Modules: AttributeMethods, ClassMethods, LensTests, Lenses Classes: AttributeNotSupportedError, FedoraLensError, Lens, RecordNotSaved

Constant Summary collapse

HOST =
"http://localhost:8983/fedora/rest"
VERSION =
'0.0.11'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_pathObject



39
40
41
# File 'lib/fedora_lens.rb', line 39

def base_path
  @@base_path ||= ''
end

.base_path=(path) ⇒ Object

Set a base path if you want to put all your objects below a certain path example:

FedoraLens.base_path = '/text


46
47
48
# File 'lib/fedora_lens.rb', line 46

def base_path= path
  @@base_path =  path
end

.connectionObject



31
32
33
# File 'lib/fedora_lens.rb', line 31

def connection
  @@connection ||= Ldp::Client.new(host)
end

.hostObject



35
36
37
# File 'lib/fedora_lens.rb', line 35

def host
  HOST
end

.id_to_uri(id) ⇒ Object



50
51
52
53
54
# File 'lib/fedora_lens.rb', line 50

def id_to_uri(id)
  id = "/#{id}" unless id.start_with? '/'
  id = FedoraLens.base_path + id unless id.start_with? "#{FedoraLens.base_path}/"
  FedoraLens.host + id
end

.uri_to_id(uri) ⇒ Object



56
57
58
# File 'lib/fedora_lens.rb', line 56

def uri_to_id(uri)
  uri.to_s.sub(FedoraLens.host + FedoraLens.base_path, '')
end

Instance Method Details

#deleteObject



92
93
94
# File 'lib/fedora_lens.rb', line 92

def delete
  @orm.resource.delete
end

#errorsObject



76
77
78
79
80
81
# File 'lib/fedora_lens.rb', line 76

def errors
  obj = Object.new
  def obj.[](key)         [] end
  def obj.full_messages() [] end
  obj
end

#idObject



112
113
114
# File 'lib/fedora_lens.rb', line 112

def id
  self.class.uri_to_id(URI.parse(uri)) if uri.present?
end

#initialize(subject_or_data = {}, data = nil) ⇒ Object



70
71
72
# File 'lib/fedora_lens.rb', line 70

def initialize(subject_or_data = {}, data = nil)
  init_core(subject_or_data, data)
end

#new_record?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/fedora_lens.rb', line 104

def new_record?
  @orm.resource.new?
end

#persisted?Boolean

Returns:

  • (Boolean)


74
# File 'lib/fedora_lens.rb', line 74

def persisted?()      false end

#read_attribute_for_validation(key) ⇒ Object



83
84
85
# File 'lib/fedora_lens.rb', line 83

def read_attribute_for_validation(key)
  @attributes[key]
end

#reloadObject



87
88
89
90
# File 'lib/fedora_lens.rb', line 87

def reload
  @orm = @orm.reload
  @attributes = get_attributes_from_orm(@orm)
end

#saveObject



96
97
98
# File 'lib/fedora_lens.rb', line 96

def save
  new_record? ? create_record : update_record
end

#save!Object



100
101
102
# File 'lib/fedora_lens.rb', line 100

def save!
  save || raise(RecordNotSaved)
end

#uriObject



108
109
110
# File 'lib/fedora_lens.rb', line 108

def uri
  @orm.try(:resource).try(:subject_uri).try(:to_s)
end