Module: Faceted::Collector
- Includes:
- Model
- Defined in:
- lib/faceted/collector.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Object
Instance methods =========================================================.
- #to_hash ⇒ Object
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/faceted/collector.rb', line 7 def self.included(base) base.extend ActiveModel::Naming base.send(:attr_accessor, :errors) base.send(:attr_accessor, :success) base.send(:attr_accessor, :fields) base.extend ClassMethods base.extend Faceted::Model::ModelClassMethods end |
Instance Method Details
#initialize(args = {}) ⇒ Object
Instance methods =========================================================
48 49 50 51 52 53 54 |
# File 'lib/faceted/collector.rb', line 48 def initialize(args={}) ! args.empty? && args.symbolize_keys.delete_if{|k,v| v.nil?}.each do |k,v| self.send("#{k}=", v) if self.respond_to?("#{k}=") && ! v.blank? end self.errors = [] self.success = true end |
#to_hash ⇒ Object
56 57 58 |
# File 'lib/faceted/collector.rb', line 56 def to_hash self.class.fields.inject({}){ |h,f| h[f] = self.send(f).map{|o| o.to_hash}; h } end |