Module: Perron::Resource::Sourceable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Perron::Resource
- Defined in:
- lib/perron/resource/sourceable.rb
Constant Summary collapse
- MODES =
{ single: ->(dataset) { dataset.zip }, combinations: ->(dataset) { dataset.to_a.combination(2).to_a } }
Instance Method Summary collapse
- #source ⇒ Object (also: #sources)
- #source_backed? ⇒ Boolean
- #source_template(source) ⇒ Object
Instance Method Details
#source ⇒ Object Also known as: sources
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/perron/resource/sourceable.rb', line 148 def source @source ||= begin data = self.class.source_definitions.each_with_object({}) do |(name, ), hash| primary_key = [:primary_key] singular_name = name.to_s.singularize identifier = frontmatter["#{singular_name}_#{primary_key}"] dataset = self.class.send(:resolve, name) hash[name] = dataset.find { it.public_send(primary_key).to_s == identifier.to_s } end Source.new(data) end end |
#source_backed? ⇒ Boolean
146 |
# File 'lib/perron/resource/sourceable.rb', line 146 def source_backed? = self.class.source_backed? |
#source_template(source) ⇒ Object
164 165 166 |
# File 'lib/perron/resource/sourceable.rb', line 164 def source_template(source) raise NotImplementedError, "#{self.class.name} must implement #source_template" end |