Class: Adobe::Aem::Jcr::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/adobe/aem/jcr/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, path, context) ⇒ Node

Returns a new instance of Node.



5
6
7
8
9
# File 'lib/adobe/aem/jcr/node.rb', line 5

def initialize(hash = {}, path, context)
  @context = context
  @path = path
  @data = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/adobe/aem/jcr/node.rb', line 39

def method_missing(name, *args, &block)
  # If we're trying to set content of a node that doesn't exist
  # we should throw exception
  #
  # /bin/wcmcommand
  # cmd:createPage
  # parentPath:/etc/replication/agents.author
  # title:Test
  # label:Test
  # template:/libs/cq/replication/templates/agent

  setter = name =~ /=$/

  if name.to_s =~ /^\[\]/
    name = args.delete_at(0)
  end

  if setter
    return set(name, *args)
  end

  unless @data[name.to_s].is_a?(Hash)
    return @data[name.to_s]
  end

  if name.to_s =~ /=$/

  else
    @context.connector.get("#{@path}/#{name}.1.json")
  end
end

Instance Method Details

#child_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/adobe/aem/jcr/node.rb', line 25

def child_exists?(name)
  @data.has_key?(name)
end

#childrenObject



11
12
13
14
15
# File 'lib/adobe/aem/jcr/node.rb', line 11

def children
  @data.select do |key, value|
    value.is_a? Hash
  end
end

#create_child(title, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/adobe/aem/jcr/node.rb', line 29

def create_child(title, options = {})
  options = {
      title: title,
      label: title,
      template: ''
  }.merge(options)

  @connector.create_page(@path, options[:title], options[:label], options[:template])
end

#jcr_contentObject



17
18
19
# File 'lib/adobe/aem/jcr/node.rb', line 17

def jcr_content
  self.send('jcr:content')
end

#jcr_content=(value) ⇒ Object



21
22
23
# File 'lib/adobe/aem/jcr/node.rb', line 21

def jcr_content=(value)
  self.send('jcr:content=', value)
end

#lengthObject Also known as: size



71
72
73
# File 'lib/adobe/aem/jcr/node.rb', line 71

def length
  children.length
end