Class: Spotlight::MDItem

Inherits:
Object
  • Object
show all
Defined in:
lib/spotlight.rb

Defined Under Namespace

Classes: InvalidAttributeValueTypeError

Constant Summary collapse

VALID_ATTRIBUTE_VALUE_TYPE =
[String, Time, Fixnum, Bignum, Float, Array, NilClass, TrueClass, FalseClass]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MDItem

Returns a new instance of MDItem.

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/spotlight.rb', line 17

def initialize(path)
  raise ArgumentError, 'Path is nil' if path.nil?
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/spotlight.rb', line 16

def path
  @path
end

Instance Method Details

#==(obj) ⇒ Object



37
38
39
# File 'lib/spotlight.rb', line 37

def ==(obj)
  obj.is_a?(MDItem) && @path == obj.path
end

#[](attr_name) ⇒ Object



27
28
29
# File 'lib/spotlight.rb', line 27

def [](attr_name)
  Intern.get_attribute(@path, attr_name)
end

#[]=(attr_name, attr_value) ⇒ Object



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

def []=(attr_name, attr_value)
  validate(attr_value)
  Intern.set_attribute(@path, attr_name, attr_value)
end

#attributesObject



21
22
23
# File 'lib/spotlight.rb', line 21

def attributes
  Intern.attributes(@path)
end

#attributes=(attributes) ⇒ Object



24
25
26
# File 'lib/spotlight.rb', line 24

def attributes=(attributes)
  Intern.set_attributes(@path, attributes)
end

#reloadObject



34
35
36
# File 'lib/spotlight.rb', line 34

def reload
  self
end

#validate(value) ⇒ Object



41
42
43
# File 'lib/spotlight.rb', line 41

def validate(value)
  raise InvalidAttributeValueTypeError, "Invalid attribute value type #{value.class.inspect}, valid types: #{VALID_ATTRIBUTE_VALUE_TYPE.join(", ")}" unless VALID_ATTRIBUTE_VALUE_TYPE.include?(value.class)
end