idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
4,300
def send_notification_email ( options = { } ) if target . notification_email_allowed? ( notifiable , key ) && notifiable . notification_email_allowed? ( target , key ) && email_subscribed? send_later = options . has_key? ( :send_later ) ? options [ :send_later ] : true send_later ? @@notification_mailer . send_notifica...
Sends notification email to the target .
4,301
def publish_to_optional_targets ( options = { } ) notifiable . optional_targets ( target . to_resources_name , key ) . map { | optional_target | optional_target_name = optional_target . to_optional_target_name if optional_target_subscribed? ( optional_target_name ) optional_target . notify ( self , options [ optional_t...
Publishes notification to the optional targets .
4,302
def open! ( options = { } ) opened? and return 0 opened_at = options [ :opened_at ] || Time . current with_members = options . has_key? ( :with_members ) ? options [ :with_members ] : true unopened_member_count = with_members ? group_members . unopened_only . count : 0 group_members . update_all ( opened_at : opened_at...
Opens the notification .
4,303
def group_notifier_count ( limit = ActivityNotification . config . opened_index_limit ) notification = group_member? && group_owner . present? ? group_owner : self notification . notifier . present? ? group_member_notifier_count ( limit ) + 1 : 0 end
Returns count of group member notifiers including group owner notifier . It always returns 0 if group owner notifier is blank . This method is designed to cache group by query result to avoid N + 1 call .
4,304
def remove_from_group new_group_owner = group_members . earliest if new_group_owner . present? new_group_owner . update ( group_owner_id : nil ) group_members . update_all ( group_owner_id : new_group_owner . id ) end new_group_owner end
Remove from notification group and make a new group owner .
4,305
def notifiable_path notifiable . present? or raise ActiveRecord :: RecordNotFound . new ( "Couldn't find notifiable #{notifiable_type}" ) notifiable . notifiable_path ( target_type , key ) end
Returns notifiable_path to move after opening notification with notifiable . notifiable_path .
4,306
def notifications_path_for ( target , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}notifications_path" , options ) : send ( "#{routing_scope(options)}#{target.to_resource_name}_notifications_path" , target , options ) end
Returns notifications_path for the target
4,307
def notification_path_for ( notification , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}notification_path" , notification , options ) : send ( "#{routing_scope(options)}#{notification.target.to_resource_name}_notification_path" , notification . tar...
Returns notification_path for the notification
4,308
def move_notification_path_for ( notification , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "move_#{routing_scope(options)}notification_path" , notification , options ) : send ( "move_#{routing_scope(options)}#{notification.target.to_resource_name}_notification_path" , not...
Returns move_notification_path for the target of specified notification
4,309
def open_notification_path_for ( notification , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "open_#{routing_scope(options)}notification_path" , notification , options ) : send ( "open_#{routing_scope(options)}#{notification.target.to_resource_name}_notification_path" , not...
Returns open_notification_path for the target of specified notification
4,310
def open_all_notifications_path_for ( target , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "open_all_#{routing_scope(options)}notifications_path" , options ) : send ( "open_all_#{routing_scope(options)}#{target.to_resource_name}_notifications_path" , target , options ) end
Returns open_all_notifications_path for the target
4,311
def notifications_url_for ( target , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}notifications_url" , options ) : send ( "#{routing_scope(options)}#{target.to_resource_name}_notifications_url" , target , options ) end
Returns notifications_url for the target
4,312
def notification_url_for ( notification , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}notification_url" , notification , options ) : send ( "#{routing_scope(options)}#{notification.target.to_resource_name}_notification_url" , notification . target...
Returns notification_url for the target of specified notification
4,313
def move_notification_url_for ( notification , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "move_#{routing_scope(options)}notification_url" , notification , options ) : send ( "move_#{routing_scope(options)}#{notification.target.to_resource_name}_notification_url" , notifi...
Returns move_notification_url for the target of specified notification
4,314
def open_notification_url_for ( notification , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "open_#{routing_scope(options)}notification_url" , notification , options ) : send ( "open_#{routing_scope(options)}#{notification.target.to_resource_name}_notification_url" , notifi...
Returns open_notification_url for the target of specified notification
4,315
def open_all_notifications_url_for ( target , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "open_all_#{routing_scope(options)}notifications_url" , options ) : send ( "open_all_#{routing_scope(options)}#{target.to_resource_name}_notifications_url" , target , options ) end
Returns open_all_notifications_url for the target of specified notification
4,316
def subscriptions_path_for ( target , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}subscriptions_path" , options ) : send ( "#{routing_scope(options)}#{target.to_resource_name}_subscriptions_path" , target , options ) end
Returns subscriptions_path for the target
4,317
def subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "#{routing_scope(options)}#{subscription.target.to_resource_name}_subscription_path" , subscription . tar...
Returns subscription_path for the subscription
4,318
def subscribe_subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "subscribe_#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "subscribe_#{routing_scope(options)}#{subscription.target.to_resource_name}_subscript...
Returns subscribe_subscription_path for the target of specified subscription
4,319
def unsubscribe_subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "unsubscribe_#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "unsubscribe_#{routing_scope(options)}#{subscription.target.to_resource_name}_sub...
Returns unsubscribe_subscription_path for the target of specified subscription
4,320
def subscribe_to_email_subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "subscribe_to_email_#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "subscribe_to_email_#{routing_scope(options)}#{subscription.target....
Returns subscribe_to_email_subscription_path for the target of specified subscription
4,321
def unsubscribe_to_email_subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "unsubscribe_to_email_#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "unsubscribe_to_email_#{routing_scope(options)}#{subscription.t...
Returns unsubscribe_to_email_subscription_path for the target of specified subscription
4,322
def subscribe_to_optional_target_subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "subscribe_to_optional_target_#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "subscribe_to_optional_target_#{routing_scope(o...
Returns subscribe_to_optional_target_subscription_path for the target of specified subscription
4,323
def unsubscribe_to_optional_target_subscription_path_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "unsubscribe_to_optional_target_#{routing_scope(options)}subscription_path" , subscription , options ) : send ( "unsubscribe_to_optional_target_#{routing_s...
Returns unsubscribe_to_optional_target_subscription_path for the target of specified subscription
4,324
def subscriptions_url_for ( target , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}subscriptions_url" , options ) : send ( "#{routing_scope(options)}#{target.to_resource_name}_subscriptions_url" , target , options ) end
Returns subscriptions_url for the target
4,325
def subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "#{routing_scope(options)}#{subscription.target.to_resource_name}_subscription_url" , subscription . target...
Returns subscription_url for the subscription
4,326
def subscribe_subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "subscribe_#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "subscribe_#{routing_scope(options)}#{subscription.target.to_resource_name}_subscriptio...
Returns subscribe_subscription_url for the target of specified subscription
4,327
def unsubscribe_subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "unsubscribe_#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "unsubscribe_#{routing_scope(options)}#{subscription.target.to_resource_name}_subsc...
Returns unsubscribe_subscription_url for the target of specified subscription
4,328
def subscribe_to_email_subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "subscribe_to_email_#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "subscribe_to_email_#{routing_scope(options)}#{subscription.target.to...
Returns subscribe_to_email_subscription_url for the target of specified subscription
4,329
def unsubscribe_to_email_subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "unsubscribe_to_email_#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "unsubscribe_to_email_#{routing_scope(options)}#{subscription.tar...
Returns unsubscribe_to_email_subscription_url for the target of specified subscription
4,330
def subscribe_to_optional_target_subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "subscribe_to_optional_target_#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "subscribe_to_optional_target_#{routing_scope(opt...
Returns subscribe_to_optional_target_subscription_url for the target of specified subscription
4,331
def unsubscribe_to_optional_target_subscription_url_for ( subscription , params = { } ) options = params . dup options . delete ( :devise_default_routes ) ? send ( "unsubscribe_to_optional_target_#{routing_scope(options)}subscription_url" , subscription , options ) : send ( "unsubscribe_to_optional_target_#{routing_sco...
Returns unsubscribe_to_optional_target_subscription_url for the target of specified subscription
4,332
def target_view_path target_type = @target . to_resources_name view_path = [ controller_path , target_type ] . join ( '/' ) lookup_context . exists? ( action_name , view_path ) ? view_path : [ controller_path , DEFAULT_VIEW_DIRECTORY ] . join ( '/' ) end
Returns path of the target view templates . Do not make this method public unless Rendarable module calls controller s target_view_path method to render resources .
4,333
def return_back_or_ajax set_index_options respond_to do | format | if request . xhr? load_index if params [ :reload ] . to_s . to_boolean ( true ) format . js else compatibly_redirect_back ( @index_options ) and return end end end
Returns JavaScript view for ajax request or redirects to back as default .
4,334
def compatibly_redirect_back ( request_params = { } ) if Rails :: VERSION :: MAJOR >= 5 redirect_back fallback_location : { action : :index } , ** request_params elsif request . referer redirect_to :back , ** request_params else redirect_to action : :index , ** request_params end true end
Redirect to back .
4,335
def notify_to ( * resources ) options = create_options ( :notifications , resources . extract_options! , [ :new , :create , :edit , :update ] ) resources . each do | target | options [ :defaults ] = { target_type : target . to_s } . merge ( options [ :devise_defaults ] ) resources_options = options . select { | key , _...
Includes notify_to method for routes which is responsible to generate all necessary routes for notifications of activity_notification .
4,336
def subscribed_by ( * resources ) options = create_options ( :subscriptions , resources . extract_options! , [ :new , :edit , :update ] ) resources . each do | target | options [ :defaults ] = { target_type : target . to_s } . merge ( options [ :devise_defaults ] ) resources_options = options . select { | key , _ | [ :...
Includes subscribed_by method for routes which is responsible to generate all necessary routes for subscriptions of activity_notification .
4,337
def text ( params = { } ) k = key . split ( '.' ) k . unshift ( 'notification' ) if k . first != 'notification' if params . has_key? ( :target ) k . insert ( 1 , params [ :target ] ) else k . insert ( 1 , target . to_resource_name ) end k . push ( 'text' ) k = k . join ( '.' ) attrs = ( parameters . symbolize_keys . me...
Virtual attribute returning text description of the notification using the notification s key to translate using i18n .
4,338
def render ( context , params = { } ) params [ :i18n ] and return context . render plain : self . text ( params ) partial = partial_path ( * params . values_at ( :partial , :partial_root , :target ) ) layout = layout_path ( * params . values_at ( :layout , :layout_root ) ) locals = prepare_locals ( params ) begin conte...
Renders notification from views .
4,339
def partial_path ( path = nil , root = nil , target = nil ) controller = ActivityNotification . get_controller if ActivityNotification . respond_to? ( :get_controller ) root ||= "activity_notification/notifications/#{target}" if target . present? root ||= controller . target_view_path if controller . present? && contro...
Returns partial path from options
4,340
def resolve_value ( thing , * args ) case thing when Symbol symbol_method = method ( thing ) if symbol_method . arity > 0 symbol_method . call ( * args ) else symbol_method . call end when Proc if thing . arity > 1 thing . call ( self , * args ) elsif thing . arity > 0 thing . call ( self ) else thing . call end when H...
Used to transform value from metadata to data which belongs model instance . Accepts Symbols which it will send against this instance Accepts Procs which it will execute with this instance . Both Symbols and Procs will be passed arguments of this method . Also accepts Hash of these Symbols or Procs . If any other value...
4,341
def index set_index_options load_index if params [ :reload ] . to_s . to_boolean ( true ) respond_to do | format | format . html format . json { render json : @notifications . to_json ( include : [ :target , :notifiable , :group ] ) } end end
Shows notification index of the target .
4,342
def open with_members = ! ( params [ :with_group_members ] . to_s . to_boolean ( false ) || params [ :without_grouping ] . to_s . to_boolean ( false ) ) @notification . open! ( with_members : with_members ) params [ :move ] . to_s . to_boolean ( false ) ? move : return_back_or_ajax end
Opens a notification .
4,343
def set_index_options limit = params [ :limit ] . to_i > 0 ? params [ :limit ] . to_i : nil reverse = params [ :reverse ] . present? ? params [ :reverse ] . to_s . to_boolean ( false ) : nil with_group_members = params [ :with_group_members ] . present? || params [ :without_grouping ] . present? ? params [ :with_group_...
Sets options to load notification index from request parameters .
4,344
def authenticated_with_devise? ( current_resource ) devise_resource = resolve_value ( _notification_devise_resource ) unless current_resource . blank? or current_resource . is_a? devise_resource . class raise TypeError , "Different type of current resource #{current_resource.class} " "with devise resource #{devise_reso...
Returns if current resource signed in with Devise is authenticated for the notification . This method is able to be overriden .
4,345
def send_batch_notification_email ( notifications , options = { } ) return if notifications . blank? if notifications . map { | n | n . target } . uniq == [ self ] Notification . send_batch_notification_email ( self , notifications , options ) end end
Sends batch notification email to the target .
4,346
def subscribes_to_notification? ( key , subscribe_as_default = ActivityNotification . config . subscribe_as_default ) ! subscription_allowed? ( key ) || _subscribes_to_notification? ( key , subscribe_as_default ) end
Returns if the target subscribes to the notification . It also returns true when the subscription management is not allowed for the target .
4,347
def subscribes_to_notification_email? ( key , subscribe_as_default = ActivityNotification . config . subscribe_as_default ) ! subscription_allowed? ( key ) || _subscribes_to_notification_email? ( key , subscribe_as_default ) end
Returns if the target subscribes to the notification email . It also returns true when the subscription management is not allowed for the target .
4,348
def subscribes_to_optional_target? ( key , optional_target_name , subscribe_as_default = ActivityNotification . config . subscribe_as_default ) ! subscription_allowed? ( key ) || _subscribes_to_optional_target? ( key , optional_target_name , subscribe_as_default ) end
Returns if the target subscribes to the specified optional target . It also returns true when the subscription management is not allowed for the target .
4,349
def _opened_notification_index ( options = { } ) limit = options [ :limit ] || ActivityNotification . config . opened_index_limit reverse = options [ :reverse ] || false with_group_members = options [ :with_group_members ] || false notifications . opened_index ( limit , reverse , with_group_members ) . filtered_by_opti...
Gets opened notification index of the target as ActiveRecord .
4,350
def subscribe ( options = { } ) subscribed_at = options [ :subscribed_at ] || Time . current with_email_subscription = options . has_key? ( :with_email_subscription ) ? options [ :with_email_subscription ] : true with_optional_targets = options . has_key? ( :with_optional_targets ) ? options [ :with_optional_targets ] ...
Subscribes to the notification and notification email .
4,351
def unsubscribe ( options = { } ) unsubscribed_at = options [ :unsubscribed_at ] || Time . current new_attributes = { subscribing : false , unsubscribed_at : unsubscribed_at , subscribing_to_email : false , unsubscribed_to_email_at : unsubscribed_at , optional_targets : optional_targets } optional_target_names . each d...
Unsubscribes to the notification and notification email .
4,352
def subscribe_to_email ( options = { } ) subscribed_to_email_at = options [ :subscribed_to_email_at ] || Time . current update ( subscribing_to_email : true , subscribed_to_email_at : subscribed_to_email_at ) end
Subscribes to the notification email .
4,353
def unsubscribe_to_email ( options = { } ) unsubscribed_to_email_at = options [ :unsubscribed_to_email_at ] || Time . current update ( subscribing_to_email : false , unsubscribed_to_email_at : unsubscribed_to_email_at ) end
Unsubscribes to the notification email .
4,354
def subscribing_to_optional_target? ( optional_target_name , subscribe_as_default = ActivityNotification . config . subscribe_as_default ) optional_target_key = Subscription . to_optional_target_key ( optional_target_name ) subscribe_as_default ? ! optional_targets . has_key? ( optional_target_key ) || optional_targets...
Returns if the target subscribes to the specified optional target .
4,355
def subscribe_to_optional_target ( optional_target_name , options = { } ) subscribed_at = options [ :subscribed_at ] || Time . current update ( optional_targets : optional_targets . merge ( Subscription . to_optional_target_key ( optional_target_name ) => true , Subscription . to_optional_target_subscribed_at_key ( opt...
Subscribes to the specified optional target .
4,356
def unsubscribe_to_optional_target ( optional_target_name , options = { } ) unsubscribed_at = options [ :unsubscribed_at ] || Time . current update ( optional_targets : optional_targets . merge ( Subscription . to_optional_target_key ( optional_target_name ) => false , Subscription . to_optional_target_unsubscribed_at_...
Unsubscribes to the specified optional target .
4,357
def optional_target_names optional_targets . keys . select { | key | key . to_s . start_with? ( "subscribing_to_" ) } . map { | key | key . slice ( 15 .. - 1 ) } end
Returns optional_target names of the subscription from optional_targets field .
4,358
def notification_targets ( target_type , options = { } ) target_typed_method_name = "notification_#{cast_to_resources_name(target_type)}" resolved_parameter = resolve_parameter ( target_typed_method_name , _notification_targets [ cast_to_resources_sym ( target_type ) ] , nil , options ) unless resolved_parameter raise ...
Returns notification targets from configured field or overriden method . This method is able to be overriden .
4,359
def notification_email_allowed? ( target , key = nil ) resolve_parameter ( "notification_email_allowed_for_#{cast_to_resources_name(target.class)}?" , _notification_email_allowed [ cast_to_resources_sym ( target . class ) ] , ActivityNotification . config . email_enabled , target , key ) end
Returns if sending notification email is allowed for the notifiable from configured field or overriden method . This method is able to be overriden .
4,360
def notifiable_path ( target_type , key = nil ) resolved_parameter = resolve_parameter ( "notifiable_path_for_#{cast_to_resources_name(target_type)}" , _notifiable_path [ cast_to_resources_sym ( target_type ) ] , nil , key ) unless resolved_parameter begin resolved_parameter = defined? ( super ) ? super : polymorphic_p...
Returns notifiable_path to move after opening notification from configured field or overriden method . This method is able to be overriden .
4,361
def printable_notifiable_name ( target , key = nil ) resolve_parameter ( "printable_notifiable_name_for_#{cast_to_resources_name(target.class)}?" , _printable_notifiable_name [ cast_to_resources_sym ( target . class ) ] , printable_name , target , key ) end
Returns printable notifiable model name to show in view or email .
4,362
def optional_target_names ( target_type , key = nil ) optional_targets ( target_type , key ) . map { | optional_target | optional_target . to_optional_target_name } end
Returns optional_target names of the notification from configured field or overriden method . This method is able to be overriden .
4,363
def generated_notifications_as_notifiable_for ( target_type = nil ) target_type . nil? ? generated_notifications_as_notifiable . all : generated_notifications_as_notifiable . filtered_by_target_type ( target_type . to_s . to_model_name ) end
Gets generated notifications for specified target type .
4,364
def destroy_generated_notifications_with_dependency ( dependent = :delete_all , target_type = nil , remove_from_group = false ) remove_generated_notifications_from_group ( target_type ) if remove_from_group generated_notifications = generated_notifications_as_notifiable_for ( target_type ) case dependent when :restrict...
Destroies generated notifications for specified target type with dependency . This method is intended to be called before destroy this notifiable as dependent configuration .
4,365
def index set_index_options load_index if params [ :reload ] . to_s . to_boolean ( true ) respond_to do | format | format . html format . json { render json : { subscriptions : @subscriptions , unconfigured_notification_keys : @notification_keys } } end end
Shows subscription index of the target .
4,366
def subscribe @subscription . subscribe ( with_email_subscription : params [ :with_email_subscription ] . to_s . to_boolean ( true ) , with_optional_targets : params [ :with_optional_targets ] . to_s . to_boolean ( true ) ) return_back_or_ajax end
Subscribes to the notification .
4,367
def set_index_options limit = params [ :limit ] . to_i > 0 ? params [ :limit ] . to_i : nil reverse = params [ :reverse ] . present? ? params [ :reverse ] . to_s . to_boolean ( false ) : nil @index_options = params . permit ( :filter , :filtered_by_key , :routing_scope , :devise_default_routes ) . to_h . symbolize_keys...
Sets options to load subscription index from request parameters .
4,368
def load_index case @index_options [ :filter ] when :configured , 'configured' @subscriptions = @target . subscription_index ( @index_options . merge ( with_target : true ) ) @notification_keys = nil when :unconfigured , 'unconfigured' @subscriptions = nil @notification_keys = @target . notification_keys ( @index_optio...
Loads subscription index with request parameters .
4,369
def find_or_create_subscription ( key , subscription_params = { } ) subscription = find_subscription ( key ) subscription || create_subscription ( subscription_params . merge ( key : key ) ) end
Gets subscription of the target and notification key .
4,370
def create_subscription ( subscription_params = { } ) created_at = Time . current if subscription_params [ :subscribing ] == false && subscription_params [ :subscribing_to_email ] . nil? subscription_params [ :subscribing_to_email ] = subscription_params [ :subscribing ] end subscription = subscriptions . new ( subscri...
Creates new subscription of the target .
4,371
def subscription_index ( options = { } ) target_index = subscriptions . filtered_by_options ( options ) target_index = options [ :reverse ] ? target_index . earliest_order : target_index . latest_order target_index = target_index . with_target if options [ :with_target ] options [ :limit ] . present? ? target_index . l...
Gets configured subscription index of the target .
4,372
def notification_keys ( options = { } ) subscription_keys = subscriptions . uniq_keys target_notifications = notifications . filtered_by_options ( options . select { | k , _ | [ :filtered_by_key , :custom_filter ] . include? ( k ) } ) target_notifications = options [ :reverse ] ? target_notifications . earliest_order :...
Gets received notification keys of the target .
4,373
def evaluate_subscription ( record , field , default , * args ) default ? record . blank? || record . send ( field , * args ) : record . present? && record . send ( field , * args ) end
Returns if the target subscribes .
4,374
def to_hierayaml attributes = Hash [ filtered_keys . map { | k | [ k . to_s , values [ k ] ] } ] YAML . dump ( 'type' => { title => attributes } ) . split ( "\n" ) . drop ( 2 ) . join ( "\n" ) + "\n" end
Convert our resource to yaml for Hiera purposes .
4,375
def filtered_keys values . keys . reject { | k | k == :title || ! attr_def [ k ] || ( attr_def [ k ] [ :behaviour ] == :namevar && @namevars . size == 1 ) } end
attribute names that are not title or namevars
4,376
def feature? ( feature ) supported = ( definition [ :features ] && definition [ :features ] . include? ( feature ) ) if supported Puppet . debug ( "#{definition[:name]} supports `#{feature}`" ) else Puppet . debug ( "#{definition[:name]} does not support `#{feature}`" ) end supported end
rubocop complains when this is named has_feature?
4,377
def check_schema ( resource , message_prefix = nil ) namevars . each do | namevar | if resource [ namevar ] . nil? raise Puppet :: ResourceError , "`#{name}.get` did not return a value for the `#{namevar}` namevar attribute" end end message_prefix = 'Provider returned data that does not match the Type Schema' if messag...
validates a resource hash against its type schema
4,378
def check_schema_keys ( resource ) rejected = [ ] resource . reject { | key | rejected << key if key != :title && attributes . key? ( key ) == false } rejected end
Returns an array of keys that where not found in the type schema No longer modifies the resource passed in
4,379
def check_schema_values ( resource ) bad_vals = { } resource . each do | key , value | next unless attributes [ key ] type = @data_type_cache [ attributes [ key ] [ :type ] ] is_sensitive = ( attributes [ key ] . key? ( :sensitive ) && ( attributes [ key ] [ :sensitive ] == true ) ) error_message = Puppet :: ResourceAp...
Returns a hash of keys and values that are not valid does not modify the resource passed in
4,380
def parse ( body ) if self . class . parser begin self . class . parser . call ( body , @parser_options ) rescue StandardError , SyntaxError => err raise err if err . is_a? SyntaxError and err . class . name != 'Psych::SyntaxError' raise Faraday :: Error :: ParsingError , err end else body end end
Parse the response body .
4,381
def prepare_env ( faraday_env ) env = headers_to_rack ( faraday_env ) url = faraday_env [ :url ] env [ 'rack.url_scheme' ] = url . scheme env [ 'PATH_INFO' ] = url . path env [ 'SERVER_PORT' ] = url . respond_to? ( :inferred_port ) ? url . inferred_port : url . port env [ 'QUERY_STRING' ] = url . query env [ 'REQUEST_M...
faraday to rack - compatible
4,382
def restore_env ( rack_env ) env = rack_env . fetch ( 'faraday' ) headers = env [ :request_headers ] headers . clear rack_env . each do | name , value | next unless String === name && String === value if NonPrefixedHeaders . include? name or name . index ( 'HTTP_' ) == 0 name = name . sub ( / / , '' ) . downcase . tr (...
rack to faraday - compatible
4,383
def match_with_syntax_highlight ( match ) highlight_chars = @prompt . abbrev . downcase . scan ( / /mu ) if @encoding && match . respond_to? ( :force_encoding ) && match . encoding != @encoding match = match . force_encoding ( @encoding ) end match . scan ( / /mu ) . inject ( [ ] ) do | output , char | if char . downca...
Highlight matching characters within the matched string .
4,384
def print_match ( idx ) return unless VIM :: Window . select ( @window ) unlock @@buffer [ line ( idx ) ] = match_text_for_idx idx lock end
Print just the specified match .
4,385
def print_matches match_count = @matches . length if match_count == 0 print_error 'NO MATCHES' else return unless VIM :: Window . select ( @window ) unlock clear @window_width = @window . width desired_lines = [ match_count , @min_height ] . max desired_lines = [ max_lines , desired_lines ] . min @window . height = des...
Print all matches .
4,386
def quickfix hide matches = @matches . map do | match | "{ 'filename': '#{VIM::escape_for_single_quotes match}' }" end . join ( ', ' ) :: VIM :: command 'call setqflist([' + matches + '])' :: VIM :: command 'cope' end
Take current matches and stick them in the quickfix window .
4,387
def backspace! if @col > 0 left , cursor , right = abbrev_segments @abbrev = left . chop! + cursor + right @col -= 1 redraw end end
Delete a character to the left of the current cursor position .
4,388
def format ( form = @config [ :local_format ] || :conventional ) if @config [ :local_format ] . is_a? ( Proc ) @config [ :local_format ] . call ( self ) elsif form == :conventional self . conventional elsif form == :canonical self . canonical elsif form == :relaxed self . relax elsif form == :standard self . standard e...
Builds the local string according to configurations
4,389
def standard form = self . mailbox form += @config [ :tag_separator ] + self . tag if self . tag form += "(" + self . comment + ")" if self . comment form . gsub! ( / \\ \" / , '\\\1' ) if form =~ / \" \( \) \[ \\ \] / form = %Q("#{form}") end form end
Returns a normalized version of the standard address parts .
4,390
def conventional? self . syntax = :invalid self . local =~ CONVENTIONAL_MAILBOX_REGEX or return false self . valid_size? or return false self . valid_encoding? or return false self . syntax = :conventional true end
True if the part matches the conventional format
4,391
def relaxed? self . syntax = :invalid self . valid_size? or return false self . valid_encoding? or return false if self . local =~ RELAXED_MAILBOX_REGEX self . syntax = :relaxed true else false end end
Relaxed conventional is not so strict about character order .
4,392
def standard? self . syntax = :invalid self . valid_size? or return false self . valid_encoding? or return false if self . local =~ STANDARD_LOCAL_REGEX self . syntax = :standard true else false end end
True if the part matches the RFC standard format
4,393
def matches? ( * rules ) rules . flatten . each do | r | if r =~ / \z / return r if File . fnmatch? ( $1 , self . local ) end end false end
Matches configured formated form against File glob strings given . Rules must end in
4,394
def canonical c = self . local . canonical c += "@" + self . host . canonical if self . host . canonical && self . host . canonical > " " c end
Returns the canonical email address according to the provider uniqueness rules . Usually this downcases the address removes spaves and comments and tags and any extraneous part of the address not considered a unique account by the provider .
4,395
def provider return @provider if defined? @provider EmailAddress :: Config . providers . each do | provider , config | if config [ :exchanger_match ] && self . matches? ( config [ :exchanger_match ] ) return @provider = provider end end @provider = :default end
Returns the provider name based on the MX - er host names or nil if not matched
4,396
def domains @_domains ||= mxers . map { | m | EmailAddress :: Host . new ( m . first ) . domain_name } . sort . uniq end
Returns Array of domain names for the MX ers used to determine the Provider
4,397
def unique_hosts ( spans ) hosts = [ ] each_endpoint ( spans ) do | endpoint | hosts . push ( endpoint ) end hosts . uniq end
Using this to resolve only once per host
4,398
def producer_options { required_acks : config . required_acks , ack_timeout : config . ack_timeout , max_retries : config . max_retries , retry_backoff : config . retry_backoff , max_buffer_size : config . max_buffer_size , max_buffer_bytesize : config . max_buffer_bytesize , compression_codec : ( config . compression_...
Options for both the sync and async producers .
4,399
def get_schedule ( name = nil ) if name . nil? get_all_schedules else encoded_schedule = SidekiqScheduler :: RedisManager . get_job_schedule ( name ) encoded_schedule . nil? ? nil : JSON . parse ( encoded_schedule ) end end
Retrive the schedule configuration for the given name if the name is nil it returns a hash with all the names end their schedules .