Class: Crudboy::TemplateContext

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/crudboy/template_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#batch_insert_values_list, #column_names_list, #insert_values_list, #lombok

Constructor Details

#initialize(definition) ⇒ TemplateContext

Returns a new instance of TemplateContext.



8
9
10
11
12
13
# File 'lib/crudboy/template_context.rb', line 8

def initialize(definition)
  @model = definition.model
  @model_name = definition.model_name
  @table_name = definition.table_name
  @columns = @model.columns
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, **options, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/crudboy/template_context.rb', line 27

def method_missing(method, *args, **options, &block)
  if args.empty? && options.empty? && block.nil? && bundle_options.table.keys.include?(method)
    bundle_options.send(method)
  else
    super
  end
end

Instance Attribute Details

#bundle_optionsObject

Returns the value of attribute bundle_options.



6
7
8
# File 'lib/crudboy/template_context.rb', line 6

def bundle_options
  @bundle_options
end

#columns(**options) ⇒ Object

Returns the value of attribute columns.



6
7
8
# File 'lib/crudboy/template_context.rb', line 6

def columns
  @columns
end

#modelObject

Returns the value of attribute model.



6
7
8
# File 'lib/crudboy/template_context.rb', line 6

def model
  @model
end

#model_nameObject

Returns the value of attribute model_name.



6
7
8
# File 'lib/crudboy/template_context.rb', line 6

def model_name
  @model_name
end

#table_nameObject

Returns the value of attribute table_name.



6
7
8
# File 'lib/crudboy/template_context.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#bindingObject



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

def binding
  Kernel::binding
end

#eval(string) ⇒ Object



15
16
17
# File 'lib/crudboy/template_context.rb', line 15

def eval(string)
  instance_eval(format('%%Q{%s}', string), string, 0)
end