Class: PaidUp::Feature
- Inherits:
-
Object
- Object
- PaidUp::Feature
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Model
- Defined in:
- lib/paid_up/feature.rb
Overview
Feature Class: Not an ActiveRecord object.
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#setting_type ⇒ Object
Returns the value of attribute setting_type.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .all ⇒ Object
- .find(**conditions) ⇒ Object
- .find_all(**conditions) ⇒ Object
- .find_by_slug(slug) ⇒ Object
-
.method_missing(method_sym, *arguments, &block) ⇒ Object
Define on self, since it’s a class method.
- .raw ⇒ Object
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Instance Method Summary collapse
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
19 20 21 |
# File 'lib/paid_up/feature.rb', line 19 def description @description end |
#setting_type ⇒ Object
Returns the value of attribute setting_type.
19 20 21 |
# File 'lib/paid_up/feature.rb', line 19 def setting_type @setting_type end |
#slug ⇒ Object
Returns the value of attribute slug.
19 20 21 |
# File 'lib/paid_up/feature.rb', line 19 def slug @slug end |
#title ⇒ Object
Returns the value of attribute title.
19 20 21 |
# File 'lib/paid_up/feature.rb', line 19 def title @title end |
Class Method Details
.all ⇒ Object
63 64 65 |
# File 'lib/paid_up/feature.rb', line 63 def self.all raw.values end |
.find(**conditions) ⇒ Object
79 80 81 |
# File 'lib/paid_up/feature.rb', line 79 def self.find(**conditions) find_all(conditions).first end |
.find_all(**conditions) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/paid_up/feature.rb', line 67 def self.find_all(**conditions) collection = [] all.each do |feature| qualifies = true conditions.each do |key, value| feature.send(key) != value && (qualifies = false) end qualifies && collection << feature end collection end |
.find_by_slug(slug) ⇒ Object
59 60 61 |
# File 'lib/paid_up/feature.rb', line 59 def self.find_by_slug(slug) raw[slug.to_sym] end |
.method_missing(method_sym, *arguments, &block) ⇒ Object
Define on self, since it’s a class method
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/paid_up/feature.rb', line 84 def self.method_missing(method_sym, *arguments, &block) # the first argument is a Symbol, so you need to_s it if you want to # pattern match if method_sym.to_s =~ /^find_by_(.*)$/ find(Regexp.last_match[1].to_sym => arguments.first) elsif method_sym.to_s =~ /^find_all_by_(.*)$/ find_all(Regexp.last_match[1].to_sym => arguments.first) else super end end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
96 97 98 |
# File 'lib/paid_up/feature.rb', line 96 def self.respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?('find_') || super end |
Instance Method Details
#feature_model ⇒ Object
55 56 57 |
# File 'lib/paid_up/feature.rb', line 55 def feature_model feature_model_name.constantize end |
#feature_model_name ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/paid_up/feature.rb', line 47 def feature_model_name acceptable_setting_types = %w( table_rows rolify_rows ) unless acceptable_setting_types.include? setting_type raise :no_implicit_conversion_of_type_features.l(type: setting_type) end slug.classify end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/paid_up/feature.rb', line 43 def to_s slug end |