Class: Models::Base
- Inherits:
-
Object
- Object
- Models::Base
- Defined in:
- lib/bob/models/base.rb
Direct Known Subclasses
CompanyField, CompanyList, Employee, EmploymentHistory, EquityGrant, LifecycleHistory, OnboardingWizard, Payroll, Salary, Table, TimeOff, Training, VariablePayment, WorkHistory
Instance Method Summary collapse
- #dig_custom_field(field) ⇒ Object
-
#initialize(raw) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(raw) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/bob/models/base.rb', line 5 def initialize(raw) attributes = Bob::Util.underscorize_hash(raw) attributes.each do |k, v| k = "field_#{k}" if k.instance_of?(String) && k.to_i.positive? instance_variable_set("@#{k}", v.is_a?(Hash) ? Models::Base.new(v) : v) self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") }) self.class.send(:define_method, "#{k}=", proc { |val| instance_variable_set("@#{k}", val) }) rescue NameError next end end |
Instance Method Details
#dig_custom_field(field) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/bob/models/base.rb', line 18 def dig_custom_field(field) Bob.custom_fields[field][:dig_path].reduce(self) { |response, sub_field| response.send(sub_field) } rescue NoMethodError => e Rails.logger.info("Error: #{e.}") nil end |