Class: Props::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/props_template.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = nil, options = {}) ⇒ Template

Returns a new instance of Template.



33
34
35
36
# File 'lib/props_template.rb', line 33

def initialize(context = nil, options = {})
  @builder = BaseWithExtensions.new(self, context, options)
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject (private)



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

def set!(key, options = {}, &block)
  if block && (options[:search] || options[:dig]) && !@builder.is_a?(Searcher)
    search = options[:search] || options[:dig]

    prev_builder = @builder
    @builder = Searcher.new(self, search, @context)

    options.delete(:search)
    options.delete(:dig)

    @builder.set!(key, options, &block)
    found_block, found_options = @builder.found!
    @builder = prev_builder

    if found_block
      set!(key, found_options, &found_block)
    end
  else
    @builder.set!(key, options, &block)
  end
end

Class Attribute Details

.template_lookup_optionsObject

Returns the value of attribute template_lookup_options.



19
20
21
# File 'lib/props_template.rb', line 19

def template_lookup_options
  @template_lookup_options
end

Instance Method Details

#builder!Object



60
61
62
# File 'lib/props_template.rb', line 60

def builder!
  @builder
end

#set!(key, options = {}, &block) ⇒ Object Also known as: method_missing



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/props_template.rb', line 38

def set!(key, options = {}, &block)
  if block && (options[:search] || options[:dig]) && !@builder.is_a?(Searcher)
    search = options[:search] || options[:dig]

    prev_builder = @builder
    @builder = Searcher.new(self, search, @context)

    options.delete(:search)
    options.delete(:dig)

    @builder.set!(key, options, &block)
    found_block, found_options = @builder.found!
    @builder = prev_builder

    if found_block
      set!(key, found_options, &found_block)
    end
  else
    @builder.set!(key, options, &block)
  end
end