Class: Bigbertha::Ref
- Inherits:
-
Object
show all
- Includes:
- Action
- Defined in:
- lib/bigbertha/ref.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Action
#dec, #get_priority, #get_rules, #inc, #push, #read, #remove, #set, #set_priority, #set_rules, #update
Constructor Details
#initialize(url, auth_token = nil) ⇒ Ref
Returns a new instance of Ref.
15
16
17
18
19
|
# File 'lib/bigbertha/ref.rb', line 15
def initialize( url, auth_token=nil )
@url = url
@uri = URI.parse( @url )
@auth_token = auth_token
end
|
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
7
8
9
|
# File 'lib/bigbertha/ref.rb', line 7
def uri
@uri
end
|
#url ⇒ Object
Returns the value of attribute url.
7
8
9
|
# File 'lib/bigbertha/ref.rb', line 7
def url
@url
end
|
Class Method Details
.evt_child_added ⇒ Object
10
|
# File 'lib/bigbertha/ref.rb', line 10
def self.evt_child_added; :add_child; end
|
.evt_child_changed ⇒ Object
11
|
# File 'lib/bigbertha/ref.rb', line 11
def self.evt_child_changed; :mod_child; end
|
.evt_child_moved ⇒ Object
13
|
# File 'lib/bigbertha/ref.rb', line 13
def self.evt_child_moved; :mv_child; end
|
.evt_child_removed ⇒ Object
12
|
# File 'lib/bigbertha/ref.rb', line 12
def self.evt_child_removed; :rm_child; end
|
.evt_value ⇒ Object
9
|
# File 'lib/bigbertha/ref.rb', line 9
def self.evt_value; :value; end
|
Instance Method Details
#child(*child_path) ⇒ Object
40
41
42
43
|
# File 'lib/bigbertha/ref.rb', line 40
def child( *child_path )
child_path = (child_path.is_a?(Array) ? child_path.join('/') : child_path )
Bigbertha::Ref.new( "#{uri.to_s}/#{child_path}", @auth_token )
end
|
#child?(child_path) ⇒ Boolean
45
46
47
48
49
50
|
# File 'lib/bigbertha/ref.rb', line 45
def child?( child_path )
child( child_path ).read
true
rescue
false
end
|
#children? ⇒ Boolean
52
53
54
55
|
# File 'lib/bigbertha/ref.rb', line 52
def children?
data = read
data.is_a? Map and !data.empty?
end
|
#name ⇒ Object
21
22
23
|
# File 'lib/bigbertha/ref.rb', line 21
def name
parse_path[-1]
end
|
#num_children ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/bigbertha/ref.rb', line 57
def num_children
data = read
if data.is_a? Map and !data.empty?
data.count
else
0
end
end
|
#parent ⇒ Object
34
35
36
37
38
|
# File 'lib/bigbertha/ref.rb', line 34
def parent
return nil if root?
path = parse_path[0..-2].join( "/" )
Bigbertha::Ref.new( root.uri.merge(path).to_s, @auth_token )
end
|
#root ⇒ Object
25
26
27
28
|
# File 'lib/bigbertha/ref.rb', line 25
def root
return self if root?
Bigbertha::Ref.new( @uri.scheme + '://' + @uri.host, @auth_token )
end
|
#root? ⇒ Boolean
30
31
32
|
# File 'lib/bigbertha/ref.rb', line 30
def root?
@uri.path.empty? or @uri.path == "/"
end
|
#to_s ⇒ Object
66
67
68
|
# File 'lib/bigbertha/ref.rb', line 66
def to_s
@url
end
|