[Rails-core] [Feature][ActiveRecord] Finding Orphans

2018-11-27 Thread Tom Rossi
Its common for me to look for orphans and I typically do it like this:

Child.eager_load(:parent).where(parents: { id: nil })

I would like to propose putting together a PR for something like this:

Child.missing(:parent)
Parent.missing(:children)

Please let me know if others are interested in the functionality and I
would love to give it a shot!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] Re: [ActiveStorage] Feature Request: attachment validations

2018-11-27 Thread ifomichev
Hi George,

thanks for your positive feedback! I'll see how far I can get :)

Best regards,
Ivan

On Tuesday, November 27, 2018 at 4:21:28 PM UTC+1, George Claghorn wrote:
>
> Validations are planned for Rails 6. Here’s a rough sketch of the API I 
> have in mind:
>
> validates_attached :logo, presence: true, byte_size: { less_than: 
> 10.megabytes, message: "must be smaller than 10 MB" }, content_type: 
> /\Aimage\//
>
> I intended to implement this myself, and laid the groundwork for it in the 
> commit Rob mentioned, but Igor Kasyanchuk asked if he could fold 
> active_storage_validations into Active Storage proper: 
> https://github.com/rails/rails/issues/33741. Since September, I’ve been 
> giving him time to open a PR.
>
> Please feel free to investigate yourself. Rails 6 is slated for early next 
> year, so if nobody else opens a PR before then, I’ll come back to 
> validations after the holidays.
>
> On Mon, Nov 26, 2018 at 4:13 PM > wrote:
>
>> Hmmm...
>>
>> Hi Rob,
>>
>> thanks for your reply!
>>
>> I see how one can validate presence of a blob from this change, but I'm 
>> not sure what could be the syntax for validating content type, filename, or 
>> file size after this change. Could you please elaborate on that? The commit 
>> you referred to provides neither documentation nor tests for these cases.
>>
>> Best regards,
>> Ivan
>>
>> On Monday, November 26, 2018 at 9:53:12 PM UTC+1, Rob Zolkos wrote:
>>>
>>> Rails 6 will have validations for AS  
>>> https://github.com/rails/rails/commit/e8682c5bf051517b0b265e446aa1a7eccfd47bf7#diff-c76fb6202b7f95a08fe12f40c4999ac9R11
>>>
>>> On Mon, Nov 26, 2018 at 3:36 PM  wrote:
>>>
 Hi all,

 I think this is one of the essential features that are missing in 
 Active Storage. Thus I'm pretty sure it's gonna be implemented pretty soon 
 one way or another, and I wonder what is the maintainers' plan for it, if 
 there is any.

 I know about active_storage_validations gem, but its functionality is 
 quite limited and the gem itself is pretty self-inconsistent and raw 
 (though it's the best publicly available gem I could find, kudos to the 
 maintainers!)

 One approach I'm thinking of would be to adapt paperclip's validators 
 for Active Storage (thanks to MIT license), and I think I could do it, but 
 I'm not sure if it's gonna be accepted. One doesn't have to invent the 
 wheel, but I'd like to hear an expert opinion.

 Thank you,

 Ivan

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Ruby on Rails: Core" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to rubyonrails-co...@googlegroups.com.
 To post to this group, send email to rubyonra...@googlegroups.com.
 Visit this group at https://groups.google.com/group/rubyonrails-core.
 For more options, visit https://groups.google.com/d/optout.

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-co...@googlegroups.com .
>> To post to this group, send email to rubyonra...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/rubyonrails-core.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] [Feature][ActiveStorage] Pre-defined Variants

2018-11-27 Thread Abhishek Chandrasekhar
@kasper - Allowing the one-off options on a given variant is an even better 
approach and just as easily implementable. Thanks for the suggestion.

> I’m not looking to see this through though, so you’d have to get George 
Claghorn or someone else on board for this ride.

Totally understood :)
@George - would love to hear your thoughts on this. If you agree, I don't 
mind picking up the development and submitting a patch. 

Thanks.

