Module: ActsAsSourceable::InstanceMethods
- Defined in:
- lib/acts_as_sourceable/acts_as_sourceable.rb
Instance Method Summary collapse
- #acts_like_sourceable? ⇒ Boolean
-
#add_sources(*sources) ⇒ Object
(also: #add_source)
Add the given holding_institutions, collections, and items.
-
#remove_sources(*sources) ⇒ Object
(also: #remove_source)
Remove the given holding_institutions, collections, and items.
- #sourced? ⇒ Boolean
- #unsourced? ⇒ Boolean
- #unused? ⇒ Boolean
- #usages ⇒ Object
- #used? ⇒ Boolean
Instance Method Details
#acts_like_sourceable? ⇒ Boolean
81 82 83 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 81 def acts_like_sourceable? true end |
#add_sources(*sources) ⇒ Object Also known as: add_source
Add the given holding_institutions, collections, and items
110 111 112 113 114 115 116 117 118 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 110 def add_sources(*sources) raise "Cannot set sources of a #{self.class.name}. They are sourced through #{[:through]}" if [: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
122 123 124 125 126 127 128 129 130 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 122 def remove_sources(*sources) raise "Cannot set sources of a #{self.class.name}. They are sourced through #{[:through]}" if [: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
85 86 87 88 89 90 91 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 85 def sourced? if [:cache_column] self[[: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
93 94 95 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 93 def unsourced? !sourced? end |
#unused? ⇒ Boolean
101 102 103 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 101 def unused? !used? end |
#usages ⇒ Object
105 106 107 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 105 def usages Hash[[:used_by].collect{|association| [association, send(association)] }] end |
#used? ⇒ Boolean
97 98 99 |
# File 'lib/acts_as_sourceable/acts_as_sourceable.rb', line 97 def used? [:used_by].any?{|association| send(association).present? } end |