Commit 810bfe8c7615c04f6f1c9accf554a7615b8e8c38

Authored by Braulio Bhavamitra
1 parent fe8fe114

rails4: use lambda syntax compatible with ruby 1.9 and 2.0

app/models/article.rb
@@ -74,7 +74,7 @@ class Article < ActiveRecord::Base @@ -74,7 +74,7 @@ class Article < ActiveRecord::Base
74 74
75 has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' 75 has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'
76 76
77 - has_many :article_categorizations, ->{ where 'articles_categories.virtual = ?', false } 77 + has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false }
78 has_many :categories, :through => :article_categorizations 78 has_many :categories, :through => :article_categorizations
79 79
80 has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' 80 has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization'
@@ -126,13 +126,13 @@ class Article < ActiveRecord::Base @@ -126,13 +126,13 @@ class Article < ActiveRecord::Base
126 126
127 xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' 127 xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list'
128 128
129 - scope :in_category, ->(category) { 129 + scope :in_category, -> category {
130 includes('categories_including_virtual').where('categories.id' => category.id) 130 includes('categories_including_virtual').where('categories.id' => category.id)
131 } 131 }
132 132
133 include TimeScopes 133 include TimeScopes
134 134
135 - scope :by_range, ->(range) { 135 + scope :by_range, -> range {
136 where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last } 136 where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last }
137 } 137 }
138 138
@@ -256,16 +256,16 @@ class Article < ActiveRecord::Base @@ -256,16 +256,16 @@ class Article < ActiveRecord::Base
256 256
257 # retrieves all articles belonging to the given +profile+ that are not 257 # retrieves all articles belonging to the given +profile+ that are not
258 # sub-articles of any other article. 258 # sub-articles of any other article.
259 - scope :top_level_for, ->(profile) { 259 + scope :top_level_for, -> profile {
260 where 'parent_id is null and profile_id = ?', profile.id 260 where 'parent_id is null and profile_id = ?', profile.id
261 } 261 }
262 262
263 - scope :is_public, ->{ 263 + scope :is_public, -> {
264 joins(:profile). 264 joins(:profile).
265 where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true) 265 where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true)
266 } 266 }
267 267
268 - scope :more_recent, ->{ 268 + scope :more_recent, -> {
269 order('articles.published_at desc, articles.id desc') 269 order('articles.published_at desc, articles.id desc')
270 .where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND 270 .where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND
271 ((articles.type != ?) OR articles.type is NULL)", 271 ((articles.type != ?) OR articles.type is NULL)",
@@ -278,8 +278,8 @@ class Article < ActiveRecord::Base @@ -278,8 +278,8 @@ class Article < ActiveRecord::Base
278 paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) 278 paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit)
279 end 279 end
280 280
281 - scope :more_popular, ->{ order 'hits DESC' }  
282 - scope :relevant_as_recent, ->{ 281 + scope :more_popular, -> { order 'hits DESC' }
  282 + scope :relevant_as_recent, -> {
283 where "(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL" 283 where "(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"
284 } 284 }
285 285
@@ -410,7 +410,7 @@ class Article < ActiveRecord::Base @@ -410,7 +410,7 @@ class Article < ActiveRecord::Base
410 self.translations.map(&:language) 410 self.translations.map(&:language)
411 end 411 end
412 412
413 - scope :native_translations, ->{ where :translation_of_id => nil } 413 + scope :native_translations, -> { where :translation_of_id => nil }
414 414
415 def translatable? 415 def translatable?
416 false 416 false
@@ -489,19 +489,19 @@ class Article < ActiveRecord::Base @@ -489,19 +489,19 @@ class Article < ActiveRecord::Base
489 ['TextArticle', 'TextileArticle', 'TinyMceArticle'] 489 ['TextArticle', 'TextileArticle', 'TinyMceArticle']
490 end 490 end
491 491
492 - scope :published, ->{ where 'articles.published = ?', true }  
493 - scope :folders, ->(profile) { where 'articles.type IN (?)', profile.folder_types }  
494 - scope :no_folders, ->(profile) { where 'articles.type NOT IN (?)', profile.folder_types }  
495 - scope :galleries, ->{ where "articles.type IN ('Gallery')" }  
496 - scope :images, ->{ where :is_image => true }  
497 - scope :no_images, ->{ where :is_image => false }  
498 - scope :text_articles, ->{ where 'articles.type IN (?)', text_article_types }  
499 - scope :files, ->{ where :type => 'UploadedFile' }  
500 - scope :with_types, ->(types) { where 'articles.type IN (?)', types } 492 + scope :published, -> { where 'articles.published = ?', true }
  493 + scope :folders, -> profile { where 'articles.type IN (?)', profile.folder_types }
  494 + scope :no_folders, -> profile { where 'articles.type NOT IN (?)', profile.folder_types }
  495 + scope :galleries, -> { where "articles.type IN ('Gallery')" }
  496 + scope :images, -> { where :is_image => true }
  497 + scope :no_images, -> { where :is_image => false }
  498 + scope :text_articles, -> { where 'articles.type IN (?)', text_article_types }
  499 + scope :files, -> { where :type => 'UploadedFile' }
  500 + scope :with_types, -> types { where 'articles.type IN (?)', types }