On Tuesday, November 27, 2018 at 10:02:39 AM UTC-5, Kasper Timm Hansen 
wrote:
>
> I do remember proposing this at one point internally:
>
> has_one_attached :avatar do |attachable|
>   attachable.variant :small, resize: ’100x100>’
>   …
> end
>
> I’m also fine with exposing it as `variant(:small)` or for one offs 
> `variant(:small, caption: ’foo’)`.
>
> I’m not looking to see this through though, so you’d have to get George 
> Claghorn or someone else on board for this ride.
>
> Appreciate the extensive write up with reasoning!
>
> Den 27. nov. 2018 kl. 14.28 skrev Abhishek Chandrasekhar <
> abhishek.ch...@gmail.com >:
>
> Hello all -
>
> Firstly, huge thanks to those who have worked on ActiveStorage so far. The 
> library seems to be coming along nicely. 
>
>
> ActiveStorage currently allows you to define variants of an attachment as 
> follows:
>
> ```ruby
> class User < ActiveRecord::Base
>   has_one_attached :avatar
>
>   # ...
> end
>
> user.avatar.variant(resize: "100x100>")
> user.avatar.variant(resize: "100x100>", caption: "foo")
> user.avatar.variant(resize: "200x200", rotate: "-90")
> ```
>
>
> I'd like to propose the following functionality that lets users configure 
> and pre-define variants. 
>
> ```ruby
> class User < ActiveRecord::Base
>   has_one_attached(
> :avatar, 
> variants: { 
>   small: { resize: "100x100>" }
>   small_captioned: { resize: "100x100>", caption: "foo" }
>   medium_rotated: { resize: "200x200", rotate: "-90" }
> }
>   )
>
>   # ...
> end
>
> user.avatar.variant(:small)
> user.avatar.variant(:small_captioned)
> user.avatar.variant(:medium_rotated)
>
> # Something not pre-definied
> user.avatar.variant(rotate: "120")
> ```
>
> This is similar in concept to how existing attachment libraries 
> (paperclip, carrierwave, etc...) have allowed definition and configuration 
> of variants.
>
> It is true that this functionality can be mimicked outside of 
> activestorage by having the developer maintain a manual mapping of key 
> names to variant configurations. However, I believe this should be part of 
> ActiveStorage directly because -
>
>
> 1. It leads to cleaner/more readable code (e.g. `
> user.avatar.variant(:small)` is easy to understand)
> 2. It keeps configuration consolidated inline with `has_one_attached`, 
> which is similar to how options are already defined inline with `has_one`, 
> `has_many`, etc...
> 3. It's fully backward compatible with how variants are invoked right now 
> and doesn't force you to use a particular approach.
>
> Would such a feature be accepted if I were to submit a pull request for 
> it? 
>
> Thank you!
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-co...@googlegroups.com .
> To post to this group, send email to rubyonra...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Kasper
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] Re: [ActiveStorage] Feature Request: attachment validations

2018-11-27 Thread George Claghorn
Validations are planned for Rails 6. Here’s a rough sketch of the API I
have in mind:

validates_attached :logo, presence: true, byte_size: { less_than:
10.megabytes, message: "must be smaller than 10 MB" }, content_type:
/\Aimage\//

I intended to implement this myself, and laid the groundwork for it in the
commit Rob mentioned, but Igor Kasyanchuk asked if he could fold
active_storage_validations into Active Storage proper:
https://github.com/rails/rails/issues/33741. Since September, I’ve been
giving him time to open a PR.

Please feel free to investigate yourself. Rails 6 is slated for early next
year, so if nobody else opens a PR before then, I’ll come back to
validations after the holidays.

On Mon, Nov 26, 2018 at 4:13 PM  wrote:

