Class: RDFMapper::Associations::Base
- Inherits:
-
Object
- Object
- RDFMapper::Associations::Base
- Includes:
- Logger
- Defined in:
- lib/lib/associations/base.rb
Overview
Base class for all association types. Contains default constructor.
Instance Method Summary collapse
-
#initialize(instance, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#inspect ⇒ String
Developer-friendly representation of the instance.
-
#object(force = false) ⇒ Object
[-].
-
#replace(value) ⇒ Object
Association should override this method.
-
#to_statements(options = {}) ⇒ Object
[-].
Methods included from Logger
Constructor Details
#initialize(instance, options = {}) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 |
# File 'lib/lib/associations/base.rb', line 16 def initialize(instance, = {}) @instance = instance @association = [:cls] @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object (private)
- -
85 86 87 88 89 90 91 |
# File 'lib/lib/associations/base.rb', line 85 def method_missing(symbol, *args, &block) if value.respond_to? symbol value.send(symbol, *args, &block) else raise RuntimeError, 'Undefined method `%s`' % symbol end end |
Instance Method Details
#inspect ⇒ String
Developer-friendly representation of the instance
68 69 70 |
# File 'lib/lib/associations/base.rb', line 68 def inspect #nodoc value.inspect end |
#object(force = false) ⇒ Object
- -
32 33 34 35 |
# File 'lib/lib/associations/base.rb', line 32 def object(force = false) value.nil? and value.empty? if force self end |
#replace(value) ⇒ Object
Association should override this method
25 26 27 |
# File 'lib/lib/associations/base.rb', line 25 def replace(value) raise NotImplementedError, 'Expected association to override `replace`' end |
#to_statements(options = {}) ⇒ Object
- -
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lib/associations/base.rb', line 40 def to_statements( = {}) [:skip] ||= [] if value.kind_of? Array items = value else items = [value] end items.reject do |item| [:skip].include?(items) end.map do |item| node = if [:full] item.to_statements(:skip => @instance) else item.to_statements(:short => true) end node + [{ :subject => @instance.id, :predicate => @options[:type], :object => item.id }] end.flatten end |