github / github/scientist

Scientist::Experiment.new creates Scientist::Default instance even when it should have been overridden

Đang mở
#92 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Ruby
Star
7.8k
Fork
505
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi friends! Thank you for your great work with this gem :sparkles:

I am having a problem in Rails apps where Scientist::Experiment defaults to the original `Default` object until the custom one is called - leading to some head-scratching about why the `try` block is not running even when `enabled?` is set to `true`.

I'm unsure whether this is a problem with the Rails load order because of how I've arranged my files, whether the examples in the README could be a little better, or whether there's genuinely a bug here.

```
$ bundle exec rails console
Loading development environment (Rails 5.1.6)
irb(main):001:0> Scientist::Experiment.new "something"
=> #
irb(main):002:0> LdapExperiment.new(name: "something")
=> #
irb(main):003:0> Scientist::Experiment.new "something"
=> #
```

I've followed the instructions in the README, which are delightful and comprehensive.

```ruby
# app/experiments/ldap_experiment.rb
require "scientist/experiment"

class LdapExperiment
include Scientist::Experiment

attr_accessor :name

def initialize(name:)
@name = name
end

def enabled?
# ...
end

def publish(result)
# ...
end
end

module Scientist::Experiment
def self.new(name)
LdapExperiment.new(name: name)
end
end
```

```ruby
# app/models/whatever.rb
class Whatever
include Scientist
def do_something
science "role lookup" do |e|
e.use { do_one_thing }
e.try { do_some_other_thing }
end
end
end
```

This is occurring in Rails 3.2.x and Rails 5.1.x applications, with version 1.2.0 of the gem.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Tái hiện hành vi từ Rails console bằng cách sử dụng app/experiments/ldap_experiment.rb và các lệnh gọi Scientist::Experiment.new được hiển thị trong issue. Đọc scientist/experiment và các ví dụ README được tham chiếu để xác định liệu đây là hành vi do thứ tự tải, lỗi triển khai hay sự mơ hồ trong tài liệu; công việc được xem là hoàn tất khi hành vi override dự kiến được xác lập và được bao quát bằng một fix hoặc phần làm rõ phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rails, ruby
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.