Class: Firm
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Firm
- Defined in:
- app/models/firm.rb
Constant Summary collapse
- FREE_INITIAL_MEETING_VALID_VALUES =
[true, false].freeze
- REGISTERED_MARKER_FIELD =
We use a scalar required field as a marker to detect a record saved with validation
:free_initial_meeting- REGISTERED_MARKER_FIELD_VALID_VALUES =
FREE_INITIAL_MEETING_VALID_VALUES- ADVICE_TYPES_ATTRIBUTES =
[ :retirement_income_products_flag, :pension_transfer_flag, :long_term_care_flag, :equity_release_flag, :inheritance_tax_and_estate_planning_flag, :wills_and_probate_flag ]
Instance Attribute Summary collapse
-
#percent_total ⇒ Object
Returns the value of attribute percent_total.
-
#primary_advice_method ⇒ Object
Returns the value of attribute primary_advice_method.
Instance Method Summary collapse
-
#__set_registered(state) ⇒ Object
(also: #__registered=)
A helper to shield tests from modifying the marker field directly.
- #advice_types ⇒ Object
- #field_order ⇒ Object
- #in_person_advice? ⇒ Boolean (also: #postcode_searchable?)
- #main_office ⇒ Object
- #missing_advisers? ⇒ Boolean
- #notify_indexer ⇒ Object
- #publishable? ⇒ Boolean
-
#registered? ⇒ Boolean
A heuristic that allows us to infer validity.
- #trading_name? ⇒ Boolean (also: #subsidiary?)
Instance Attribute Details
#percent_total ⇒ Object
Returns the value of attribute percent_total.
38 39 40 |
# File 'app/models/firm.rb', line 38 def percent_total @percent_total end |
#primary_advice_method ⇒ Object
Returns the value of attribute primary_advice_method.
39 40 41 |
# File 'app/models/firm.rb', line 39 def primary_advice_method @primary_advice_method end |
Instance Method Details
#__set_registered(state) ⇒ Object Also known as: __registered=
A helper to shield tests from modifying the marker field directly
121 122 123 124 |
# File 'app/models/firm.rb', line 121 def __set_registered(state) new_value = (state) ? REGISTERED_MARKER_FIELD_VALID_VALUES.first : nil send("#{REGISTERED_MARKER_FIELD}=", new_value) end |
#advice_types ⇒ Object
167 168 169 |
# File 'app/models/firm.rb', line 167 def advice_types ADVICE_TYPES_ATTRIBUTES.map { |a| [a, self[a]] }.to_h end |
#field_order ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/models/firm.rb', line 141 def field_order [ :website_address, :address_line_one, :address_line_two, :address_town, :address_county, :address_postcode, :primary_advice_method, :in_person_advice_methods, :other_advice_methods, :free_initial_meeting, :initial_meeting_duration, :initial_advice_fee_structures, :ongoing_advice_fee_structures, :allowed_payment_methods, :minimum_fixed_fee, :percent_total, *ADVICE_TYPES_ATTRIBUTES, :ethical_investing_flag, :sharia_investing_flag, :languages, :investment_sizes ] end |
#in_person_advice? ⇒ Boolean Also known as: postcode_searchable?
130 131 132 |
# File 'app/models/firm.rb', line 130 def in_person_advice? in_person_advice_methods.present? end |
#main_office ⇒ Object
176 177 178 |
# File 'app/models/firm.rb', line 176 def main_office offices.first end |
#missing_advisers? ⇒ Boolean
184 185 186 |
# File 'app/models/firm.rb', line 184 def missing_advisers? (primary_advice_method == :local) && advisers.empty? end |
#notify_indexer ⇒ Object
106 107 108 |
# File 'app/models/firm.rb', line 106 def notify_indexer FirmIndexer.handle_firm_changed(self) end |
#publishable? ⇒ Boolean
180 181 182 |
# File 'app/models/firm.rb', line 180 def publishable? registered? && offices.any? && !missing_advisers? end |
#registered? ⇒ Boolean
A heuristic that allows us to infer validity
This method is basically a cheap way to answer the question: has this record ever been saved with validation enabled?
114 115 116 117 |
# File 'app/models/firm.rb', line 114 def registered? # false is a valid value so we cannot use `.present?` !(send(REGISTERED_MARKER_FIELD).nil?) end |
#trading_name? ⇒ Boolean Also known as: subsidiary?
135 136 137 |
# File 'app/models/firm.rb', line 135 def trading_name? parent.present? end |