Module: Magick::DSL

Defined in:
lib/magick/dsl.rb

Instance Method Summary collapse

Instance Method Details

#add_dependency(feature_name, dependency_name) ⇒ Object



61
62
63
# File 'lib/magick/dsl.rb', line 61

def add_dependency(feature_name, dependency_name)
  Magick[feature_name].add_dependency(dependency_name)
end

#boolean_feature(name, default: false, **options) ⇒ Object



10
11
12
# File 'lib/magick/dsl.rb', line 10

def boolean_feature(name, default: false, **options)
  Magick.register_feature(name, type: :boolean, default_value: default, **options)
end

#disable_feature(feature_name, user_id: nil) ⇒ Object



70
71
72
# File 'lib/magick/dsl.rb', line 70

def disable_feature(feature_name, user_id: nil)
  Magick[feature_name].disable(user_id: user_id)
end

#disabled_for?(feature_name, object, **additional_context) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/magick/dsl.rb', line 79

def disabled_for?(feature_name, object, **additional_context)
  Magick.disabled_for?(feature_name, object, **additional_context)
end

#enable_feature(feature_name, user_id: nil) ⇒ Object

Enable/disable features globally



66
67
68
# File 'lib/magick/dsl.rb', line 66

def enable_feature(feature_name, user_id: nil)
  Magick[feature_name].enable(user_id: user_id)
end

#enable_for_custom_attribute(feature_name, attribute_name, values, operator: :equals) ⇒ Object



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

def enable_for_custom_attribute(feature_name, attribute_name, values, operator: :equals)
  Magick[feature_name].enable_for_custom_attribute(attribute_name, values, operator: operator)
end

#enable_for_date_range(feature_name, start_date, end_date) ⇒ Object



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

def enable_for_date_range(feature_name, start_date, end_date)
  Magick[feature_name].enable_for_date_range(start_date, end_date)
end

#enable_for_group(feature_name, group_name) ⇒ Object



27
28
29
# File 'lib/magick/dsl.rb', line 27

def enable_for_group(feature_name, group_name)
  Magick[feature_name].enable_for_group(group_name)
end

#enable_for_ip_addresses(feature_name, *ip_addresses) ⇒ Object



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

def enable_for_ip_addresses(feature_name, *ip_addresses)
  Magick[feature_name].enable_for_ip_addresses(ip_addresses)
end

#enable_for_role(feature_name, role_name) ⇒ Object



31
32
33
# File 'lib/magick/dsl.rb', line 31

def enable_for_role(feature_name, role_name)
  Magick[feature_name].enable_for_role(role_name)
end

#enable_for_user(feature_name, user_id) ⇒ Object

Targeting DSL methods



23
24
25
# File 'lib/magick/dsl.rb', line 23

def enable_for_user(feature_name, user_id)
  Magick[feature_name].enable_for_user(user_id)
end

#enable_percentage(feature_name, percentage, type: :users) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/magick/dsl.rb', line 35

def enable_percentage(feature_name, percentage, type: :users)
  feature = Magick[feature_name]
  case type
  when :users
    feature.enable_percentage_of_users(percentage)
  when :requests
    feature.enable_percentage_of_requests(percentage)
  end
end

#enabled_for?(feature_name, object, **additional_context) ⇒ Boolean

Check enablement for an object

Returns:

  • (Boolean)


75
76
77
# File 'lib/magick/dsl.rb', line 75

def enabled_for?(feature_name, object, **additional_context)
  Magick.enabled_for?(feature_name, object, **additional_context)
end

#feature(name, **options) ⇒ Object

Feature definition DSL methods



6
7
8
# File 'lib/magick/dsl.rb', line 6

def feature(name, **options)
  Magick.register_feature(name, **options)
end

#number_feature(name, default: 0, **options) ⇒ Object



18
19
20
# File 'lib/magick/dsl.rb', line 18

def number_feature(name, default: 0, **options)
  Magick.register_feature(name, type: :number, default_value: default, **options)
end

#set_variants(feature_name, variants) ⇒ Object



57
58
59
# File 'lib/magick/dsl.rb', line 57

def set_variants(feature_name, variants)
  Magick[feature_name].set_variants(variants)
end

#string_feature(name, default: '', **options) ⇒ Object



14
15
16
# File 'lib/magick/dsl.rb', line 14

def string_feature(name, default: '', **options)
  Magick.register_feature(name, type: :string, default_value: default, **options)
end