Module: Attributes

Defined in:
lib/filebase/attributes.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/filebase/attributes.rb', line 17

def method_missing(name,*args)
  if args.empty?
     get(name.to_s)
   elsif (name = name.to_s) =~ /=$/
     set(name.chop, args[0])
   else
     super
   end
end

Instance Method Details

#[](name) ⇒ Object Also known as: get



27
28
29
30
31
32
33
# File 'lib/filebase/attributes.rb', line 27

def [](name)
  if ( rval = @attrs[name = name.to_s] ).is_a?( Hash )
    @attrs[name] = self.class.new( rval )
   else
     rval
   end  
end

#[]=(name, val) ⇒ Object Also known as: set



35
# File 'lib/filebase/attributes.rb', line 35

def []=(name,val) ; @attrs[name.to_s] = val ; end

#attributesObject



9
# File 'lib/filebase/attributes.rb', line 9

def attributes ; @attrs ||= {} ; end

#attributes=(hash) ⇒ Object



5
6
7
# File 'lib/filebase/attributes.rb', line 5

def attributes=( hash )
  @attrs = {}; hash.each { |k,v| @attrs[k.to_s] = v }
end

#delete(key) ⇒ Object



15
# File 'lib/filebase/attributes.rb', line 15

def delete( key ) ; @attrs.delete( key.to_s ) ; end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


11
# File 'lib/filebase/attributes.rb', line 11

def has_key?( key ) ; @attrs.has_key?( key.to_s ) ; end

#initialize(assigns = {}) ⇒ Object



3
# File 'lib/filebase/attributes.rb', line 3

def initialize( assigns = {} ) ; self.attributes = assigns ; end

#keysObject



13
# File 'lib/filebase/attributes.rb', line 13

def keys; @attrs.keys; end

#to_hObject Also known as: to_hash



37
# File 'lib/filebase/attributes.rb', line 37

def to_h ; @attrs ; end