Sha256: 720f281d222744fbce527c9ea3c9e5e01648484ccaaf856d58f9f4cd601684bf
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
module WithFilters module Filter # @private class Base attr_reader :to_partial_path, :label, :label_attrs, :field_name, :value, :attrs, :collection def initialize(name, namespace, value, options = {}) @value = value @theme = options.delete(:theme) @label = options.delete(:label) || name.to_s.titleize @label_attrs = options.delete(:label_attrs) || {} @field_name = options[:field_name] || "#{namespace}[#{name}]" @collection = options[:collection] ? Collection.new(@field_name, options.delete(:collection) || [], {selected: value}) : nil @attrs = options @to_partial_path = create_partial_path end private def create_partial_path partial_path = self.class.name.underscore if @theme themed_partial_path = partial_path.split(File::SEPARATOR).insert(1, @theme) if Dir.glob(File.join(Rails.root, 'app', 'views', *themed_partial_path).sub(/([^#{File::SEPARATOR}]+?)$/, '_\1.*')).any? partial_path = themed_partial_path.join(File::SEPARATOR) end end partial_path end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
with_filters-0.1.2 | lib/with_filters/models/filter/base.rb |
with_filters-0.1.1 | lib/with_filters/models/filter/base.rb |
with_filters-0.1.0 | lib/with_filters/models/filter/base.rb |