501 501
502 - scope :more_popular, ->{ order 'hits DESC' }  
503 - scope :more_comments, ->{ order "comments_count DESC" }  
504 - scope :more_recent, ->{ order "created_at DESC" } 502 + scope :more_popular, -> { order 'hits DESC' }
  503 + scope :more_comments, -> { order "comments_count DESC" }
  504 + scope :more_recent, -> { order "created_at DESC" }
505 505
506 scope :display_filter, lambda {|user, profile| 506 scope :display_filter, lambda {|user, profile|
507 return published if (user.nil? && profile && profile.public?) 507 return published if (user.nil? && profile && profile.public?)
app/models/category.rb
@@ -15,11 +15,11 @@ class Category < ActiveRecord::Base @@ -15,11 +15,11 @@ class Category < ActiveRecord::Base
15 belongs_to :environment 15 belongs_to :environment
16 16
17 # Finds all top level categories for a given environment. 17 # Finds all top level categories for a given environment.
18 - scope :top_level_for, ->(environment) { 18 + scope :top_level_for, -> environment {
19 where 'parent_id is null and environment_id = ?', environment.id 19 where 'parent_id is null and environment_id = ?', environment.id
20 } 20 }
21 21
22 - scope :on_level, ->(parent) { where :parent_id => parent } 22 + scope :on_level, -> parent { where :parent_id => parent }
23 23
24 acts_as_filesystem 24 acts_as_filesystem
25 25
@@ -46,7 +46,7 @@ class Category < ActiveRecord::Base @@ -46,7 +46,7 @@ class Category < ActiveRecord::Base
46 display_color = nil if display_color.blank? 46 display_color = nil if display_color.blank?
47 end 47 end
48 48
49 - scope :from_types, ->(types) { 49 + scope :from_types, -> types {
50 if types.select{ |t| t.blank? }.empty? then 50 if types.select{ |t| t.blank? }.empty? then
51 where(type: types) else 51 where(type: types) else
52 where("type IN (?) OR type IS NULL", types.reject{ |t| t.blank? }) end 52 where("type IN (?) OR type IS NULL", types.reject{ |t| t.blank? }) end
app/models/event.rb
@@ -34,19 +34,19 @@ class Event < Article @@ -34,19 +34,19 @@ class Event < Article
34 end 34 end
35 end 35 end
36 36
37 - scope :by_day, ->(date) { 37 + scope :by_day, -> date {
38 where('start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)', 38 where('start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)',
39 start_date: date.beginning_of_day, end_date: date.end_of_day). 39 start_date: date.beginning_of_day, end_date: date.end_of_day).
40 order('start_date ASC') 40 order('start_date ASC')
41 } 41 }
42 42
43 - scope :next_events_from_month, ->(date) { 43 + scope :next_events_from_month, -> date {
44 date_temp = date.strftime("%Y-%m-%d") 44 date_temp = date.strftime("%Y-%m-%d")
45 order('start_date ASC') 45 order('start_date ASC')
46 .where("start_date >= ?","#{date_temp}") 46 .where("start_date >= ?","#{date_temp}")
47 } 47 }
48 48
49 - scope :by_month, ->(date) { 49 + scope :by_month, -> date {
50 order('start_date ASC') 50 order('start_date ASC')
51 .where("EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?", date.year, date.month) 51 .where("EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?", date.year, date.month)
52 } 52 }
@@ -69,7 +69,7 @@ class Event &lt; Article @@ -69,7 +69,7 @@ class Event &lt; Article
69 'event' 69 'event'
70 end 70 end
71 71
72 - scope :by_range, ->(range) { 72 + scope :by_range, -> range {
73 where('start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', 73 where('start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day',
74 {:start_day => range.first, :end_day => range.last}) 74 {:start_day => range.first, :end_day => range.last})
75 } 75 }
app/models/person.rb
@@ -16,24 +16,24 @@ class Person &lt; Profile @@ -16,24 +16,24 @@ class Person &lt; Profile
16 acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} 16 acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)}
17 acts_as_accessor 17 acts_as_accessor
18 18
19 - scope :members_of, ->(resources) { 19 + scope :members_of, -> resources {
20 resources = Array(resources) 20 resources = Array(resources)
21 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') 21 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ')
22 select('DISTINCT profiles.*').joins(:role_assignments).where([conditions]) 22 select('DISTINCT profiles.*').joins(:role_assignments).where([conditions])
23 } 23 }
24 24
25 - scope :not_members_of, ->(resources) { 25 + scope :not_members_of, -> resources {
26 resources = Array(resources) 26 resources = Array(resources)
27 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') 27 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ')
28 select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions) 28 select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions)
29 } 29 }
30 30
31 - scope :by_role, ->(roles) { 31 + scope :by_role, -> roles {
32 roles = Array(roles) 32 roles = Array(roles)
33 select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles) 33 select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles)
34 } 34 }
35 35
36 - scope :not_friends_of, ->(resources) { 36 + scope :not_friends_of, -> resources {
37 resources = Array(resources) 37 resources = Array(resources)
38 select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "friendships" ON "friendships"."person_id" = "profiles"."id" WHERE "friendships"."friend_id" IN (%s))' % resources.map(&:id)) 38 select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "friendships" ON "friendships"."person_id" = "profiles"."id" WHERE "friendships"."friend_id" IN (%s))' % resources.map(&:id))
39 } 39 }
@@ -83,7 +83,7 @@ class Person &lt; Profile @@ -83,7 +83,7 @@ class Person &lt; Profile
83 has_many :friendships, :dependent => :destroy 83 has_many :friendships, :dependent => :destroy
84 has_many :friends, :class_name => 'Person', :through => :friendships 84 has_many :friends, :class_name => 'Person', :through => :friendships
85 85
86 - scope :online, ->{ 86 + scope :online, -> {
87 joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes) 87 joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes)
88 } 88 }
89 89
@@ -102,27 +102,27 @@ class Person &lt; Profile @@ -102,27 +102,27 @@ class Person &lt; Profile
102 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' 102 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
103 103
104 has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy 104 has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy
105 - has_many :suggested_people, ->{ 105 + has_many :suggested_people, -> {
106 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true 106 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true
107 }, through: :suggested_profiles, source: :suggestion 107 }, through: :suggested_profiles, source: :suggestion
108 - has_many :suggested_communities, ->{ 108 + has_many :suggested_communities, -> {
109 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true 109 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true
110 }, through: :suggested_profiles, source: :suggestion 110 }, through: :suggested_profiles, source: :suggestion
111 111
112 - scope :more_popular, ->{ order 'friends_count DESC' } 112 + scope :more_popular, -> { order 'friends_count DESC' }
113 113
114 - scope :abusers, ->{ 114 + scope :abusers, -> {
115 joins(:abuse_complaints).where('tasks.status = 3').select('DISTINCT profiles.*') 115 joins(:abuse_complaints).where('tasks.status = 3').select('DISTINCT profiles.*')
116 } 116 }
117 - scope :non_abusers, ->{ 117 + scope :non_abusers, -> {
118 select("DISTINCT profiles.*"). 118 select("DISTINCT profiles.*").
119 joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'"). 119 joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'").
120 where("tasks.status != 3 OR tasks.id is NULL") 120 where("tasks.status != 3 OR tasks.id is NULL")
121 } 121 }
122 122
123 - scope :admins, ->{ joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') }  
124 - scope :activated, ->{ joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') }  
125 - scope :deactivated, ->{ joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') } 123 + scope :admins, -> { joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') }
  124 + scope :activated, -> { joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') }
  125 + scope :deactivated, -> { joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') }
126 126
127 after_destroy do |person| 127 after_destroy do |person|
128 Friendship.where(friend_id: person.id).each{ |friendship| friendship.destroy } 128 Friendship.where(friend_id: person.id).each{ |friendship| friendship.destroy }
app/models/product.rb
@@ -52,7 +52,7 @@ class Product &lt; ActiveRecord::Base @@ -52,7 +52,7 @@ class Product &lt; ActiveRecord::Base
52 52
53 scope :more_recent, :order => "created_at DESC" 53 scope :more_recent, :order => "created_at DESC"
54 54
55 - scope :from_category, ->(category) { 55 + scope :from_category, -> category {
56 joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category 56 joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category
57 } 57 }
58 58
app/models/product_category.rb
@@ -6,14 +6,14 @@ class ProductCategory &lt; Category @@ -6,14 +6,14 @@ class ProductCategory &lt; Category
6 attr_accessible :name, :parent, :environment 6 attr_accessible :name, :parent, :environment
7 7
8 scope :unique, :select => 'DISTINCT ON (path) categories.*' 8 scope :unique, :select => 'DISTINCT ON (path) categories.*'
9 - scope :by_enterprise, ->(enterprise) { 9 + scope :by_enterprise, -> enterprise {
10 joins(:products). 10 joins(:products).
11 where('products.profile_id = ?', enterprise.id) 11 where('products.profile_id = ?', enterprise.id)
12 } 12 }
13 - scope :by_environment, ->(environment) { 13 + scope :by_environment, -> environment {
14 where 'environment_id = ?', environment.id 14 where 'environment_id = ?', environment.id
15 } 15 }
16 - scope :unique_by_level, ->(level) { 16 + scope :unique_by_level, -> level {
17 select "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*" 17 select "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*"
18 } 18 }
19 19
app/models/profile.rb
@@ -87,28 +87,28 @@ class Profile &lt; ActiveRecord::Base @@ -87,28 +87,28 @@ class Profile &lt; ActiveRecord::Base
87 87
88 include Noosfero::Plugin::HotSpot 88 include Noosfero::Plugin::HotSpot
89 89
90 - scope :memberships_of, ->(person) { 90 + scope :memberships_of, -> person {
91 select('DISTINCT profiles.*'). 91 select('DISTINCT profiles.*').
92 joins(:role_assignments). 92 joins(:role_assignments).
93 where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id) 93 where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id)
94 } 94 }
95 #FIXME: these will work only if the subclass is already loaded 95 #FIXME: these will work only if the subclass is already loaded
96 - scope :enterprises, ->{ 96 + scope :enterprises, -> {
97 where((Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) 97 where((Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR "))
98 } 98 }
99 - scope :communities, ->{ 99 + scope :communities, -> {
100 where((Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) 100 where((Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR "))
101 } 101 }
102 - scope :templates, ->(template_id = nil) { 102 + scope :templates, -> template_id = nil {
103 s = where is_template: true 103 s = where is_template: true
104 s = s.where id: template_id if template_id 104 s = s.where id: template_id if template_id
105 s 105 s
106 } 106 }
107 107
108 - scope :with_templates, ->(templates) { 108 + scope :with_templates, -> templates {
109 where template_id: templates 109 where template_id: templates
110 } 110 }
111 - scope :no_templates, ->{ where is_template: false } 111 + scope :no_templates, -> { where is_template: false }
112 112
113 # Returns a scoped object to select profiles in a given location or in a radius 113 # Returns a scoped object to select profiles in a given location or in a radius
114 # distance from the given location center. 114 # distance from the given location center.
@@ -185,10 +185,10 @@ class Profile &lt; ActiveRecord::Base @@ -185,10 +185,10 @@ class Profile &lt; ActiveRecord::Base
185 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') 185 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',')
186 end 186 end
187 187
188 - scope :visible, ->{ where visible: true, secret: false }  
189 - scope :disabled, ->{ where visible: false }  
190 - scope :is_public, ->{ where visible: true, public_profile: true, secret: false }  
191 - scope :enabled, ->{ where enabled: true } 188 + scope :visible, -> { where visible: true, secret: false }
  189 + scope :disabled, -> { where visible: false }
  190 + scope :is_public, -> { where visible: true, public_profile: true, secret: false }
  191 + scope :enabled, -> { where enabled: true }
192 192
193 # Subclasses must override this method 193 # Subclasses must override this method
194 scope :more_popular 194 scope :more_popular
@@ -289,7 +289,7 @@ class Profile &lt; ActiveRecord::Base @@ -289,7 +289,7 @@ class Profile &lt; ActiveRecord::Base
289 end 289 end
290 end 290 end
291 291
292 - has_many :profile_categorizations, ->{ where 'categories_profiles.virtual = ?', false } 292 + has_many :profile_categorizations, -> { where 'categories_profiles.virtual = ?', false }
293 has_many :categories, :through => :profile_categorizations 293 has_many :categories, :through => :profile_categorizations
294 294
295 has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' 295 has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization'
app/models/scrap.rb
@@ -18,9 +18,9 @@ class Scrap &lt; ActiveRecord::Base @@ -18,9 +18,9 @@ class Scrap &lt; ActiveRecord::Base
18 after_create :create_activity 18 after_create :create_activity
19 after_update :update_activity 19 after_update :update_activity
20 20
21 - scope :all_scraps, ->(profile) { limit(30).where("receiver_id = ? OR sender_id = ?", profile, profile) } 21 + scope :all_scraps, -> profile { limit(30).where("receiver_id = ? OR sender_id = ?", profile, profile) }
22 22
23 - scope :not_replies, ->{ where scrap_id: nil } 23 + scope :not_replies, -> { where scrap_id: nil }
24 24
25 track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target, :custom_user => :sender 25 track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target, :custom_user => :sender
26 26
app/models/task.rb
@@ -281,16 +281,16 @@ class Task &lt; ActiveRecord::Base @@ -281,16 +281,16 @@ class Task &lt; ActiveRecord::Base
281 end 281 end
282 end 282 end
283 283
284 - scope :pending, ->{ where status: Task::Status::ACTIVE }  
285 - scope :hidden, ->{ where status: Task::Status::HIDDEN }  
286 - scope :finished, ->{ where status: Task::Status::FINISHED }  
287 - scope :canceled, ->{ where status: Task::Status::CANCELLED }  
288 - scope :closed, ->{ where status: [Task::Status::CANCELLED, Task::Status::FINISHED] }  
289 - scope :opened, ->{ where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] }  
290 - scope :of, ->(type) { where "type LIKE ?", type if type }  
291 - scope :order_by, ->(attribute, ord) { order "#{attribute} #{ord}" }  
292 - scope :like, ->(field, value) { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value }  
293 - scope :pending_all, ->(profile, filter_type, filter_text) { 284 + scope :pending, -> { where status: Task::Status::ACTIVE }
  285 + scope :hidden, -> { where status: Task::Status::HIDDEN }
  286 + scope :finished, -> { where status: Task::Status::FINISHED }
  287 + scope :canceled, -> { where status: Task::Status::CANCELLED }
  288 + scope :closed, -> { where status: [Task::Status::CANCELLED, Task::Status::FINISHED] }
  289 + scope :opened, -> { where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] }
  290 + scope :of, -> type { where "type LIKE ?", type if type }
  291 + scope :order_by, -> attribute, ord { order "#{attribute} #{ord}" }
  292 + scope :like, -> field, value { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value }
  293 + scope :pending_all, -> profile, filter_type, filter_text {
294 self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text) 294 self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text)
295 } 295 }
296 296
@@ -364,7 +364,7 @@ class Task &lt; ActiveRecord::Base @@ -364,7 +364,7 @@ class Task &lt; ActiveRecord::Base
364 # specified code AND with status = Task::Status::ACTIVE. 364 # specified code AND with status = Task::Status::ACTIVE.
365 # 365 #
366 # Can be used in subclasses to find only their instances. 366 # Can be used in subclasses to find only their instances.
367 - scope :from_code, ->(code) { where code: code, status: Task::Status::ACTIVE } 367 + scope :from_code, -> code { where code: code, status: Task::Status::ACTIVE }
368 368
369 class << self 369 class << self
370 370
plugins/bsc/lib/bsc_plugin/contract.rb
@@ -8,8 +8,8 @@ class BscPlugin::Contract &lt; ActiveRecord::Base @@ -8,8 +8,8 @@ class BscPlugin::Contract &lt; ActiveRecord::Base
8 8
9 belongs_to :bsc, :class_name => 'BscPlugin::Bsc' 9 belongs_to :bsc, :class_name => 'BscPlugin::Bsc'
10 10
11 - named_scope :status, ->(status_list) { where 'status in (?)', status_list if status_list.present? }  
12 - named_scope :sorted_by, ->(sorter, direction) { order "#{sorter} #{direction}" } 11 + named_scope :status, -> status_list { where 'status in (?)', status_list if status_list.present? }
  12 + named_scope :sorted_by, -> sorter, direction { order "#{sorter} #{direction}" }
13 13
14 before_create do |contract| 14 before_create do |contract|
15 contract.created_at ||= Time.now.utc 15 contract.created_at ||= Time.now.utc
plugins/comment_group/lib/ext/comment.rb
@@ -2,9 +2,9 @@ require_dependency &#39;comment&#39; @@ -2,9 +2,9 @@ require_dependency &#39;comment&#39;
2 2
3 class Comment 3 class Comment
4 4
5 - scope :without_group, ->{ where group_id: nil } 5 + scope :without_group, -> { where group_id: nil }
6 6
7 - scope :in_group, ->(group_id) { where 'group_id = ?', group_id } 7 + scope :in_group, -> group_id { where 'group_id = ?', group_id }
8 8
9 attr_accessible :group_id 9 attr_accessible :group_id
10 10
plugins/custom_forms/lib/custom_forms_plugin/form.rb
@@ -26,9 +26,9 @@ class CustomFormsPlugin::Form &lt; ActiveRecord::Base @@ -26,9 +26,9 @@ class CustomFormsPlugin::Form &lt; ActiveRecord::Base
26 tasks.each {|task| task.cancel} 26 tasks.each {|task| task.cancel}
27 end 27 end
28 28
29 - scope :from_profile, ->(profile) { where profile_id: profile.id }  
30 - scope :on_memberships, ->{ where on_membership: true, for_admission: false }  
31 - scope :for_admissions, ->{ where for_admission: true } 29 + scope :from_profile, -> profile { where profile_id: profile.id }
  30 + scope :on_memberships, -> { where on_membership: true, for_admission: false }
  31 + scope :for_admissions, -> { where for_admission: true }
32 =begin 32 =begin
33 scope :accessible_to lambda do |profile| 33 scope :accessible_to lambda do |profile|
34 #TODO should verify is profile is associated with the form owner 34 #TODO should verify is profile is associated with the form owner
plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb
@@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey &lt; Task @@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey &lt; Task
5 5
6 include CustomFormsPlugin::Helper 6 include CustomFormsPlugin::Helper
7 7
8 - scope :from_profile, ->(profile) { where requestor_id: profile.id } 8 + scope :from_profile, -> profile { where requestor_id: profile.id }
9 9
10 def perform 10 def perform
11 form = CustomFormsPlugin::Form.find(form_id) 11 form = CustomFormsPlugin::Form.find(form_id)
plugins/people_block/lib/ext/person.rb
@@ -2,7 +2,7 @@ require_dependency &#39;person&#39; @@ -2,7 +2,7 @@ require_dependency &#39;person&#39;
2 2
3 class Person 3 class Person
4 4
5 - scope :with_role, ->(role_id) { 5 + scope :with_role, -> role_id {
6 select('DISTINCT profiles.*').joins(:role_assignments). 6 select('DISTINCT profiles.*').joins(:role_assignments).
7 where("role_assignments.role_id = #{role_id}") 7 where("role_assignments.role_id = #{role_id}")
8 } 8 }
plugins/spaminator/lib/spaminator_plugin/report.rb
@@ -8,7 +8,7 @@ class SpaminatorPlugin::Report &lt; ActiveRecord::Base @@ -8,7 +8,7 @@ class SpaminatorPlugin::Report &lt; ActiveRecord::Base
8 8
9 attr_accessible :environment 9 attr_accessible :environment
10 10
11 - scope :from_environment, ->(environment) { where :environment_id => environment } 11 + scope :from_environment, -> environment { where :environment_id => environment }
12 12
13 after_initialize do |report| 13 after_initialize do |report|
14 report.failed = {:people => [], :comments => []} if report.failed.blank? 14 report.failed = {:people => [], :comments => []} if report.failed.blank?
plugins/sub_organizations/lib/ext/organization.rb
@@ -13,17 +13,17 @@ class Organization @@ -13,17 +13,17 @@ class Organization
13 13
14 FIELDS << 'sub_organizations_plugin_parent_to_be' 14 FIELDS << 'sub_organizations_plugin_parent_to_be'
15 15
16 - scope :children, ->(parent) { 16 + scope :children, -> parent {
17 joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.child_id"). 17 joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.child_id").
18 where("relations.parent_id = ?", parent.id) 18 where("relations.parent_id = ?", parent.id)
19 } 19 }
20 20
21 - scope :parents, ->(*children) { 21 + scope :parents, -> *children {
22 joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id"). 22 joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id").
23 where("relations.child_id in (?)", children.map(&:id)) 23 where("relations.child_id in (?)", children.map(&:id))
24 } 24 }
25 25
26 - scope :pending_children, ->(parent) { 26 + scope :pending_children, -> parent {
27 select("distinct profiles.*"). 27 select("distinct profiles.*").
28 joins("inner join sub_organizations_plugin_approve_paternity_relations as relations on profiles.id=relations.child_id inner join tasks on relations.task_id=tasks.id"). 28 joins("inner join sub_organizations_plugin_approve_paternity_relations as relations on profiles.id=relations.child_id inner join tasks on relations.task_id=tasks.id").
29 where("relations.parent_id = ? AND tasks.status = 1", parent.id) 29 where("relations.parent_id = ? AND tasks.status = 1", parent.id)
vendor/plugins/access_control/lib/role_assignment.rb
@@ -9,11 +9,11 @@ class RoleAssignment &lt; ActiveRecord::Base @@ -9,11 +9,11 @@ class RoleAssignment &lt; ActiveRecord::Base
9 validates_presence_of :role, :accessor 9 validates_presence_of :role, :accessor
10 10
11 track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], 11 track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"],
12 - if: ->(x) { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 }, 12 + if: -> x { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 },
13 :custom_user => :accessor, :custom_target => :resource 13 :custom_user => :accessor, :custom_target => :resource
14 14
15 track_actions :add_member_in_community, :after_create, 15 track_actions :add_member_in_community, :after_create,
16 - if: ->(x) { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 }, 16 + if: -> x { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 },
17 :custom_user => :accessor, :custom_target => :resource 17 :custom_user => :accessor, :custom_target => :resource
18 18
19 def has_permission?(perm, res) 19 def has_permission?(perm, res)
vendor/plugins/kandadaboggu-vote_fu/lib/models/vote.rb
1 class Vote < ActiveRecord::Base 1 class Vote < ActiveRecord::Base
2 2
3 - scope :for_voter, ->(*args) { 3 + scope :for_voter, -> *args {
4 where "voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name 4 where "voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name
5 } 5 }
6 - scope :for_voteable, ->(*args) { 6 + scope :for_voteable, -> *args {
7 where "voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name 7 where "voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name
8 } 8 }
9 - scope :recent, ->(*args) { 9 + scope :recent, -> *args {
10 where "created_at > ?", (args.first || 2.weeks.ago).to_s(:db) 10 where "created_at > ?", (args.first || 2.weeks.ago).to_s(:db)
11 } 11 }
12 - scope :descending, ->{ order "created_at DESC" } 12 + scope :descending, -> { order "created_at DESC" }
13 13
14 # NOTE: Votes belong to the "voteable" interface, and also to voters 14 # NOTE: Votes belong to the "voteable" interface, and also to voters
15 belongs_to :voteable, :polymorphic => true 15 belongs_to :voteable, :polymorphic => true