Module: Materialist::Materializer::Internals::DSL

Defined in:
lib/materialist/materializer/internals/dsl.rb

Instance Method Summary collapse

Instance Method Details

#after_destroy(*method_array) ⇒ Object



63
64
65
# File 'lib/materialist/materializer/internals/dsl.rb', line 63

def after_destroy(*method_array)
  __materialist_options[:after_destroy] = method_array
end

#after_upsert(*method_array) ⇒ Object



59
60
61
# File 'lib/materialist/materializer/internals/dsl.rb', line 59

def after_upsert(*method_array)
  __materialist_options[:after_upsert] = method_array
end

#before_destroy(*method_array) ⇒ Object



67
68
69
# File 'lib/materialist/materializer/internals/dsl.rb', line 67

def before_destroy(*method_array)
  __materialist_options[:before_destroy] = method_array
end

#before_upsert(*method_array) ⇒ Object



55
56
57
# File 'lib/materialist/materializer/internals/dsl.rb', line 55

def before_upsert(*method_array)
  __materialist_options[:before_upsert] = method_array
end

#before_upsert_with_payload(*method_array) ⇒ Object

This method is meant to be used for cases when the application needs to have access to the ‘payload` that is returned on the HTTP call. Such an example would be if the application logic requires all relationships to be present before the `resource` is saved in the database. Introduced in github.com/deliveroo/materialist/pull/47



51
52
53
# File 'lib/materialist/materializer/internals/dsl.rb', line 51

def before_upsert_with_payload(*method_array)
  __materialist_options[:before_upsert_with_payload] = method_array
end

#capture(key, as: key, &value_parser_block) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/materialist/materializer/internals/dsl.rb', line 9

def capture(key, as: key, &value_parser_block)
  __materialist_dsl_mapping_stack.last << FieldMapping.new(
    key: key,
    as: as,
    value_parser: value_parser_block
  )
end


17
18
19
20
21
22
23
# File 'lib/materialist/materializer/internals/dsl.rb', line 17

def capture_link_href(key, as:, &url_parser_block)
  __materialist_dsl_mapping_stack.last << LinkHrefMapping.new(
    key: key,
    as: as,
    url_parser: url_parser_block
  )
end


25
26
27
28
29
30
31
# File 'lib/materialist/materializer/internals/dsl.rb', line 25

def link(key, enable_caching: false)
  link_mapping = LinkMapping.new(key: key, enable_caching: enable_caching)
  __materialist_dsl_mapping_stack.last << link_mapping
  __materialist_dsl_mapping_stack << link_mapping.mapping
  yield
  __materialist_dsl_mapping_stack.pop
end


5
6
7
# File 'lib/materialist/materializer/internals/dsl.rb', line 5

def materialize_link(key, topic: key)
  __materialist_options[:links_to_materialize][key] = { topic: topic }
end

#persist_to(klass) ⇒ Object



33
34
35
# File 'lib/materialist/materializer/internals/dsl.rb', line 33

def persist_to(klass)
  __materialist_options[:model_class] = klass
end

#sidekiq_options(options) ⇒ Object



37
38
39
# File 'lib/materialist/materializer/internals/dsl.rb', line 37

def sidekiq_options(options)
  __materialist_options[:sidekiq_options] = options
end

#source_key(key, &source_key_parser) ⇒ Object



41
42
43
44
# File 'lib/materialist/materializer/internals/dsl.rb', line 41

def source_key(key, &source_key_parser)
  __materialist_options[:source_key] = key
  __materialist_options[:source_key_parser] = source_key_parser
end