Class: Libhoney::Builder
- Inherits:
-
Object
- Object
- Libhoney::Builder
- Defined in:
- lib/libhoney/builder.rb
Instance Attribute Summary collapse
-
#api_host ⇒ Object
Returns the value of attribute api_host.
-
#dataset ⇒ Object
Returns the value of attribute dataset.
-
#dyn_fields ⇒ Object
Returns the value of attribute dyn_fields.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#writekey ⇒ Object
Returns the value of attribute writekey.
Instance Method Summary collapse
-
#add(data) ⇒ self
adds a group of field->values to the events created from this builder.
-
#add_dynamic_field(name, proc) ⇒ self
adds a single field->dynamic value function, which is invoked to supply values when events are created from this builder.
-
#add_field(name, val) ⇒ self
adds a single field->value mapping to the events created from this builder.
-
#builder(fields = {}, dyn_fields = {}) ⇒ Builder
creates and returns a clone of this builder, merged with fields and dyn_fields passed as arguments.
-
#event ⇒ Event
creates and returns a new Event containing all fields/dyn_fields from this builder, that can be further fleshed out and sent on its own.
-
#initialize(libhoney, parent_builder, fields = {}, dyn_fields = {}) ⇒ Builder
constructor
private
A new instance of Builder.
- #send_now(data = {}) ⇒ self deprecated Deprecated.
Constructor Details
#initialize(libhoney, parent_builder, fields = {}, dyn_fields = {}) ⇒ Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Builder.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/libhoney/builder.rb', line 10 def initialize(libhoney, parent_builder, fields = {}, dyn_fields = {}) @libhoney = libhoney @fields = {} @dyn_fields = {} unless parent_builder.nil? @writekey = parent_builder.writekey @dataset = parent_builder.dataset @sample_rate = parent_builder.sample_rate @api_host = parent_builder.api_host @fields.merge!(parent_builder.fields) @dyn_fields.merge!(parent_builder.dyn_fields) end @fields.merge!(fields) @dyn_fields.merge!(dyn_fields) end |
Instance Attribute Details
#api_host ⇒ Object
Returns the value of attribute api_host.
5 6 7 |
# File 'lib/libhoney/builder.rb', line 5 def api_host @api_host end |
#dataset ⇒ Object
Returns the value of attribute dataset.
5 6 7 |
# File 'lib/libhoney/builder.rb', line 5 def dataset @dataset end |
#dyn_fields ⇒ Object
Returns the value of attribute dyn_fields.
5 6 7 |
# File 'lib/libhoney/builder.rb', line 5 def dyn_fields @dyn_fields end |
#fields ⇒ Object
Returns the value of attribute fields.
5 6 7 |
# File 'lib/libhoney/builder.rb', line 5 def fields @fields end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
5 6 7 |
# File 'lib/libhoney/builder.rb', line 5 def sample_rate @sample_rate end |
#writekey ⇒ Object
Returns the value of attribute writekey.
5 6 7 |
# File 'lib/libhoney/builder.rb', line 5 def writekey @writekey end |
Instance Method Details
#add(data) ⇒ self
adds a group of field->values to the events created from this builder.
41 42 43 44 |
# File 'lib/libhoney/builder.rb', line 41 def add(data) @fields.merge!(data) self end |
#add_dynamic_field(name, proc) ⇒ self
adds a single field->dynamic value function, which is invoked to supply values when events are created from this builder.
65 66 67 |
# File 'lib/libhoney/builder.rb', line 65 def add_dynamic_field(name, proc) @dyn_fields[name] = proc end |
#add_field(name, val) ⇒ self
adds a single field->value mapping to the events created from this builder.
53 54 55 56 |
# File 'lib/libhoney/builder.rb', line 53 def add_field(name, val) @fields[name] = val self end |
#builder(fields = {}, dyn_fields = {}) ⇒ Builder
creates and returns a clone of this builder, merged with fields and dyn_fields passed as arguments.
115 116 117 |
# File 'lib/libhoney/builder.rb', line 115 def builder(fields = {}, dyn_fields = {}) Builder.new(@libhoney, self, fields, dyn_fields) end |
#event ⇒ Event
creates and returns a new Event containing all fields/dyn_fields from this builder, that can be further fleshed out and sent on its own.
101 102 103 |
# File 'lib/libhoney/builder.rb', line 101 def event Event.new(@libhoney, self, @fields, @dyn_fields) end |
#send_now(data = {}) ⇒ self
Creates and sends an event, including all global builder fields/dyn_fields, as well as anything in the optional data parameter.
Equivalent to:
ev = builder.event
ev.add(data)
ev.send
May be removed in a future major release
87 88 89 90 91 92 |
# File 'lib/libhoney/builder.rb', line 87 def send_now(data = {}) ev = event ev.add(data) ev.send self end |