class Dbee::KeyPath
This class represents a relative path from a model to a column. For example: Say we have a model called “users” which is represented by a “users” table. The “users” table also has a one-to-many relationship with a “phone_numbers” table, which is modeled as a nested model under “users” as “phone_numbers”. Then, to get the column: “area_code”, you would use: “phone_numbers.area_code”. Say the column “name” is located on “users”, you could use the key path: “name”. This also works for deeper nested columns in the same fashion.
Constants
- SPLIT_CHAR
Attributes
ancestor_names[R]
column_name[R]
value[R]
Public Class Methods
get(obj)
click to toggle source
# File lib/dbee/key_path.rb, line 22 def get(obj) obj.is_a?(self.class) ? obj : new(obj) end
new(value)
click to toggle source
# File lib/dbee/key_path.rb, line 33 def initialize(value) raise 'Value is required' if value.to_s.empty? @value = value.to_s @ancestor_names = value.to_s.split(SPLIT_CHAR) @column_name = @ancestor_names.pop freeze end
Public Instance Methods
==(other)
click to toggle source
# File lib/dbee/key_path.rb, line 47 def ==(other) other.to_s == to_s end
Also aliased as: eql?
ancestor_paths()
click to toggle source
# File lib/dbee/key_path.rb, line 52 def ancestor_paths ancestor_names.each_with_object([]) do |ancestor, memo| memo << [memo.last, ancestor].compact.join(SPLIT_CHAR) end end
hash()
click to toggle source
# File lib/dbee/key_path.rb, line 43 def hash value.hash end