Class: Ricordami::Relationship
- Inherits:
-
Object
- Object
- Ricordami::Relationship
- Defined in:
- lib/ricordami/relationship.rb
Constant Summary collapse
- SUPPORTED_TYPES =
[:references_many, :references_one, :referenced_in]
- MANDATORY_ARGS =
[:other, :self]
Instance Attribute Summary collapse
-
#alias ⇒ Object
readonly
Returns the value of attribute alias.
-
#dependent ⇒ Object
readonly
Returns the value of attribute dependent.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#object_kind ⇒ Object
readonly
Returns the value of attribute object_kind.
-
#self_kind ⇒ Object
readonly
Returns the value of attribute self_kind.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, options = {}) ⇒ Relationship
constructor
A new instance of Relationship.
- #object_class ⇒ Object
- #referrer_id ⇒ Object
Constructor Details
#initialize(type, options = {}) ⇒ Relationship
Returns a new instance of Relationship.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ricordami/relationship.rb', line 8 def initialize(type, = {}) .assert_valid_keys(:other, :as, :self, :alias, :dependent) raise TypeNotSupported.new(type.to_s) unless SUPPORTED_TYPES.include?(type) missing = find_missing_args() raise MissingMandatoryArgs.new(missing.map(&:to_s).join(", ")) unless missing.empty? if [:dependent] && ![:delete, :nullify].include?([:dependent]) raise OptionValueInvalid.new([:dependent].to_s) end @name = [:as] || [:other] @type = type @object_kind = [:other].to_s.singularize.to_sym @self_kind = [:self].to_s.singularize.to_sym @alias = [:alias] || [:self] @dependent = [:dependent] end |
Instance Attribute Details
#alias ⇒ Object (readonly)
Returns the value of attribute alias.
6 7 8 |
# File 'lib/ricordami/relationship.rb', line 6 def alias @alias end |
#dependent ⇒ Object (readonly)
Returns the value of attribute dependent.
6 7 8 |
# File 'lib/ricordami/relationship.rb', line 6 def dependent @dependent end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/ricordami/relationship.rb', line 6 def name @name end |
#object_kind ⇒ Object (readonly)
Returns the value of attribute object_kind.
6 7 8 |
# File 'lib/ricordami/relationship.rb', line 6 def object_kind @object_kind end |
#self_kind ⇒ Object (readonly)
Returns the value of attribute self_kind.
6 7 8 |
# File 'lib/ricordami/relationship.rb', line 6 def self_kind @self_kind end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/ricordami/relationship.rb', line 6 def type @type end |
Instance Method Details
#object_class ⇒ Object
24 25 26 |
# File 'lib/ricordami/relationship.rb', line 24 def object_class @object_kind.to_s.camelize.constantize end |
#referrer_id ⇒ Object
28 29 30 31 32 |
# File 'lib/ricordami/relationship.rb', line 28 def referrer_id return @referrer_id unless @referrer_id.nil? referrer = type == :referenced_in ? @name.to_s : @alias.to_s.singularize @referrer_id = referrer.foreign_key end |