Sha256: 8f841c148d9c1102f07c9b78f0a3de0a5e41355e28f26ed1a1f539ec29d0c312

Contents?: true

Size: 756 Bytes

Versions: 2

Compression:

Stored size: 756 Bytes

Contents

module LazyModelSupport
	extend ActiveSupport::Concern
	
	included do
		attr_accessor :raw_attribute, :enumerables, :custom_finders, :column, :model, :attribute, :belongs_to
	end
	
	def initialize(model, raw_attribute, enumerables = nil, custom_finders = {})
		self.model 			= model
		self.raw_attribute 	= raw_attribute
		self.enumerables 	= enumerables
		self.custom_finders = custom_finders
		calculate_atttribute_and_belongs_to
	end

	def to_method_name(any_string_or_symbol)
		any_string_or_symbol.to_s.underscore
	end

	private

	def calculate_atttribute_and_belongs_to
		if raw_attribute.is_a?(Hash)
			self.belongs_to = raw_attribute.keys.first
			self.attribute 	= raw_attribute[belongs_to]
		else
			self.attribute = raw_attribute
		end
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lazy_model-0.0.10 lib/lazy_model/lazy_model_support.rb
lazy_model-0.0.9 lib/lazy_model/lazy_model_support.rb