Class: Bigbertha::Ref

Inherits:
Object
  • 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

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/bigbertha/ref.rb', line 7

def uri
  @uri
end

#urlObject (readonly)

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_addedObject



10
# File 'lib/bigbertha/ref.rb', line 10

def self.evt_child_added;   :add_child; end

.evt_child_changedObject



11
# File 'lib/bigbertha/ref.rb', line 11

def self.evt_child_changed; :mod_child; end

.evt_child_movedObject



13
# File 'lib/bigbertha/ref.rb', line 13

def self.evt_child_moved;   :mv_child;  end

.evt_child_removedObject



12
# File 'lib/bigbertha/ref.rb', line 12

def self.evt_child_removed; :rm_child;  end

.evt_valueObject



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

Returns:

  • (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

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/bigbertha/ref.rb', line 52

def children?
  data = read
  data.is_a? Map and !data.empty?
end

#nameObject



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

def name
  parse_path[-1]
end

#num_childrenObject



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

#parentObject



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

#rootObject



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

Returns:

  • (Boolean)


30
31
32
# File 'lib/bigbertha/ref.rb', line 30

def root?
  @uri.path.empty? or @uri.path == "/"
end

#to_sObject



66
67
68
# File 'lib/bigbertha/ref.rb', line 66

def to_s
  @url
end