Project

General

Profile

« Previous | Next » 

Revision bb3572ff

Added by Daniel Lobato Garcia over 8 years ago

Refs #3809 - Stabby lambda syntax for oneliners

I started by spotting log.rb which didn't have a lambda wrapping its
default scope, as needed by Rails 4. Since the style guide and most
Rails 4 documents used the stabby lambda, I turned on the cop so that we
use it everywhere there's a oneliner lambda.

View differences:

app/models/puppetclass.rb
has_many :config_groups, :through => :config_group_classes, :dependent => :destroy
has_many :lookup_keys, :inverse_of => :puppetclass, :dependent => :destroy
accepts_nested_attributes_for :lookup_keys, :reject_if => lambda { |a| a[:key].blank? }, :allow_destroy => true
accepts_nested_attributes_for :lookup_keys, :reject_if => ->(a) { a[:key].blank? }, :allow_destroy => true
# param classes
has_many :class_params, :through => :environment_classes, :uniq => true,
:source => :lookup_key, :conditions => 'environment_classes.lookup_key_id is NOT NULL'
accepts_nested_attributes_for :class_params, :reject_if => lambda { |a| a[:key].blank? }, :allow_destroy => true
accepts_nested_attributes_for :class_params, :reject_if => ->(a) { a[:key].blank? }, :allow_destroy => true
validates :name, :uniqueness => true, :presence => true, :no_whitespace => true
audited :allow_mass_assignment => true, :except => [:total_hosts, :lookup_keys_count, :global_class_params_count]
......
alias_attribute :smart_class_parameters, :class_params
alias_attribute :smart_class_parameter_ids, :class_param_ids
default_scope lambda { order('puppetclasses.name') }
default_scope -> { order('puppetclasses.name') }
scoped_search :on => :name, :complete_value => :true
scoped_search :on => :total_hosts
......
scoped_search :in => :hosts, :on => :name, :complete_value => :true, :rename => "host", :ext_method => :search_by_host, :only_explicit => true
scoped_search :in => :class_params, :on => :key, :complete_value => :true, :only_explicit => true
scope :not_in_any_environment, lambda { includes(:environment_classes).where(:environment_classes => {:environment_id => nil}) }
scope :not_in_any_environment, -> { includes(:environment_classes).where(:environment_classes => {:environment_id => nil}) }
# returns a hash containing modules and associated classes
def self.classes2hash(classes)

Also available in: Unified diff