Class: XMLable::Handlers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlable/handlers/base.rb

Overview

Base contains base handlers logic

Direct Known Subclasses

Attribute, Document, Element

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}, &block) ⇒ Base

Returns a new instance of Base.

Parameters:

  • name (String, Symbol)

    element/attribute name

  • opts (Hash) (defaults to: {})

    adtional handler options

Options Hash (opts):

  • :tag (Object)

    element/attribute tag name

  • :type (Object)

    element/attribute class object

  • :container (Object)

    elements container



20
21
22
23
24
# File 'lib/xmlable/handlers/base.rb', line 20

def initialize(name, opts = {}, &block)
  @name = name.to_s
  @type = opts.delete(:type) || String
  @block = block
end

Instance Attribute Details

#block#call (readonly)

Returns block with additional settings

Returns:

  • (#call)

    returns block with additional settings



11
12
13
# File 'lib/xmlable/handlers/base.rb', line 11

def block
  @block
end

#typeObject (readonly)

Returns:

  • (Object)


8
9
10
# File 'lib/xmlable/handlers/base.rb', line 8

def type
  @type
end

Class Method Details

.build(*args, &block) ⇒ XMLable::Handlers::Base

Factory to build a handler



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/xmlable/handlers/base.rb', line 90

def self.build(*args, &block)
  name = args.shift.to_s
  opts = args.last.is_a?(Hash) ? args.pop : {}
  opts[:type] = args.shift if args.size > 0
  opts[:container] = args.shift if args.size > 0

  # standalone
  opts[:tag] = opts[:type].__tag if opts[:type].respond_to?(:__tag)

  new(name, opts, &block)
end

Instance Method Details

#block_settings?Boolean

Does the handler have additional settings?

Returns:

  • (Boolean)


81
82
83
# File 'lib/xmlable/handlers/base.rb', line 81

def block_settings?
  @block != nil
end

#inject_wraped(klass) ⇒ Class

Inject type class with addtional logic

Parameters:

  • klass (Class)

Returns:

  • (Class)


52
53
# File 'lib/xmlable/handlers/base.rb', line 52

def inject_wraped(klass)
end

#method_nameString

Handler’s element method name

Returns:

  • (String)


72
73
74
# File 'lib/xmlable/handlers/base.rb', line 72

def method_name
  @name
end

#optionsObject



63
64
65
# File 'lib/xmlable/handlers/base.rb', line 63

def options
  proxy.__options
end

#options?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/xmlable/handlers/base.rb', line 59

def options?
  !options.nil?
end

#proxy#new

Proxy object which holds element data

Returns:

  • (#new)

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/xmlable/handlers/base.rb', line 41

def proxy
  raise NotImplementedError
end

#type_class#new

Type class for the handler element

Returns:

  • (#new)

    returns class to store elements and attributes



31
32
33
34
# File 'lib/xmlable/handlers/base.rb', line 31

def type_class
  klass = Builder.proxy_for(@type)
  wrapped_type? ? inject_wraped(klass) : klass
end

#wrapped_type?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/xmlable/handlers/base.rb', line 55

def wrapped_type?
  Builder.wrapped_type?(type)
end