Sha256: a72a5a6176704ef5964b11a55cb52f39b9e56411b45b3c95439e2502564f2c7c

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

module StatusManager
	module StatusGroupManager
		def status_group (status_attribute_name, group_status_set={})
			status_store = self.status_store_list.get(status_attribute_name.to_sym)
			raise "undefined #{status_attribute_name}" unless status_store
			
			group_status_set.each do |group_status_name, group_statuses|
				raise "#{status_attribute_name}-#{group_status_name} is not a group, group must have statuses" if group_statuses.size < 1
				status_store.add_group_status(group_status_name, group_statuses)

				# set scope
				scope "#{status_store.attribute_name}_#{group_status_name}", where("#{self.table_name}.#{status_store.attribute_name} in (?)", status_store.get_group_status(group_status_name).values)

				# status check method
				define_method "#{status_attribute_name}_#{group_status_name}?" do 
					status_store.get_group_status(group_status_name).values.include? self.send(status_attribute_name)
				end

				define_method "#{status_attribute_name}_was_#{group_status_name}?" do
					status_store.get_group_status(group_status_name).values.include? self.send("#{status_attribute_name}_was")
				end
			end
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
status-manager-0.8.5 lib/status-manager/status_group_manager.rb
status-manager-0.8.3 lib/status-manager/status_group_manager.rb
status-manager-0.8.1 lib/status-manager/status_group_manager.rb