Class: Handcart::SettingConstraint

Inherits:
Object
  • Object
show all
Defined in:
app/models/handcart/setting_constraint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, feature) ⇒ SettingConstraint

Returns a new instance of SettingConstraint.



6
7
8
9
# File 'app/models/handcart/setting_constraint.rb', line 6

def initialize(matcher, feature)
  @matcher = matcher
  @feature = feature
end

Instance Attribute Details

#featureObject

Returns the value of attribute feature.



4
5
6
# File 'app/models/handcart/setting_constraint.rb', line 4

def feature
  @feature
end

#matcherObject

Returns the value of attribute matcher.



4
5
6
# File 'app/models/handcart/setting_constraint.rb', line 4

def matcher
  @matcher
end

Instance Method Details

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/handcart/setting_constraint.rb', line 11

def matches?(request)
  # Given this request, find out if the thing which `acts_as_handcart` can call `matcher` looking for `feature`.
  my_subdomain = Subdomain.find_by_name(request.subdomain)
  if my_subdomain && request.subdomain.present? && my_subdomain.handcart
    if my_subdomain.handcart.respond_to?(@matcher)
      my_subdomain.handcart.send(@matcher.to_s, @feature)
    else
      # The handcart doesn't respond to the matcher, so no point checking
      false
    end
  end

end