Sha256: de6975e5cc9f7955c7429fb9fb1e1c426aa07ced12222f8692cc1dd0e40eac8f
Contents?: true
Size: 1.92 KB
Versions: 20
Compression:
Stored size: 1.92 KB
Contents
module Adparlor module Facebook module GraphApi module Fields module FieldDecorator GLOBAL_FIELDS = [:account_id, :conn, :files, :message, :source] def self.included(base) base.extend(ClassMethods) end module ClassMethods def fields(*args) if args.first == :all @fields.map(&:to_s).join(',') else invalid_fields = args.map(&:to_s) - @fields.map(&:to_s) invalid_fields_error(invalid_fields) if invalid_fields.any? (@fields & args).map(&:to_s).join(',') end end def validate_initialize_fields(*args) create_fields = self.const_defined?('CREATE_FIELDS') ? const_get('CREATE_FIELDS') : [] invalid_fields = args.map(&:to_s) - ((@fields || []) + GLOBAL_FIELDS + create_fields).map(&:to_s) invalid_fields_error(invalid_fields) if invalid_fields.any? end def validate_post_fields(*args, method) valid_fields = self.const_defined?('CREATE_FIELDS') ? const_get('CREATE_FIELDS') : [] if method == 'CREATE' valid_fields = self.const_defined?('UPDATE_FIELDS') ? const_get('UPDATE_FIELDS') : [] if method == 'UPDATE' || method == 'DELETE' invalid_fields = args.map(&:to_s) - (@fields + GLOBAL_FIELDS + valid_fields).map(&:to_s) invalid_fields_error(invalid_fields) if invalid_fields.any? end def field_attrs(fields) @fields = fields @fields.each { |field| attr_accessor field } end private def invalid_fields_error(invalid_fields) raise Adparlor::Facebook::Error.new("Invalid field#{invalid_fields.length > 1 ? 's' : ''} #{invalid_fields.join(', ')} passed", 500) end end end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems