module EasyGoesIt
Constants
- VERSION
Private Class Methods
date_range_between(range, attributes)
click to toggle source
For searching by date range on multiple attributes at once (i.e. attribute OR attribute) First argument is date range and second argument is the array of attributes to be searched
# File lib/easy_goes_it.rb, line 36 def self.date_range_between(range, attributes) return if range.blank? || attributes.blank? set = self.where(attributes.first => range) attributes.each do |attribute| next if attribute == attributes.first set = set.or(self.where(attribute => range)) end return set end
generate_date_ranges(objects, attribute, increment)
click to toggle source
# File lib/easy_goes_it.rb, line 13 def self.generate_date_ranges(objects, attribute, increment) return [] if objects.empty? || attribute.blank? || increment.blank? lower_bound = objects.minimum(attribute).strftime("%Y-%m-1").to_date upper_bound = objects.maximum(attribute).strftime("%Y-%m-1").to_date date = lower_bound date_ranges = [] index = 0 while date <= upper_bound next_month = date + 1.send(increment.to_sym) date_ranges[index] = date..next_month index = index + 1 date = next_month end return date_ranges end
in_development?()
click to toggle source
in_production?()
click to toggle source
# File lib/easy_goes_it.rb, line 84 def self.in_production? Rails.env.production? end
Private Instance Methods
downcase_attributes(*args)
click to toggle source
# File lib/easy_goes_it.rb, line 66 def downcase_attributes(*args) args.each do |arg| next if arg.blank? || self.send(arg.to_sym).blank? self.assign_attributes(arg.to_sym => self.send(arg.to_sym).downcase) end end
dynamic_name()
click to toggle source
¶ ↑
Formatters =================================================================
¶ ↑
Motivation.new(name: 'Hello World').dynamic_name => 'Hello World'
# File lib/easy_goes_it.rb, line 52 def dynamic_name # Motivation.new.dynamic_name => 'New Motivation' class_name = self.class.table_name.to_sym attributes = [:banner, :display_name, :head, :heading, :headline, :label, :title, :name] attribute = attributes.find {|attribute| ActiveRecord::Base.connection.column_exists?(class_name, attribute) } ActiveRecord::Base.connection.close if ActiveRecord::Base.connection if self.send(attribute).present? self.send(attribute) else self.new_record? ? "New #{self.class.name.underscore.humanize}" : self.send(attribute) end end
in_development?()
click to toggle source
# File lib/easy_goes_it.rb, line 80 def in_development? Rails.env.development? end
in_production?()
click to toggle source
# File lib/easy_goes_it.rb, line 88 def in_production? Rails.env.production? end