Module: ActsAsSourceable::InstanceMethods

Defined in:
lib/acts_as_sourceable/acts_as_sourceable.rb

Instance Method Summary collapse

Instance Method Details

#acts_like_sourceable?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 80

def acts_like_sourceable?
  true
end

#add_sources(*sources) ⇒ Object Also known as: add_source

Add the given holding_institutions, collections, and items



97
98
99
100
101
102
103
104
105
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 97

def add_sources(*sources)
  raise "Cannot set sources of a #{self.class.name}. They are sourced through #{acts_as_sourceable_options[:through]}" if acts_as_sourceable_options[:through]

  sources = Array(sources).flatten
  sources.each do |source|
    source_scope(source).first_or_create!
  end
  update_sourceable_cache_column(true) if sources.present?
end

#remove_sources(*sources) ⇒ Object Also known as: remove_source

Remove the given holding_institutions, collections, and items



109
110
111
112
113
114
115
116
117
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 109

def remove_sources(*sources)
  raise "Cannot set sources of a #{self.class.name}. They are sourced through #{acts_as_sourceable_options[:through]}" if acts_as_sourceable_options[:through]

  sources = Array(sources).flatten
  sources.each do |source|
    source_scope(source).delete_all
  end
  update_sourceable_cache_column(false) if self.sourceable_registry_entries.empty?
end

#sourced?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 84

def sourced?
  if acts_as_sourceable_options[:cache_column]
    self[acts_as_sourceable_options[:cache_column]]
  else
    self.class.sourced.uniq(false).exists?(self) # Remove the uniqness check because it allows for better use of the indexes
  end
end

#unsourced?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 92

def unsourced?
  !sourced?
end