Module: Conflow::Redis::Model::ClassMethods Private
- Defined in:
- lib/conflow/redis/model.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Methods for defining fields on model
Constant Summary collapse
- ALLOWED_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps types (option for #field) to specific type field
{ hash: Conflow::Redis::HashField, array: Conflow::Redis::ArrayField, value: Conflow::Redis::ValueField, sorted_set: Conflow::Redis::SortedSetField, set: Conflow::Redis::SetField, raw_value: Conflow::Redis::RawValueField }.freeze
Instance Method Summary collapse
-
#field(name, type) ⇒ Object
private
Defines Redis field accessors.
-
#fields ⇒ Array<Symbol>
private
Fields defined on this class.
-
#has_many(name, klass, field_name: "#{name.to_s.chop}_ids") ⇒ Object
private
Convienience method for defining relation-like accessor.
-
#inherited(subclass) ⇒ Object
private
Copies field and relations information.
-
#relations ⇒ Array<Symbol>
private
Relations defined on this class.
Instance Method Details
#field(name, type) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines Redis field accessors.
77 78 79 80 81 82 83 |
# File 'lib/conflow/redis/model.rb', line 77 def field(name, type) type_class = ALLOWED_TYPES[type] raise ArgumentError, "Unknown type: #{type}. Should be one of: #{ALLOWED_TYPES.keys.inspect}" unless type_class fields << name FieldBuilder.new(name, type_class).call(self) end |
#fields ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns fields defined on this class.
95 96 97 |
# File 'lib/conflow/redis/model.rb', line 95 def fields @fields ||= [] end |
#has_many(name, klass, field_name: "#{name.to_s.chop}_ids") ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convienience method for defining relation-like accessor.
88 89 90 91 92 |
# File 'lib/conflow/redis/model.rb', line 88 def has_many(name, klass, field_name: "#{name.to_s.chop}_ids") field(field_name, :array) relations << name define_method(name) { send(field_name).map { |id| klass.new(id) } } end |
#inherited(subclass) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copies field and relations information
57 58 59 60 |
# File 'lib/conflow/redis/model.rb', line 57 def inherited(subclass) subclass.instance_variable_set("@fields", fields.dup) subclass.instance_variable_set("@relations", relations.dup) end |
#relations ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns relations defined on this class.
100 101 102 |
# File 'lib/conflow/redis/model.rb', line 100 def relations @relations ||= [] end |