Class: PaidUp::Feature
- Inherits:
-
Object
- Object
- PaidUp::Feature
- Extended by:
- ActiveSupport::Concern
- 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
- .find_by_slug!(slug) ⇒ Object
- .method_missing(method_sym, *arguments, &block) ⇒ Object
- .raw ⇒ Object
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Instance Method Summary collapse
- #feature_model ⇒ Object
- #feature_model_name ⇒ Object
- #for_graphql(setting) ⇒ Object
- #setting_human(setting) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
22 23 24 |
# File 'lib/paid_up/feature.rb', line 22 def description @description end |
#setting_type ⇒ Object
Returns the value of attribute setting_type.
22 23 24 |
# File 'lib/paid_up/feature.rb', line 22 def setting_type @setting_type end |
#slug ⇒ Object
Returns the value of attribute slug.
22 23 24 |
# File 'lib/paid_up/feature.rb', line 22 def slug @slug end |
#title ⇒ Object
Returns the value of attribute title.
22 23 24 |
# File 'lib/paid_up/feature.rb', line 22 def title @title end |
Class Method Details
.all ⇒ Object
55 56 57 |
# File 'lib/paid_up/feature.rb', line 55 def all raw.values end |
.find(**conditions) ⇒ Object
71 72 73 |
# File 'lib/paid_up/feature.rb', line 71 def find(**conditions) find_all(conditions).first end |
.find_all(**conditions) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/paid_up/feature.rb', line 59 def 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
47 48 49 |
# File 'lib/paid_up/feature.rb', line 47 def find_by_slug(slug) raw[slug.to_sym] end |
.find_by_slug!(slug) ⇒ Object
51 52 53 |
# File 'lib/paid_up/feature.rb', line 51 def find_by_slug!(slug) find_by_slug(slug) || raise(:feature_not_found.l) end |
.method_missing(method_sym, *arguments, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/paid_up/feature.rb', line 75 def method_missing(method_sym, *arguments, &block) 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
85 86 87 |
# File 'lib/paid_up/feature.rb', line 85 def respond_to_missing?(method_name, include_private = false) method_name.to_s.start_with?('find_') || super end |
Instance Method Details
#feature_model ⇒ Object
102 103 104 |
# File 'lib/paid_up/feature.rb', line 102 def feature_model feature_model_name.constantize end |
#feature_model_name ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/paid_up/feature.rb', line 94 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 |
#for_graphql(setting) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/paid_up/feature.rb', line 106 def for_graphql(setting) OpenStruct.new( id: slug, title: title, slug: slug, description: description, setting: setting, setting_human: setting_human(setting) ) end |
#setting_human(setting) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/paid_up/feature.rb', line 117 def setting_human(setting) if setting == PaidUp::Unlimited.to_i PaidUp::Unlimited.to_s elsif setting_type == 'boolean' setting ? :allowed.l : :not_allowed.l else setting.to_s end end |
#to_s ⇒ Object
90 91 92 |
# File 'lib/paid_up/feature.rb', line 90 def to_s slug end |