Rails plugins and libraries / Lower-level

From WhyNotWiki

Jump to: navigation, search

Contents

[edit] [Ruby-level (category)]

(Ruby support libraries that are packaged as Rails plugins (unfortunately), as well as some that are plain old gems...)

[edit] Injection

Categories/Tags: [dependency injection (category)]



Project/Development: http://rubyforge.org/projects/injection/


Description: Injection is a simple dependency injection plugin for rails which lets you inject objects into your controllers which have been declared in a YAML file.





[edit] ActiveSupport

...

[edit] star_full.gif star_empty.gif star_empty.gif Named Options

As listed in other directories: http://rubyfurnace.com/plugins/named_options






def user(*args)
  options = NamedOptions.new(:name, :age, args)
  options[:name] # => “maiha”
  options[:age] # => 14
end

Lets you call it using ordered arguments or with a hash of arguments/options...

user(“maiha”, 14)
user(:name => ‘maiha’, :age => 14)
user(“maiha”, :age => 14)

[edit] SandboxedMethods

http://rubyfurnace.com/plugins/sandboxed_methods

Avoid conflicting method and variable names between modules.

"We unconsciously prefer shorter names and tend to use well-conflictable method names such as ‘names’, ‘valid?’, ‘path’ for middle(internal) methods. Indeed it works sanely in your system, but how about outside of it?"

To use it, just change your module from this:

 1 module Foo
 2   def self.included(base)
 3     base.__send__ :include, InstanceMethods
 4   end
 5 
 6   module InstanceMethods
       ...
16   end
17 end

to this:

 1 module Foo
 2   def self.included(base)
 3     InstanceMethods.give(base, :foo)        # 1) use 'give' class methods
 4   end
 5 
 6   class InstanceMethods < SandboxedMethods  # 2) use SandboxedMethods class
       ...
16   end
17 end

It basically does this by prefixing each method with the name of the class ("class_name__method_name"?) and then delegating (?) all method calls...

http://wota.jp/svn/rails/plugins/trunk/sandboxed_methods/lib/sandboxed_methods.rb

    def give(base, *methods)
      target  = (methods.last.is_a?(Hash) && methods.pop[:class]) ? (class<<base; self end) : base
      methods = instance_methods - SandboxedMethods.instance_methods if methods.empty?
      methods << {:to=>"(@_#{name.underscore.gsub('/', '__')} ||= #{self}.new(self))"}
      target.delegate *methods
    end

[edit] [Ruby-level (category)]: Dates and times

[edit] relative_time_helpers

Rating:
Homepage: [1]
Source code: http://ar-code.svn.engineyard.com/plugins/relative_time_helpers/








http://ar-code.svn.engineyard.com/plugins/relative_time_helpers/init.rb

    # Used for getting multifield attributes like those generated by a 
    # select_datetime into a new Time object. For example if you have 
    # following <tt>params={:meetup=>{:"time(1i)=>..."}}</tt> just do 
    # following:
    #
    # <tt>Time.parse_from_attributes(params[:meetup], :time)</tt>
    def parse_from_attributes(attrs, field, method=:gm)
      attrs = attrs.keys.sort.grep(/^#{field.to_s}\(.+\)$/).map { |k| attrs[k] }
      attrs.any? ? Time.send(method, *attrs) : nil
    end

Con: They foist their date format preferences on you (Nov 15th, rather than 15 November or 11-15):

http://ar-code.svn.engineyard.com/plugins/relative_time_helpers/test/relative_time_helpers_test.rb

  def test_should_show_date_span_on_the_different_year
    assert_equal 'Nov 15th, 2006 - Dec 16th, 2007', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2007, 12, 16)])
    assert_equal 'Nov 15th, 2006 - Dec 16th, 2007', relative_date_span([Time.utc(2007, 12, 16), Time.utc(2006, 11, 15)])
  end

[edit] star_full.gif star_empty.gif star_empty.gif interpolated_time_formats

Homepage: http://wiki.pluginaweek.org/Interpolated_time_formats
Source code: http://svn.pluginaweek.org/trunk/plugins/ruby/time/interpolated_time_formats


As listed in other directories: http://rubyfurnace.com/plugins/interpolated_time_formats






http://wiki.pluginaweek.org/Interpolated_time_formats

