Class: ActiveStash::Index
- Inherits:
-
Object
- Object
- ActiveStash::Index
- Defined in:
- lib/active_stash/index.rb
Constant Summary collapse
- INDEX_TYPES_WITH_UNIQUE_SUPPORT =
These index types support uniqueness. Note that when using :auto indexing with :unique, only the generated :exact index will have the uniqueness validation.
[:exact, :range]
- FIELD_TYPE_TO_SUPPORTED_INDEX_TYPES =
{ :timestamp => [:range], :date => [:range], :datetime => [:range], :float => [:range], :decimal => [:range], :integer => [:range], :string => [:range, :exact, :match], :text => [:range, :exact, :match], :boolean => [:range], :uuid => [:range], }
- RANGE_OPS =
[:lt, :lte, :gt, :gte, :eq, :between]
- EXACT_OPS =
[:eq]
- MATCH_OPS =
[:match]
- INDEX_TYPE_TO_OPS =
{ :exact => EXACT_OPS, :range => RANGE_OPS, :match => MATCH_OPS }
- OPS_HASH =
{ lt: "<", lte: "<=", gt: ">", gte: ">=", eq: "==", match: "=~", between: "between" }
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unique ⇒ Object
Returns the value of attribute unique.
-
#valid_ops ⇒ Object
Returns the value of attribute valid_ops.
Class Method Summary collapse
- .applicable_index_types(type) ⇒ Object
- .dynamic_match(field, **opts) ⇒ Object
- .exact(field, **opts) ⇒ Object
- .match(field, **opts) ⇒ Object
- .match_multi(fields, **opts) ⇒ Object
- .range(field, **opts) ⇒ Object
- .valid_index_type_for_field_type?(index_type, field_type) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(field, type, **opts) ⇒ Index
constructor
A new instance of Index.
- #make_unique! ⇒ Object
- #valid_op?(op) ⇒ Boolean
Constructor Details
#initialize(field, type, **opts) ⇒ Index
Returns a new instance of Index.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/active_stash/index.rb', line 47 def initialize(field, type, **opts) @field = field @type = type @options = opts @name = @options[:name] || @field.to_s @options.delete(:name) @valid_ops = INDEX_TYPE_TO_OPS[type] @unique = @options[:unique] || false @options.delete(:unique) end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/active_stash/index.rb', line 4 def field @field end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/active_stash/index.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/active_stash/index.rb', line 3 def @options end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/active_stash/index.rb', line 3 def type @type end |
#unique ⇒ Object
Returns the value of attribute unique.
3 4 5 |
# File 'lib/active_stash/index.rb', line 3 def unique @unique end |
#valid_ops ⇒ Object
Returns the value of attribute valid_ops.
3 4 5 |
# File 'lib/active_stash/index.rb', line 3 def valid_ops @valid_ops end |
Class Method Details
.applicable_index_types(type) ⇒ Object
62 63 64 |
# File 'lib/active_stash/index.rb', line 62 def self.applicable_index_types(type) FIELD_TYPE_TO_SUPPORTED_INDEX_TYPES[type] || [] end |
.dynamic_match(field, **opts) ⇒ Object
86 87 88 |
# File 'lib/active_stash/index.rb', line 86 def self.dynamic_match(field, **opts) new(field, :match, name: "#{field}_dynamic_match", **opts) end |
.exact(field, **opts) ⇒ Object
70 71 72 |
# File 'lib/active_stash/index.rb', line 70 def self.exact(field, **opts) new(field, :exact, **opts) end |
.match(field, **opts) ⇒ Object
74 75 76 |
# File 'lib/active_stash/index.rb', line 74 def self.match(field, **opts) new(field, :match, name: "#{field}_match", **opts) end |
.match_multi(fields, **opts) ⇒ Object
78 79 80 |
# File 'lib/active_stash/index.rb', line 78 def self.match_multi(fields, **opts) new(fields, :match, name: "__match_multi", **opts) end |
.range(field, **opts) ⇒ Object
82 83 84 |
# File 'lib/active_stash/index.rb', line 82 def self.range(field, **opts) new(field, :range, name: "#{field}_range", **opts) end |
.valid_index_type_for_field_type?(index_type, field_type) ⇒ Boolean
58 59 60 |
# File 'lib/active_stash/index.rb', line 58 def self.valid_index_type_for_field_type?(index_type, field_type) applicable_index_types(field_type).include?(index_type) end |
Instance Method Details
#make_unique! ⇒ Object
66 67 68 |
# File 'lib/active_stash/index.rb', line 66 def make_unique! @unique = true end |
#valid_op?(op) ⇒ Boolean
90 91 92 |
# File 'lib/active_stash/index.rb', line 90 def valid_op?(op) @valid_ops.include?(op) end |