Sha256: b7ebf99e4311404c255452415e7f278cea392b33779531fdf39e14a5d513fa76

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

module LazyModel
	
	class LazyBoolean

		include LazyModelSupport

		def define_methods
			define_instance_methods
			define_class_methods
		end

		private

		def define_instance_methods
			if belongs_to
				model.class_eval <<-LZY
					def #{attribute}?
						#{belongs_to_attribute}?
					end

					def #{attribute}
						#{belongs_to_attribute}
					end

				LZY
			end
		end

		def define_class_methods
			model.class_eval <<-LZY
				class << self
	
					def #{attribute}
						#{joins}where(#{klass}.arel_table[:#{attribute}].eq(true))
					end

					def not_#{attribute}
						#{joins}where(#{klass}.arel_table[:#{attribute}].eq(false))
					end

					def nil_#{attribute}
						#{joins}where(#{klass}.arel_table[:#{attribute}].eq(nil))
					end

				end
			LZY
		end


	end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lazy_model-0.1.0 lib/lazy_model/lazy_boolean.rb
lazy_model-0.0.13 lib/lazy_model/lazy_boolean.rb
lazy_model-0.0.12 lib/lazy_model/lazy_boolean.rb