> Hmmm...
>
> Hi Rob,
>
> thanks for your reply!
>
> I see how one can validate presence of a blob from this change, but I'm
> not sure what could be the syntax for validating content type, filename, or
> file size after this change. Could you please elaborate on that? The commit
> you referred to provides neither documentation nor tests for these cases.
>
> Best regards,
> Ivan
>
> On Monday, November 26, 2018 at 9:53:12 PM UTC+1, Rob Zolkos wrote:
>>
>> Rails 6 will have validations for AS
>> https://github.com/rails/rails/commit/e8682c5bf051517b0b265e446aa1a7eccfd47bf7#diff-c76fb6202b7f95a08fe12f40c4999ac9R11
>>
>> On Mon, Nov 26, 2018 at 3:36 PM  wrote:
>>
>>> Hi all,
>>>
>>> I think this is one of the essential features that are missing in Active
>>> Storage. Thus I'm pretty sure it's gonna be implemented pretty soon one way
>>> or another, and I wonder what is the maintainers' plan for it, if there is
>>> any.
>>>
>>> I know about active_storage_validations gem, but its functionality is
>>> quite limited and the gem itself is pretty self-inconsistent and raw
>>> (though it's the best publicly available gem I could find, kudos to the
>>> maintainers!)
>>>
>>> One approach I'm thinking of would be to adapt paperclip's validators
>>> for Active Storage (thanks to MIT license), and I think I could do it, but
>>> I'm not sure if it's gonna be accepted. One doesn't have to invent the
>>> wheel, but I'd like to hear an expert opinion.
>>>
>>> Thank you,
>>>
>>> Ivan
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ruby on Rails: Core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to rubyonrails-co...@googlegroups.com.
>>> To post to this group, send email to rubyonra...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/rubyonrails-core.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails-core] [Feature][ActiveStorage] Pre-defined Variants

2018-11-27 Thread Kasper Timm Hansen
I do remember proposing this at one point internally:

has_one_attached :avatar do |attachable|
  attachable.variant :small, resize: ’100x100>’
  …
end

I’m also fine with exposing it as `variant(:small)` or for one offs 
`variant(:small, caption: ’foo’)`.

I’m not looking to see this through though, so you’d have to get George 
Claghorn or someone else on board for this ride.

Appreciate the extensive write up with reasoning!

> Den 27. nov. 2018 kl. 14.28 skrev Abhishek Chandrasekhar 
> :
> 
> Hello all -
> 
> Firstly, huge thanks to those who have worked on ActiveStorage so far. The 
> library seems to be coming along nicely. 
> 
> 
> ActiveStorage currently allows you to define variants of an attachment as 
> follows:
> 
> ```ruby
> class User < ActiveRecord::Base
>   has_one_attached :avatar
> 
>   # ...
> end
> 
> user.avatar.variant(resize: "100x100>")
> user.avatar.variant(resize: "100x100>", caption: "foo")
> user.avatar.variant(resize: "200x200", rotate: "-90")
> ```
> 
> 
> I'd like to propose the following functionality that lets users configure and 
> pre-define variants. 
> 
> ```ruby
> class User < ActiveRecord::Base
>   has_one_attached(
> :avatar, 
> variants: { 
>   small: { resize: "100x100>" }
>   small_captioned: { resize: "100x100>", caption: "foo" }
>   medium_rotated: { resize: "200x200", rotate: "-90" }
> }
>   )
> 
>   # ...
> end
> 
> user.avatar.variant(:small)
> user.avatar.variant(:small_captioned)
> user.avatar.variant(:medium_rotated)
> 
> # Something not pre-definied
> user.avatar.variant(rotate: "120")
> ```
> 
> This is similar in concept to how existing attachment libraries (paperclip, 
> carrierwave, etc...) have allowed definition and configuration of variants.
> 
> It is true that this functionality can be mimicked outside of activestorage 
> by having the developer maintain a manual mapping of key names to variant 
> configurations. However, I believe this should be part of ActiveStorage 
> directly because -
> 
> 
> 1. It leads to cleaner/more readable code (e.g. `user.avatar.variant(:small)` 
> is easy to understand)
> 2. It keeps configuration consolidated inline with `has_one_attached`, which 
> is similar to how options are already defined inline with `has_one`, 
> `has_many`, etc...
> 3. It's fully backward compatible with how variants are invoked right now and 
> doesn't force you to use a particular approach.
> 
> Would such a feature be accepted if I were to submit a pull request for it? 
> 
> Thank you!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-core+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to rubyonrails-core@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/rubyonrails-core 
> .
> For more options, visit https://groups.google.com/d/optout 
> .

--
Kasper

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.