dyoder-filebase 0.3.0 → 0.3.1
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.
- data/lib/filebase/attributes.rb +11 -25
- metadata +1 -1
data/lib/filebase/attributes.rb
CHANGED
@@ -1,47 +1,33 @@
|
|
1
1
|
module Attributes
|
2
2
|
|
3
|
-
def initialize(hash = {} )
|
4
|
-
attributes = hash
|
5
|
-
end
|
3
|
+
def initialize( hash = {} ) ; self.attributes = hash ; end
|
6
4
|
|
7
5
|
def attributes=( hash )
|
8
6
|
# copy the hash, converting all keys to strings
|
9
7
|
@attrs = hash.inject({}) { |h,p| k,v = p; h[k.to_s] = v; h }
|
10
8
|
end
|
11
9
|
|
12
|
-
def attributes
|
13
|
-
@attrs ||= {}
|
14
|
-
end
|
10
|
+
def attributes ; @attrs ||= {} ; end
|
15
11
|
|
16
12
|
def method_missing(name,*args)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
get(name)
|
13
|
+
case args.length
|
14
|
+
when 0 then get( name.to_s )
|
15
|
+
when 1 then set( name.to_s[0..-2], args[0] )
|
16
|
+
else raise ArgumentError.new("#{args.length} for 0 or 1")
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
|
-
def [](name)
|
26
|
-
get(name)
|
27
|
-
end
|
20
|
+
def [](name) ; get(name) ; end
|
28
21
|
|
29
|
-
def []=(name,val)
|
30
|
-
set(name,val)
|
31
|
-
end
|
22
|
+
def []=(name,val) ; set(name,val) ; end
|
32
23
|
|
33
|
-
def set(name, val)
|
34
|
-
attributes[name.to_s] = val
|
35
|
-
end
|
24
|
+
def set(name, val) ; attributes[name.to_s] = val ; end
|
36
25
|
|
37
26
|
def get(name)
|
38
|
-
rval = attributes[name.to_s]
|
39
|
-
rval.is_a?( Hash ) ? Attributes.new( rval ) : rval
|
27
|
+
( ( rval = attributes[name.to_s] ).is_a?( Hash ) and self.new( rval ) ) or rval
|
40
28
|
end
|
41
29
|
|
42
|
-
def to_h
|
43
|
-
@attrs
|
44
|
-
end
|
30
|
+
def to_h ; @attrs ; end
|
45
31
|
|
46
32
|
alias_method :to_hash, :to_h
|
47
33
|
|