Class: Feature

Inherits:
Struct
  • Object
show all
Defined in:
app/models/feature.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#matching_valuesObject

Returns the value of attribute matching_values

Returns:

  • (Object)

    the current value of matching_values



1
2
3
# File 'app/models/feature.rb', line 1

def matching_values
  @matching_values
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



1
2
3
# File 'app/models/feature.rb', line 1

def name
  @name
end

Class Method Details

.allObject



3
4
5
6
7
# File 'app/models/feature.rb', line 3

def all
  Featurer.feature_list.map do |feature_details|
    Feature.new(feature_details[:name], feature_details[:matching_values])
  end
end

.by_name(name) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/models/feature.rb', line 9

def by_name(name)
  found_feature_hash = Featurer.feature_list.find do |feature_hash|
    !name.empty? && feature_hash[:name] == name.to_sym
  end

  raise "Unknown feature: '#{name}'" unless found_feature_hash

  Feature.new(found_feature_hash[:name], found_feature_hash[:matching_values])
end

.update(name, matching_values_string) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/feature.rb', line 19

def update(name, matching_values_string)
  massaged_values = matching_values_string.split("\r\n").map do |matching_value|
    regexp_match = Regexp.new(%r{^\/(.*)\/$}).match(matching_value)

    if regexp_match
      Regexp.new(regexp_match[1])
    else
      matching_value
    end
  end

  Featurer.register(name, massaged_values)
end