Class: Ripple::Association
- Inherits:
-
Object
- Object
- Ripple::Association
- Includes:
- Translation
- Defined in:
- ripple/lib/ripple/associations.rb
Overview
The “reflection” for an association - metadata about how it is configured.
Instance Attribute Summary (collapse)
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) options
readonly
Returns the value of attribute options.
-
- (Object) type
readonly
Returns the value of attribute type.
Instance Method Summary (collapse)
-
- (Object) class_name
String The class name of the associated object(s).
-
- (true, false) embeddable?
Is the associated class an EmbeddedDocument.
-
- (Association) initialize(type, name, options = {})
constructor
association options :using, :class_name, :class, :extend, options that may be added :validate.
-
- (String) ivar
The instance variable in the owner where the association will be stored.
-
- (Class) klass
The class of the associated object(s).
-
- (Proc) link_filter
A filter proc to be used with Enumerable#select for collecting links that belong to this association (only when #linked? is true).
-
- (Riak::WalkSpec) link_spec
When #linked? is true, a specification for which links to follow to retrieve the associated documents.
-
- (String?) link_tag
When #linked? is true, the tag for outgoing links.
-
- (true, false) linked?
Does the association use links.
-
- (true, false) many?
Is the cardinality of the association > 1.
-
- (true, false) one?
Is the cardinality of the association == 1.
-
- (true, false) polymorphic?
TODO: Polymorphic not supported.
-
- (Class) proxy_class
The association proxy class.
-
- (String) proxy_class_name
The class name of the association proxy.
-
- (Symbol) using
Which method is used for representing the association - currently only supports :embedded and :linked.
- - (Object) verify_type!(value, owner)
Methods included from Translation
Methods included from Riak::Util::Translation
Constructor Details
- (Association) initialize(type, name, options = {})
association options :using, :class_name, :class, :extend, options that may be added :validate
152 153 154 |
# File 'ripple/lib/ripple/associations.rb', line 152 def initialize(type, name, ={}) @type, @name, @options = type, name, . end |
Instance Attribute Details
- (Object) name (readonly)
Returns the value of attribute name
147 148 149 |
# File 'ripple/lib/ripple/associations.rb', line 147 def name @name end |
- (Object) options (readonly)
Returns the value of attribute options
147 148 149 |
# File 'ripple/lib/ripple/associations.rb', line 147 def @options end |
- (Object) type (readonly)
Returns the value of attribute type
147 148 149 |
# File 'ripple/lib/ripple/associations.rb', line 147 def type @type end |
Instance Method Details
- (Object) class_name
String The class name of the associated object(s)
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'ripple/lib/ripple/associations.rb', line 157 def class_name @class_name ||= case when @options[:class_name] @options[:class_name] when @options[:class] @options[:class].to_s when many? @name.to_s.classify else @name.to_s.camelize end end |
- (true, false) embeddable?
Is the associated class an EmbeddedDocument
186 187 188 |
# File 'ripple/lib/ripple/associations.rb', line 186 def klass. end |
- (String) ivar
The instance variable in the owner where the association will be stored
202 203 204 |
# File 'ripple/lib/ripple/associations.rb', line 202 def ivar "@_#{name}" end |
- (Class) klass
The class of the associated object(s)
171 172 173 |
# File 'ripple/lib/ripple/associations.rb', line 171 def klass @klass ||= [:class] || class_name.constantize end |
- (Proc) link_filter
A filter proc to be used with Enumerable#select for collecting links that belong to this association (only when #linked? is true)
218 219 220 |
# File 'ripple/lib/ripple/associations.rb', line 218 def link_filter linked? ? lambda {|link| link.tag == link_tag } : lambda {|_| false } end |
- (Riak::WalkSpec) link_spec
When #linked? is true, a specification for which links to follow to retrieve the associated documents
228 229 230 231 232 233 234 235 236 237 |
# File 'ripple/lib/ripple/associations.rb', line 228 def link_spec # TODO: support transitive linked associations if linked? tag = name.to_s bucket = polymorphic? ? '_' : klass.bucket_name Riak::WalkSpec.new(:tag => tag, :bucket => bucket) else nil end end |
- (String?) link_tag
When #linked? is true, the tag for outgoing links
223 224 225 |
# File 'ripple/lib/ripple/associations.rb', line 223 def link_tag linked? ? Array(link_spec).first.tag : nil end |
- (true, false) linked?
Does the association use links
197 198 199 |
# File 'ripple/lib/ripple/associations.rb', line 197 def linked? using == :linked end |
- (true, false) many?
Is the cardinality of the association > 1
176 177 178 |
# File 'ripple/lib/ripple/associations.rb', line 176 def many? @type == :many end |
- (true, false) one?
Is the cardinality of the association == 1
181 182 183 |
# File 'ripple/lib/ripple/associations.rb', line 181 def one? @type == :one end |
- (true, false) polymorphic?
TODO: Polymorphic not supported
192 193 194 |
# File 'ripple/lib/ripple/associations.rb', line 192 def polymorphic? false end |
- (Class) proxy_class
The association proxy class
207 208 209 |
# File 'ripple/lib/ripple/associations.rb', line 207 def proxy_class @proxy_class ||= proxy_class_name.constantize end |
- (String) proxy_class_name
The class name of the association proxy
212 213 214 215 |
# File 'ripple/lib/ripple/associations.rb', line 212 def proxy_class_name klass_name = (many? ? 'Many' : 'One') + using.to_s.camelize + ('Polymorphic' if polymorphic?).to_s + 'Proxy' "Ripple::Associations::#{klass_name}" end |
- (Symbol) using
Which method is used for representing the association - currently only supports :embedded and :linked
240 241 242 |
# File 'ripple/lib/ripple/associations.rb', line 240 def using @using ||= [:using] || ( ? :embedded : :linked) end |
- (Object) verify_type!(value, owner)
245 246 247 248 249 250 251 252 253 |
# File 'ripple/lib/ripple/associations.rb', line 245 def verify_type!(value, owner) unless type_matches?(value) raise ArgumentError.new(t('invalid_association_value', :name => name, :owner => owner.inspect, :klass => polymorphic? ? "<polymorphic>" : klass.name, :value => value.inspect)) end end |