Module: FieldTest

Defined in:
lib/field_test/calculations.rb,
lib/field_test.rb,
lib/field_test/engine.rb,
lib/field_test/mailer.rb,
lib/field_test/helpers.rb,
lib/field_test/version.rb,
lib/field_test/controller.rb,
lib/field_test/experiment.rb,
lib/field_test/participant.rb,
app/models/field_test/event.rb,
app/models/field_test/membership.rb,
app/helpers/field_test/base_helper.rb,
app/controllers/field_test/base_controller.rb,
lib/generators/field_test/events_generator.rb,
lib/generators/field_test/install_generator.rb,
app/controllers/field_test/experiments_controller.rb,
app/controllers/field_test/memberships_controller.rb,
app/controllers/field_test/participants_controller.rb

Overview

Defined Under Namespace

Modules: BaseHelper, Calculations, Controller, Generators, Helpers, Mailer Classes: BaseController, Engine, Error, Event, Experiment, ExperimentNotFound, ExperimentsController, Membership, MembershipsController, Participant, ParticipantsController, UnknownParticipant

Constant Summary collapse

UUID_NAMESPACE =

same as ahoy

"a82ae811-5011-45ab-a728-569df7499c5f"
VERSION =
"0.4.1"

Class Method Summary collapse

Class Method Details

.cacheObject



41
42
43
# File 'lib/field_test.rb', line 41

def self.cache
  config["cache"]
end

.configObject



29
30
31
# File 'lib/field_test.rb', line 29

def self.config
  @config ||= YAML.load(ERB.new(File.read(config_path)).result)
end

.config_pathObject



24
25
26
27
# File 'lib/field_test.rb', line 24

def self.config_path
  path = defined?(Rails) ? Rails.root : File
  path.join("config", "field_test.yml")
end

.cookiesObject



45
46
47
# File 'lib/field_test.rb', line 45

def self.cookies
  config.key?("cookies") ? config["cookies"] : true
end

.events_supported?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/field_test.rb', line 57

def self.events_supported?
  unless defined?(@events_supported)
    connection = FieldTest::Membership.connection
    table_name = "field_test_events"
    @events_supported =
      if connection.respond_to?(:data_source_exists?)
        connection.data_source_exists?(table_name)
      else
        connection.table_exists?(table_name)
      end
  end
  @events_supported
end

.exclude_bots?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/field_test.rb', line 37

def self.exclude_bots?
  config["exclude"] && config["exclude"]["bots"]
end

.excluded_ipsObject



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

def self.excluded_ips
  @excluded_ips ||= Array(config["exclude"] && config["exclude"]["ips"]).map { |ip| IPAddr.new(ip) }
end

.legacy_participantsObject



49
50
51
# File 'lib/field_test.rb', line 49

def self.legacy_participants
  config["legacy_participants"]
end

.mask_ip(ip) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/field_test.rb', line 71

def self.mask_ip(ip)
  addr = IPAddr.new(ip)
  if addr.ipv4?
    # set last octet to 0
    addr.mask(24).to_s
  else
    # set last 80 bits to zeros
    addr.mask(48).to_s
  end
end

.precisionObject



53
54
55
# File 'lib/field_test.rb', line 53

def self.precision
  config["precision"] || 0
end