Rather than requiring the addition of helper methods, this plugin proposes creating such strings with strftime. For example,

>> Time.parse('12/31/2006').strftime('#{day.ordinalize} of %B')
=> "31st of December"


[edit] EZTime

http://users.webtest.wvu.edu/cbscharf/eztime/

puts d.eztime(":day :nmonth :year at :hour12::minute::second 
:lmeridian") 
=> 20 December 2003 at 5:30:00 pm

[edit] Date Finder

http://rubyfurnace.com/plugins/date_finder

Can find dates that match certain criteria. Eg:

The next three Tuesdays: DateFinderBase.weekly.day(:tuesday).find(:max => 3)

The last Monday for the next three months: DateFinderBase.monthly.day(:monday).day_occurrence(:last).find(:max => 3)

Note: This appears to have nothing at all to do with ActiveRecord searching (kind of deceptive, if you ask me, since it's packaged as a Rails plugin). Rather, it actually returns Date instances as the results of its "searches".

[edit] [library-level (category)]

[edit] object_id_session: Lets you store ActiveRecord models in the session using their IDs

http://rubyfurnace.com/plugins/object_id_session

A very simple plugin that allows to store ActiveRecord models over session using their IDs transparently.

session[:user] = User.find(id)
# After this, your session will have :user => id and ?__user_object_id_session? => User.

[edit] star_full.gif star_full.gif star_empty.gif [GnuPG (category)] plugin [API wrappers for command-line applications (category)]

Homepage: http://www.ahgsoftware.com/pages/erb_buffer
Source code: svn://ahgsoftware.com/gnupg/trunk


As listed in other directories: http://rubyfurnace.com/plugins/gnupg






passphrase = "uglydonkeys"

gnupg = GnuPG.new :binary=>"/opt/local/bin/gpg",
   :workdir=>workdir,
   :homedir_pub=>workdir,
   :homedir_sec=>workdir,
   :recipient=>"your uid"

plain_message = "my secret message"
encrypted_message = gnupg.encrypt(plain_message)

gnupg.load_key File.read("sec_key.asc")
decrypted_message = gnupg.decrypt(encrypted_message, passphrase)
gnupg.drop_key

[edit] RailMail

http://railmail.nullstyle.com/

Advantages:

  • Logs all outgoing e-mail to a database table. Much nicer to read/search than the log file, which is where it gets logged by default.
    • Why would you want to see what's been sent? Maybe if someone claims they never received an e-mail you sent, you could check the logs easily and see. (Even if it appears that you did already send it, this would make it easier to resend.)
  • Less dependencies on your development box. No need to set up outgoing mail on your box or even have an Internet connection. Just check the RailMail log to see if it went out.
  • Can test your application with addresses other than your own and not worry about bothering other people. (This could also be solved by using a much simpler plugin that just overrode ActionMailer to have it deliver all outgoing messages to you regardless of original recipient.)

Problems:

  • Don't fallaciously assume e-mail is going out successfully just because it is logged by RailMail. Manual testing of e-mails on live server will still be necessary.
  • Does having a message in the RailsMail log mean that it was sent? Apparently, you need to set railmail_settings[:passthrough] = :smtp in order for mail to actually be sent. So maybe it should log the value of passthrough for each logged message so you know if it was actually passed through to SMTP or not.

Conclusion: Seems like overkill to me. Maybe some applications would have more need of e-mail logging, but I probably typically wouldn't.



[edit] Permissions/Security

[edit] ModelSecurity

http://weblog.rubyonrails.com/2005/11/11/why-engines-and-components-are-not-evil-but-distracting McNewby, 2005-11-16 05:50:

However, from an infrastructural perspective, I like the thinking of ModelSecurity – in as much as permissions should at least begin in the Model (and hopefully ripple out to the UI). It should be possible to develop Rails such that permissions can be automatically ‘discovered’, e.g. for every attribute, there’s only three options: no access, read, write. Likewise for each method, there’s only two: can run, can’t run…

[edit] secure-action-plugin

http://rubyfurnace.com/plugins/secure_action_plugin

secure-action-plugin provides an easy to use interface for protecting your app against assumed logged in attacks
Facts about Rails plugins and libraries / Lower-levelRDF feed
Description [Oops! No type defined for attribute]
Personal tools