Method: Chawk.node

Defined in:
lib/chawk.rb

.node(agent, key, access = :full) ⇒ Chawk::Node

The primary method for retrieving an Node. If a key does not exist, it will be created and the current agent will be set as an admin for it.

Parameters:

  • agent (Chawk::Agent)

    the agent whose permission will be used for this request

  • key (String)

    the string address this node can be found in the database.

Returns:

  • (Chawk::Node)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/chawk.rb', line 61

def self.node(agent,key,access=:full)

  unless key =~ /^[\w\:\$\!\@\*\[\]\~\(\)]+$/
    raise ArgumentError, "Key can only contain [A-Za-z0-9_:$!@*[]~()] (#{key})"
  end

  unless agent.is_a?(Chawk::Models::Agent) 
    raise ArgumentError, 'Agent must be a Chawk::Models::Agent instance'
  end

  unless key.is_a?(String)
    raise ArgumentError, 'key must be a string.'
  end

  node = find_or_create_node(agent,key,access)

  unless node
    raise ArgumentError,"No node was returned."
  end

  node.agent = agent
  return node
end