SlideShare a Scribd company logo
1 of 28
Download to read offline
ACTIVESUPPORT




Sunday, September 12, 2010
WHOAMI




Sunday, September 12, 2010
HOW WE WRITE MODULES




Sunday, September 12, 2010
module M
                              def self.included(base)
                               base.extend, ClassMethods
                               base.send(:include, InstanceMethods)
                               scope :disabled, where(:disabled => true)
                              end

                              module ClassMethods
                               ...
                              end

                              module InstanceMethods
                               ...
                              end
                             end
Sunday, September 12, 2010
previously wrote

                             HOW WE WRITE MODULES




Sunday, September 12, 2010
ACTIVESUPPORT::CONCERN




Sunday, September 12, 2010
module M
                              extend ActiveSupport::Concern

                              included do
                                scope :disabled, where(:disabled => true)
                              end

                              module ClassMethods
                               ...
                              end

                              module InstanceMethods
                               ...
                              end
                             end
Sunday, September 12, 2010
Why use it?




Sunday, September 12, 2010
...it handles dependencies to other
                                            modules!



Sunday, September 12, 2010
module Bar
                              extend ActiveSupport::Concern
                              include Foo

                              included do
                                self.method_injected_by_foo
                              end
                             end

                             class Host
                               include Bar
                             end

Sunday, September 12, 2010
ActiveSupport::Concern in the Wild




Sunday, September 12, 2010
module Mongoid #:nodoc
                              module Indexes #:nodoc
                               extend ActiveSupport::Concern

                               included do
                                 cattr_accessor :index_options
                                 self.index_options = {}
                               end

                               module ClassMethods #:nodoc

                                 # Send the actual index creation comments to the MongoDB driver
                                 def create_indexes
                                     return unless index_options
                                     current_collection = self._collection || set_collection
                                     index_options.each do |name, options|
                                       current_collection.create_index(name, options)
                                     end
                                 end
                                 ...
                               end
                              end
                             end


Sunday, September 12, 2010
PLUGGABLE JSON BACKENDS




Sunday, September 12, 2010
#to_json calls ActiveSupport::JSON.encode()




Sunday, September 12, 2010
Rails used to only have YAML-based JSON support




Sunday, September 12, 2010
ActiveSupport::JSON.backend = 'Yajl'




Sunday, September 12, 2010
YAJL BENCHMARKS
                                Yajl::Encoder#encode: 3.59s
                                      JSON#to_json: 6.2s
                             ActiveSupport::JSON.encode: 45.58s

                                   Yajl::Parser#parse: 4.54s
                                        JSON.parse: 5.47s
                             ActiveSupport::JSON.decode: 64.42s




Sunday, September 12, 2010
PRESENCE




Sunday, September 12, 2010
BEFORE


                             name = params[:name] unless params[:name].blank?




Sunday, September 12, 2010
NOW


                             name = params[:name] if params[: name].present?




Sunday, September 12, 2010
BEFORE

                             state = params[:state] unless params[:state].blank?
                             country = params[:country] unless params[:country].blank?
                             region = state || country || 'US'




Sunday, September 12, 2010
NOW


        region = params[:state].presence || params[:country].presence || 'US'




Sunday, September 12, 2010
ARRAY#UNIQ_BY




Sunday, September 12, 2010
[1, 2, 3, 4].uniq_by(&:odd?)
                                       #=> [1, 2]




Sunday, September 12, 2010
CLASS_ATTRIBUTE




Sunday, September 12, 2010
Declare one or more class-level attribute
                             whose value is inheritable and over-writable by
                                       subclasses and instances




Sunday, September 12, 2010
>> Base.setting = "foo" => "foo"
                             >> Subclass.setting => "foo"
                             >> Subclass.setting = "bar" => "bar"
                             >> Base.setting => "foo"




Sunday, September 12, 2010
QUESTIONS?




Sunday, September 12, 2010

More Related Content

Similar to ActiveSupport

Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Cheng Ta Yeh
 
Dominion Enterprises _H@<k@th0n_
Dominion Enterprises _H@<k@th0n_Dominion Enterprises _H@<k@th0n_
Dominion Enterprises _H@<k@th0n_
Ken Collins
 
Reusable Ruby • Rt 9 Ruby Group • Jun 2012
Reusable Ruby • Rt 9 Ruby Group • Jun 2012Reusable Ruby • Rt 9 Ruby Group • Jun 2012
Reusable Ruby • Rt 9 Ruby Group • Jun 2012
skinandbones
 
Introduction to Twig
Introduction to TwigIntroduction to Twig
Introduction to Twig
markstory
 
Dist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN DistributionsDist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN Distributions
Ricardo Signes
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
Rebecca Murphey
 
Tulsa techfest2010 security
Tulsa techfest2010   securityTulsa techfest2010   security
Tulsa techfest2010 security
Jason Ragsdale
 

Similar to ActiveSupport (20)

07 problem-solving
07 problem-solving07 problem-solving
07 problem-solving
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
 
Intro to Angular.JS Directives
Intro to Angular.JS DirectivesIntro to Angular.JS Directives
Intro to Angular.JS Directives
 
MongoTalk/Voyage
MongoTalk/VoyageMongoTalk/Voyage
MongoTalk/Voyage
 
Dominion Enterprises _H@<k@th0n_
Dominion Enterprises _H@<k@th0n_Dominion Enterprises _H@<k@th0n_
Dominion Enterprises _H@<k@th0n_
 
Reusable Ruby • Rt 9 Ruby Group • Jun 2012
Reusable Ruby • Rt 9 Ruby Group • Jun 2012Reusable Ruby • Rt 9 Ruby Group • Jun 2012
Reusable Ruby • Rt 9 Ruby Group • Jun 2012
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End Optimizations
 
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
Fork cli tool
Fork cli toolFork cli tool
Fork cli tool
 
Introduction to Twig
Introduction to TwigIntroduction to Twig
Introduction to Twig
 
Flex além do browser - Lightning talk qcon
Flex além do browser - Lightning talk qcon Flex além do browser - Lightning talk qcon
Flex além do browser - Lightning talk qcon
 
Progressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancementProgressive Advancement, by way of progressive enhancement
Progressive Advancement, by way of progressive enhancement
 
Dist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN DistributionsDist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN Distributions
 
Cleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQueryCleaner, Leaner, Meaner: Refactoring your jQuery
Cleaner, Leaner, Meaner: Refactoring your jQuery
 
Writing Drupal 5 Module
Writing Drupal 5 ModuleWriting Drupal 5 Module
Writing Drupal 5 Module
 
StORM preview
StORM previewStORM preview
StORM preview
 
Tulsa techfest2010 security
Tulsa techfest2010   securityTulsa techfest2010   security
Tulsa techfest2010 security
 
Pundit
PunditPundit
Pundit
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

ActiveSupport