tag:blogger.com,1999:blog-50772325146587624312024-03-17T00:22:27.420+05:30Acts as ThinkingOpen source enthusiastic. Loves Painting, photography and Music. I work on Ruby on Rails, migrated from Java.shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-5077232514658762431.post-58687035734076491812013-10-10T16:51:00.004+05:302013-11-12T12:57:02.121+05:30Cucumber and Ruby, Introduction<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
I was using RSpec, as my testing framework , as part of my daily Rails development since couple of years. Recently I happened to try Cucumber. In that process I decided to use Cucumber Ruby than Rails.<br />
<br />
<b>Cucumber ?</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ZLhNJN1XGok1y2u8g-3SoIOTk474C1ZaSx8jbvV01IQsrp_CN0uQQlfQdtHA9Gq5_y4B0M4HSwzfDEE90HN9bEIG5_4UkVmfaPJM2KJgdKGgKLml77MSOjzKyQNOcE8gKonDLje4ux0/s1600/cucumbers.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="cucumber image" border="0" height="217" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ZLhNJN1XGok1y2u8g-3SoIOTk474C1ZaSx8jbvV01IQsrp_CN0uQQlfQdtHA9Gq5_y4B0M4HSwzfDEE90HN9bEIG5_4UkVmfaPJM2KJgdKGgKLml77MSOjzKyQNOcE8gKonDLje4ux0/s320/cucumbers.jpg" title="cucumber" width="320" /></a></div>
Lets us look at the exiting business practice.<br />
<br />
Who owns the business ?<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Some one who have an idea.<br />
<br />
Then why do we need software developers or “engineers” ?<br />
<br />
Why can not business people do development as well ? They can express their thoughts in some language, English, Hindi, Spanish etc ...<br />
<br />
Instruction to computer:<br />
“Let there be a Robot that can move in one direction”<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8HpIW9L9RHwIsbSIfIyB21TgDNFHG80fmsS30pDK9sUXfZWOJfcjxyge4ik6ZvIgJSnerRrN1WESg9Ap1fDq0ku3ZSBdQl5wCr5z4OjQx96ZJwOkRT-Kiztssqd8mpWJfj_TU3Y7O5cE/s1600/magician.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="magic cap" border="0" height="151" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8HpIW9L9RHwIsbSIfIyB21TgDNFHG80fmsS30pDK9sUXfZWOJfcjxyge4ik6ZvIgJSnerRrN1WESg9Ap1fDq0ku3ZSBdQl5wCr5z4OjQx96ZJwOkRT-Kiztssqd8mpWJfj_TU3Y7O5cE/s200/magician.jpg" title="Magic" width="200" /></a></div>
<br />
Nothing happens .. Glad that our computers does not produce software based on instructions in spoken languages, yet. (fortunately !).<br />
<br />
As long as this is the case, we the software engineers are safe :)<br />
<br />
<br />
<b>What to expect from Cucumber</b><br />
<br />
<ol style="text-align: left;">
<li>Cucumber lets software development teams describe how software should behave in plain text, spoken languages. </li>
<li>Reduces the gap between business requirement and developed product( Agile to the rescue). </li>
<li>Develop only what is required</li>
<li>Documentation</li>
<li>Acceptance test. Some defined way of proving that developer met the expectation.</li>
</ol>
<br />
<br />
<b>TDD - In general</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLGQl36OvYm4L4Ukw1ZA-9cE473GO2hNFNPf0HcdrOyaPk3Ol6pe-aCpUwb4tzaNe9qRd6M5lCKLn_jMMr0HyJ4ibYy9Q0p8LfjpsKe9F7NW6oLkm-XoNQ7HmFhrjWPWBGcxqGF4JmCPk/s1600/tdd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="TDD-digram" border="0" height="248" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLGQl36OvYm4L4Ukw1ZA-9cE473GO2hNFNPf0HcdrOyaPk3Ol6pe-aCpUwb4tzaNe9qRd6M5lCKLn_jMMr0HyJ4ibYy9Q0p8LfjpsKe9F7NW6oLkm-XoNQ7HmFhrjWPWBGcxqGF4JmCPk/s320/tdd.png" title="TDD" width="320" /></a></div>
<b>Cucumber and TDD</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ucMFQWxwlhI7mhrNhUCs_iYmvNIKURCsr14U_gxSRNjwbWqDleRsknl4BZerc2YiQKXy61L9NxJldrFy4pj_-mi6UqfMKhPZ06DUqeOcd7qxmwkboCMhFt1yC98ckDqat8eC5Vme4Js/s1600/tdd_cucumber.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Cucumber and TDD diagram" border="0" height="230" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ucMFQWxwlhI7mhrNhUCs_iYmvNIKURCsr14U_gxSRNjwbWqDleRsknl4BZerc2YiQKXy61L9NxJldrFy4pj_-mi6UqfMKhPZ06DUqeOcd7qxmwkboCMhFt1yC98ckDqat8eC5Vme4Js/s320/tdd_cucumber.png" title="cucumber and TDD" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: left;">I am not sure if business people would get involved as much I expected here. </span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: left;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<b>Cucumber steps</b></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv_zpwZuqrSxuHqQWwlftKdyTp_NTIVMmPPC3e2JkUdchxVuLGvXLWiC6ULcmUi2FnVxGtqr8stM7Iqy_hlKOfQlPk-kJgCzyZB2Pfx1JSRsHkSkUfWDsV6p8u47Fv6gVJ_b7nXlUpsvw/s1600/cuke_steps.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="cucumber steps - diagram" border="0" height="123" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv_zpwZuqrSxuHqQWwlftKdyTp_NTIVMmPPC3e2JkUdchxVuLGvXLWiC6ULcmUi2FnVxGtqr8stM7Iqy_hlKOfQlPk-kJgCzyZB2Pfx1JSRsHkSkUfWDsV6p8u47Fv6gVJ_b7nXlUpsvw/s320/cuke_steps.png" title="cucumber steps" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<b>How does a feature file look like ?</b><br />
<b><br /></b>
Feature: Serve coffee<br />
In order to earn money<br />
Customers should be able to<br />
buy coffee at all times<br />
<br />
Scenario: Buy last coffee<br />
Given there are 1 coffees left in the machine<br />
And I have deposited 1$<br />
When I press the coffee button<br />
Then I should be served a coffee<br />
Scenario: Buy first coffee<br />
Given there are 10 cofee left<br />
When I press the coffee button<br />
Then I should be served a coffee<br />
<br />
And number of coffee became 9<br />
<b><br /></b>
<br />
<ul style="text-align: left;">
<li>Notice indentation.</li>
<li>A line starting with the keyword Feature followed by free indented text starts a feature. A feature usually contains a list of scenarios. You can write whatever you want up until the first scenario, which starts with Scenario.</li>
<li>Every scenario consists of a list of steps, which must start with one of the keywords Given, When, Then, But or And.</li>
</ul>
<br />
<br />
<b><br /></b>
Cucumber supports over 40 spoken languages and the number is steadily growing.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>A # language: header on the first line of a feature file tells Cucumber what spoken language to use – for example # language: fr for French. If you omit this header, Cucumber will default to English (en).<b><br /></b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQrIfj86TB0HVBjn1AGuAdFHSNA8pt5QI94PC0gSziuS0Q-M_VxgGQxYT-pYYJQJ7K_Y0Y_4ifCOA-wNWyeTlJLyuuFekTz1Ndwx_tEMO6hZexT3dNRPgxjx-3Lh2JCsEGu8bv_7rNxyE/s1600/cuke_languages.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="feature file snapshot" border="0" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQrIfj86TB0HVBjn1AGuAdFHSNA8pt5QI94PC0gSziuS0Q-M_VxgGQxYT-pYYJQJ7K_Y0Y_4ifCOA-wNWyeTlJLyuuFekTz1Ndwx_tEMO6hZexT3dNRPgxjx-3Lh2JCsEGu8bv_7rNxyE/s320/cuke_languages.png" title="feature file" width="320" /></a></div>
<br />
<br />
<b>Gherkin</b><br />
<b><br /></b>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga76lLDPgqKJAQTer5T-duW7GntCDcgdQFERdbBxdtPxd_gpQFvaRUqaOKKYwgsIUAXQRHDPyqU3teHHYTgKvoFss5-AGCOoKObGFYDbdRex7mvVMytWV6-f4WAUSeWl76lqKhUA1v4DY/s1600/gherkin.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Gherkin" border="0" height="149" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga76lLDPgqKJAQTer5T-duW7GntCDcgdQFERdbBxdtPxd_gpQFvaRUqaOKKYwgsIUAXQRHDPyqU3teHHYTgKvoFss5-AGCOoKObGFYDbdRex7mvVMytWV6-f4WAUSeWl76lqKhUA1v4DY/s200/gherkin.jpeg" title="gherkin" width="200" /></a></div>
<b><br /></b>
<b><br /></b>
Cucumber lets software development teams describe how software should behave in plain text.<br />
The text is written in a business-readable domain-specific language -<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>The language that Cucumber understands is called Gherkin -<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Gherkin is the language that Cucumber understands.<br />
It is a Business Readable, Domain Specific Language that lets you describe software’s behavior<br />
without detailing how that behavior is implemented.()<br />
<br />
Gherkin’s grammar is defined in the Treetop grammar<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Single Gherkin source file contains a description of a single feature.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Source files have .feature extension.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Like Python and YAML, Gherkin is a line-oriented language that uses indentation to define structure.<br />
Line endings terminate statements (eg, steps). <span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
Either spaces or tabs may be used for indentation (but spaces are more portable). Most lines start with a keyword.<br />
<br />
<br />
<b>Example</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz9qxCbvTTjuOJjgCX7atirp281TotjAuYW2bBaJ5t0YEFKr0GufQBsSFGoBvOFiZYefwyDmeorNi7vTE2L4oVS_BYL_UlBDmVPmSNxGEgz_82e7D7vFARfR69CPVdeWyCFargmJDhQrE/s1600/robot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Robot " border="0" height="121" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz9qxCbvTTjuOJjgCX7atirp281TotjAuYW2bBaJ5t0YEFKr0GufQBsSFGoBvOFiZYefwyDmeorNi7vTE2L4oVS_BYL_UlBDmVPmSNxGEgz_82e7D7vFARfR69CPVdeWyCFargmJDhQrE/s320/robot.png" title="robot" width="320" /></a></div>
<b><br /></b>
<br />
<div style="text-align: center;">
Moving robot, but only in one direction.</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
Accept 2 params, step and direction</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
Ex: 'F', 10 OR 'B', 20</div>
<div style="text-align: center;">
<br /></div>
<br />
<div style="text-align: center;">
Moves either forward or back ward, Initially at the center (0).</div>
<div style="text-align: center;">
<br /></div>
<div>
<div>
<b><br /></b></div>
<div>
<b>Installing cucumber</b></div>
<div>
<b>1.</b></div>
<div>
$ gem install cucumber</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Building native extensions. This could take a while...</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Successfully installed builder-3.2.2</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Successfully installed diff-lcs-1.2.4</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Successfully installed multi_json-1.8.0</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Successfully installed gherkin-2.12.1</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Successfully installed multi_test-0.0.2</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>Successfully installed cucumber-1.3.8</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>6 gems installed</div>
<div>
<br /></div>
<div>
<b>2.</b></div>
<div>
$cucumber</div>
<div>
No such file or directory - features. Please create a features directory to get started. (Errno::ENOENT)</div>
<div>
<b><br /></b></div>
<div>
<b>3.</b></div>
<div>
Create directory and then create '<b>features/robot.feature'</b></div>
<div>
<div style="text-align: left;">
<div>
<i>Feature: Robot in Motion</i></div>
<div>
<i> In order to move my robot</i></div>
<div>
<i> As an owner</i></div>
<div>
<i> I want the ability to create and move based on instructions</i></div>
<div>
<i> Scenario: Create a robot</i></div>
<div>
<i> Given Robot created</i></div>
<div>
<i> When I check the position</i></div>
<div>
<i> Then Robot should be at 0</i></div>
<div>
<i> Scenario: Move forward</i></div>
<div>
<i> Given Robot is at 0</i></div>
<div>
<i> When I enter 'F', 10</i></div>
<div>
<i> And I check the position</i></div>
<div>
<i> Then Robot should be at 10</i></div>
</div>
</div>
<div style="text-align: left;">
<b><br /></b></div>
<div style="text-align: left;">
<b>4.</b></div>
<div style="text-align: left;">
Run again and see it fails.</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<b>5.</b></div>
<div style="text-align: left;">
Now create '<b>features/step_definitions/robot_steps.rb</b>' as</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<div>
<i>require 'robot'</i></div>
<div>
<i><br /></i></div>
<div>
<i>Given(/^Robot created$/) do</i></div>
<div>
<i> @robot = Robot.new</i></div>
<div>
<i> # pending # express the regexp above with the code you wish you had</i></div>
<div>
<i>end</i></div>
<div>
<i><br /></i></div>
<div>
<i>When(/^I check the position$/) do</i></div>
<div>
<i> @position = @robot.position</i></div>
<div>
<i> # pending # express the regexp above with the code you wish you had</i></div>
<div>
<i>end</i></div>
<div>
<i><br /></i></div>
<div>
<i>Then(/^Robot should be at (\d+)$/) do |arg1|</i></div>
<div>
<i> @position.should == arg1.to_i</i></div>
<div>
<i> # pending # express the regexp above with the code you wish you had</i></div>
<div>
<i>end</i></div>
<div>
<i><br /></i></div>
<div>
<i>Given(/^Robot is at (\d+)$/) do |arg1|</i></div>
<div>
<i> @robot = Robot.new</i></div>
<div>
<i> # pending # express the regexp above with the code you wish you had</i></div>
<div>
<i>end</i></div>
<div>
<i><br /></i></div>
<div>
<i>When(/^I enter 'F', (\d+)$/) do |arg1|</i></div>
<div>
<i> @robot.move('F', arg1.to_i)</i></div>
<div>
<i> # pending # express the regexp above with the code you wish you had</i></div>
<div>
<i>end</i></div>
</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<b>6. </b>This will again fail, create the actual robot class now - $ <i>robot.rb</i></div>
<div style="text-align: left;">
<div>
<i><br /></i></div>
<div>
<i>class Robot</i></div>
<div>
<i> attr_accessor :location</i></div>
<div>
<i><br /></i></div>
<div>
<i> def initialize</i></div>
<div>
<i> @location = 0</i></div>
<div>
<i> end</i></div>
<div>
<i><br /></i></div>
<div>
<i> def move(dir, step)</i></div>
<div>
<i> if dir=='F'</i></div>
<div>
<i> @location = @location + step</i></div>
<div>
<i> elsif dir=='B'</i></div>
<div>
<i> @location = @location - step</i></div>
<div>
<i> end</i></div>
<div>
<i> end</i></div>
<div>
<i><br /></i></div>
<div>
<i> def position</i></div>
<div>
<i> @location</i></div>
<div>
<i> end</i></div>
<div>
<i>end</i></div>
<div>
<br /></div>
</div>
<div style="text-align: left;">
<b> 7. </b>$cucumber -f html > report.html </div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
This gives you some level of documentation, something like ...</div>
</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjrXt7oRKxrB-qKH1AHawzRWiPaN37JDG_TIb4-3VjJ1Ludh8lzxl0NjA8DK3HzTo8TvIel7Mmsu6BqUXIrJb2aEzdFpldWWRjxNZUcoWQpwqmIB5JMn8vLrmMr0LZMjeKWwp2y4KPhUg/s1600/sample-report.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="cucumber report" border="0" height="150" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjrXt7oRKxrB-qKH1AHawzRWiPaN37JDG_TIb4-3VjJ1Ludh8lzxl0NjA8DK3HzTo8TvIel7Mmsu6BqUXIrJb2aEzdFpldWWRjxNZUcoWQpwqmIB5JMn8vLrmMr0LZMjeKWwp2y4KPhUg/s400/sample-report.png" title="cucumber report" width="400" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<b>Ref</b><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>http://cukes.info/<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>https://github.com/cucumber/cucumber/wiki<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>https://github.com/cucumber/cucumber/wiki/Given-When-Then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br /></div>
shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com1tag:blogger.com,1999:blog-5077232514658762431.post-66060305088786821862013-09-04T17:45:00.000+05:302013-11-12T12:57:46.961+05:30Installing and configuring Ruby and Rails in Ubuntu 13.04 . Addressing issues with libxml2, nokogiri<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-size: small;">After upgrading Ubuntu to 13.04(Raring Ringtail), I started having problems with bundle install and starting server, main concern was libxml2. </span><br />
<br />
<span style="font-size: small;">I managed to solve the issue using 'rvm pkg' and 'build.config'. Finally I thought of writing those steps used. The entire steps of installing rvm, ruby, libraries with some notes about the issues with lixml2.</span><br />
<br />
<h3 style="text-align: left;">
<span style="font-size: large;">Libraries required:</span></h3>
<br />
Assuming that user has an UBUNTU machine.<br />
<br />
Install below given libraries. ex: $sudo apt-get install curl. Multiple libraries can be installed separated by spaces. You can skip those libraries that are not required. Below given list has most of the common libraries required. <br />
<br />
<i><span style="font-family: Georgia,"Times New Roman",serif;">$sudo apt-get install curl build-essential openssl libreadline6 libreadline6-dev
curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev
sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake
libtool bison</span></i><br />
<i><span style="font-family: Georgia,"Times New Roman",serif;">mysql-server mysql-client libmysqlclient-dev libxml2-dev libxslt-dev imagemagick</span></i><br />
<br />
<i><span style="font-family: Georgia,"Times New Roman",serif;">$ sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev(required for curb)</span></i><br />
<br />
<i><span style="font-family: Georgia,"Times New Roman",serif;">$ sudo apt-get install graphicsmagick-libmagick-dev-compat (required for RMagick, libmagick9-dev doesn not exists any more)</span></i><br />
<br />
<i><span style="font-family: Georgia,"Times New Roman",serif;">$ sudo apt-get install libmagickcore-dev libmagickwand-dev (If you get ' wand/MAgickWand.h missing' error)</span></i><br />
<br />
<h3 style="text-align: left;">
<i><span style="font-family: Georgia,"Times New Roman",serif;"> </span></i><span style="font-family: Georgia,"Times New Roman",serif;">Installing RVM(https://rvm.io/rvm/install)</span></h3>
<br />
<div style="text-align: left;">
<span style="font-size: large;"><b><span style="font-family: Georgia,"Times New Roman",serif;"><span style="font-weight: normal;"> </span></span></b></span>$ \curl -L https://get.rvm.io | bash -s stable</div>
<br />
Folow instructions if any. I had instructions to add "source ~./profile" in to '~/home/shilesh/.bash_profile'<br />
<br />
# making sure that it is loaded for the current instance also<br />
$source ~/.profile<br />
<br />
Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command:<br />
<br />
user$ source ~/.rvm/scripts/rvm<br />
If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output 'rvm is a function' as shown below.<br />
<br />
user$ type rvm | head -n 1<br />
rvm is a function<br />
<br />
<h3 style="text-align: left;">
</h3>
<h3 style="text-align: left;">
Installing ruby</h3>
$ rvm list known #This will show the available ruby options.<br />
<br />
$ rvm install 1.8.7 # This will install Ruby 1.8.7<br />
<br />
$ rvm use 1.8.7<br />
<br />
$ rvm --default 1.8.7 # makes 1.8.7 as default ruby version.<br />
<br />
$ ruby -v # should give you something like ruby 1.8.7<br />
<h2 style="text-align: left;">
</h2>
<h3 style="text-align: left;">
Source code from Git or ?.</h3>
<br />
You are expected to have ssh keys in .ssh folder of your profile (ex: /home/shilesh/.ssh/id_rsa. And it should have 066 permissions).<br />
<br />
$ git clone git@github.com:<project>/<name>.git<br />
# using https will promt for user name and password for each pull and push.<br />
<br />
$ git checkout <some_branch> # move to development branch, if not master.<br />
<br />
# Edit the values in database.yml with your local mysql server details. If you do not have server ready, update yml file with a user name and password which you will give to the server.<br />
<br />
<h3 style="text-align: left;">
Installing Gems using bundler </h3>
Install ruby gems from "http://rubygems.org/pages/download" and install. <br />
$gem -v # This might give you 2.0.6 or greater.<br />
<br />
If you did not get the correct version to download, use<br />
$ gem update --system 1.3.7 # This will update the gem to 1.3.7 version<br />
$ gem install bundler # Installing Bundler gem<br />
<br />
We are ready to install all the gems, this might take some time based on your gems.<br />
$bundle install --local<br />
<br />
<h2 style="text-align: left;">
</h2>
<h3 style="text-align: left;">
Database</h3>
<br />
$ bundle exec rake db:create # This will create database for development<br />
<br />
$bundle exec rake db:migrate # Creates schema<br />
<br />
$bundle exec rake db:seed # Load default values.<br />
<br />
<h3 style="text-align: left;">
<b>Server </b></h3>
<br />
$ bundle exec script/server # Your server should be up now on 3000 port.<br />
<br />
<h3 style="text-align: left;">
</h3>
<h3 style="text-align: left;">
Errors: </h3>
<div style="text-align: left;">
<h4 style="text-align: left;">
Failed undefined method "source index for module"</h4>
</div>
reason could be wrong version of gem. <br />
$ gem update --system <br />
# gem install rubygems-update -v 1.3.7<br />
<h4 style="text-align: left;">
</h4>
<h4 style="text-align: left;">
There were cases where installing libxml-ruby fails as,</h4>
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">Installing libxml-ruby (1.1.3)<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.</span><br />
<br style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;" />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">/home/shilesh/.rvm/rubies/ruby-1.8.7-p374/bin/ruby extconf.rb<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for socket() in -lsocket... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for gethostbyname() in -lnsl... yes</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for atan() in -lm... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for atan() in -lm... yes</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for inflate() in -lz... yes</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for iconv_open() in -liconv... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for libiconv_open() in -liconv... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for libiconv_open() in -llibiconv... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for iconv_open() in -llibiconv... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for iconv_open() in -lc... yes</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for xmlParseDoc() in -lxml2... yes</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for libxml/xmlversion.h... no</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">checking for libxml/xmlversion.h in /home/shilesh/.rvm/rubies/ruby-1.8.7-p374/include,/home/shilesh/.rvm/rubies/ruby-1.8.7-p374/include/libxml2,/opt/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... yes</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">creating extconf.h</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">creating Makefile</span><br />
<br />
<h4 style="text-align: left;">
And then, even after bundler successfully installed all gems, server might fail as,</h4>
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">$ bundle exec script/server<span class="Apple-converted-space"> </span></span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">=> Booting WEBrick</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">=> Rails 2.3.17 application starting on http://0.0.0.0:3000</span><br />
<span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">/home/shilesh/.rvm/gems/ruby-1.8.7-p374@izone-1.8.7/gems/nokogiri-1.5.6/lib/nokogiri/nokogiri.so: /usr/lib/i386-linux-gnu/libxslt.so.1: symbol<b> xmlBufUse, version LIBXML2_2.9.</b>0 not defined in file libxml2.so.2 with link time reference - /home/shilesh/.rvm/gems/ruby-1.8.7-p374@izone-1.8.7/gems/nokogiri-1.5.6/lib/nokogiri/<b>nokogiri.so (LoadError)</b></span><b><br style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;" /></b><span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"><b>from /home/shilesh/.rvm/gems/ruby-1.8.7-p374@izone-1.8.7/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require</b>' </span><br />
<br />
In that case, try to specify the library after getting them with in rvm.<br />
<br />
<b><span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">$ rvm pkg install libxml2 --verify-downloads 1</span></b><br />
<b><span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;"> </span><br style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;" /><br style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;" /><span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">$ bundle config build.libxml-ruby --with-xml2-lib=${HOME}/.rvm/usr/lib --with-xml2-include=${HOME}/.rvm/usr/include/libxml2</span><br style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;" /><br style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;" /><span style="-webkit-text-stroke-width: 0px; background-color: #cccccc; color: #666666; display: inline !important; float: none; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">$ bundle config build.nokogiri --with-xml2-lib=${HOME}/.rvm/usr/lib --with-xml2-include=${HOME}/.rvm/usr/include/libxml2</span></b><br />
<br />
Then it is better to re-install all the gems using bundler. I deleted my gemset and created this again. After that installed bundler gem. Did the configurations as mentioned above, then ran bundler.<br />
<br />
Everything was working fine then.<br />
<br />
<br />
<br />
<br /></div>
shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com8tag:blogger.com,1999:blog-5077232514658762431.post-3646555972300250222013-05-03T15:07:00.003+05:302013-05-03T15:07:30.056+05:30RMagick gem and UBUNTU 13.04<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
I recently upgraded my OS from Ubuntu 12.04 ro 13.04, Since then my 'rmagick' gem was not working. I used to get below error while starting my rails server ;<br />
<br />
<blockquote class="tr_bq">
<span style="font-size: x-small;">libMagickCore.so.4: cannot open shared object file: No such file or directory - /home/shilesh/.rvm/gems/ruby-1.8.7-p352@rails_2.3.16/gems/rmagick-2.12.2/lib/RMagick2.so (LoadError) </span></blockquote>
<br />
Installing gem using bundler used to give below error;<br />
<br />
<blockquote class="tr_bq">
<i><span style="font-size: x-small;">$ gem install rmagick</span></i><i><span style="font-size: x-small;">Building native extensions. This could take a while...</span></i><i><span style="font-size: x-small;">ERROR: Error installing rmagick:</span></i><i><span style="font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ERROR: Failed to build gem native extension.</span></i><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;"> /home/shilesh/.rvm/rubies/ruby-1.8.7-p352/bin/ruby extconf.rb</span></i><i><span style="font-size: x-small;">checking for Ruby version >= 1.8.5... yes</span></i><i><span style="font-size: x-small;">checking for gcc... yes</span></i><i><span style="font-size: x-small;">checking for Magick-config... yes</span></i><i><span style="font-size: x-small;">checking for ImageMagick version >= 6.4.9... yes</span></i><i><span style="font-size: x-small;">checking for HDRI disabled version of ImageMagick... yes</span></i><i><span style="font-size: x-small;">checking for stdint.h... yes</span></i><i><span style="font-size: x-small;">checking for sys/types.h... yes</span></i><i><span style="font-size: x-small;">checking for wand/MagickWand.h... no</span></i><i><span style="font-size: x-small;"><br /></span></i><i><span style="font-size: x-small;">Can't install RMagick 2.13.2. Can't find MagickWand.h.</span></i><i><span style="font-size: x-small;">*** extconf.rb failed ***</span></i><i><span style="font-size: x-small;">Could not create Makefile due to some reason, probably lack of</span></i><i><span style="font-size: x-small;">necessary libraries and/or headers. Check the mkmf.log file for more</span></i><i><span style="font-size: x-small;">details. You may need configuration options</span></i></blockquote>
<br />
Finally I re-installed ImageMagick and RMagick gem as given below, that worked,finally.<br />
<br />
<b>$ sudo apt-get install imagemagick</b><br />
<br />
<b>$sudo apt-get install libmagickwand-dev</b><br />
<b><br /></b>
<br />
<b>$ gem install rmagick</b><br />
<blockquote class="tr_bq">
Building native extensions. This could take a while...<br />Successfully installed rmagick-2.13.2<br />1 gem installed<br />Installing ri documentation for rmagick-2.13.2...<br />Installing RDoc documentation for rmagick-2.13.2..</blockquote>
</div>
shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-43310631606395028262012-03-08T12:36:00.000+05:302012-03-08T12:36:12.877+05:30deploy rails with different user roles.<div dir="ltr" style="text-align: left;" trbidi="on">
Using capistrano we can set the user running the application different from the user owning the files and folder of the application.<br />
<br />
<br />
<blockquote>
deploy.rb </blockquote>
<blockquote>
set :app_runtime_user, "123"<br />
set :app_runtime_group, "123group"<br />
<br />
set :user, "abc"<br />
<br />
</blockquote>
"abc" will own the folders and "123" will run the application.</div>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-91234825663266892712011-09-16T14:27:00.000+05:302011-09-16T14:28:00.425+05:30Scope of block variables in Ruby 1.8 and 1.9<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
There is a difference in the scope of the variables in blocks w.e.f ruby 1.8 and 1.9 I have pasted en example to high light the change. It created trouble when I moved my application from 1.8 to 1.9 <br />
<br />
<div style="background-color: white;">
<br /></div>
<div style="background-color: white;">
<span style="color: #674ea7;">a = 1</span><br style="color: #674ea7;" /><span style="color: #674ea7;">b = 2</span><br style="color: #674ea7;" /><span style="color: #674ea7;">r = 0</span><br style="color: #674ea7;" /><span style="color: #674ea7;">n =0</span><br style="color: #674ea7;" /><br style="color: #674ea7;" /><span style="color: #674ea7;">(0..10).each do |n|</span><br style="color: #674ea7;" /><span style="color: #674ea7;"> a = n</span><br style="color: #674ea7;" /><span style="color: #674ea7;"> r = r + n</span><br style="color: #674ea7;" /><span style="color: #674ea7;">end</span><br style="color: #674ea7;" /><br style="color: #674ea7;" /><span style="color: #674ea7;">puts "a = #{a} ; b = #{b} ; r = #{r} ; n = #{n}" </span></div>
<div style="background-color: white; color: #cc0000;">
<br /></div>
<div style="color: #cc0000;">
<br /></div>
<div style="color: #cc0000;">
<b><u>ruby 1.8.7</u></b></div>
<div style="color: #cc0000;">
a = 10 ; b = 2 ; r = 55 ; <b>n = 10</b></div>
<br />
<div style="color: #38761d;">
<b><u>ruby 1.9.2</u></b></div>
<span style="color: #38761d;"> a = 10 ; b = 2 ; r = 55 ; <b>n = 0</b></span><br /><br />
<br />
<br />
<br />
<br /></div>
shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-19695102680980945142011-09-08T12:06:00.000+05:302013-05-08T15:00:27.276+05:30Postfix on Ubuntu, send mail using telnet.<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
Post fix is said to be better than send mail as I read from many sources.<br />
<br />
"sudo aptitude install postfix" Installed postfix for me. Give various details when prompted for.<br />
"/etc/postfix/main.cf" Has all the config details.<br />
<br />
#sudo postfix start -> starts post fix if not already running.<br />
<br />
#telnet localhost 25<br />
<br />
<span class="Apple-style-span" style="background-color: white; font-family: 'Helvetica Neue', 'Lucida Grande', Helvetica, Arial, Verdana, sans-serif; font-size: 14px;"></span><br />
<pre style="background-color: #f0eee6; border-bottom-color: rgb(193, 180, 150); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(193, 180, 150); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(193, 180, 150); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(193, 180, 150); border-top-style: dashed; border-top-width: 1px; font-family: courier, monospace; padding-bottom: 4pt; padding-left: 4pt; padding-right: 4pt; padding-top: 4pt; white-space: pre-wrap; word-wrap: break-word;">ehlo localhost
<span class="anchor" id="line-2-2"></span>mail from: user@localhost
<span class="anchor" id="line-3-1"></span>rcpt to: someone@localhost
<span class="anchor" id="line-4-1"></span>data
<span class="anchor" id="line-5"></span>Subject: my subject
<span class="anchor" id="line-6"></span>
<span class="anchor" id="line-7"></span>Hi,
<span class="anchor" id="line-8"></span> How are you?
<span class="anchor" id="line-9"></span>regards,
<span class="anchor" id="line-10"></span>Admin
<span class="anchor" id="line-11"></span>. (Type the .[dot] in a new Line and press Enter )
<span class="anchor" id="line-12"></span>quit</pre>
<pre style="background-color: #f0eee6; border-bottom-color: rgb(193, 180, 150); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(193, 180, 150); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(193, 180, 150); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(193, 180, 150); border-top-style: dashed; border-top-width: 1px; font-family: courier, monospace; padding-bottom: 4pt; padding-left: 4pt; padding-right: 4pt; padding-top: 4pt; white-space: pre-wrap; word-wrap: break-word;"></pre>
<pre style="background-color: #f0eee6; border-bottom-color: rgb(193, 180, 150); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(193, 180, 150); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(193, 180, 150); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(193, 180, 150); border-top-style: dashed; border-top-width: 1px; font-family: courier, monospace; padding-bottom: 4pt; padding-left: 4pt; padding-right: 4pt; padding-top: 4pt; white-space: pre-wrap; word-wrap: break-word;">#mailq will show you the mails to be delivered.</pre>
</div>
shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com2tag:blogger.com,1999:blog-5077232514658762431.post-78534837069985620902011-06-13T18:51:00.000+05:302013-11-12T12:53:16.202+05:30Rack on Rails and Custom webserver<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmn-fEa2Sp6sKQdvQtZkzUjiOLtmY-fk70dt1WzbiZetEwC0DJo9Vm5-F4plSGAwejsgOyfulT2-hxMKdMamtklDKKwTpotN9zgLyT2A4RPCpEJHBTym5QFz8VTts2Mh86ETRPwSK8QCwA/s1600/RoR-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<br />
<div style="text-align: center;">
Rails on Rack</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
What would be interesting</div>
<ul style="text-align: left;">
<li>Where does Rack fit in web framework</li>
<li>How to install</li>
<li>Build our own framework</li>
<li>Use our middle ware in Rails.</li>
</ul>
Rack is an interface for Ruby webserver. It provides a minimal interface between webservers supporting Ruby and Ruby frameworks.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpgu4M7zfmUAmfcxZonoa-2fQpeOrB1jVv2a0t67qEwY0g_f_9lsrHT4wMDumJ6ZCE_nGCi8EBq4H_tx9GgLvacaW0pjRxLYL18DkWd-YWiZXDE-XwjBDZwZaZ4OxiB6PDLfIkhtB3Wvdb/s1600/ror8.png" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
Rack
provides an interface between different web servers and your
application, Making it very simple for your application to be compatible
with any web server that supports Rack - Passenger, Litespeed, Mongrel,
Thin, Ebb, Webrick etc ...<br />
<br />
It is also possible to use multiple frameworks in a single application. Rails and Sinatra integration is a good example.<br />
<br />
Think of Middle ware as a Rails before_filter/after_filter that are reusable across different rack supported frameworks. Ex: We can use the same 'anti_spamming' middle ware for our Rails app, Sinatra app etc ..<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggr6A7WWXrEeJzsfNgoauIyupBG_R_kQQcCx1Uh0yyuzmrWNyZxJwSMCFO69u3lFgv8Ybbrs3ns6NxAM5B50FoGCSCzGG1Atdb2EWuTJ4_0vwLQhoFT2-Qks2j23eUDyj6rIb5gvPTJH6Z/s1600/ror4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Rack handlers" border="0" height="401" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggr6A7WWXrEeJzsfNgoauIyupBG_R_kQQcCx1Uh0yyuzmrWNyZxJwSMCFO69u3lFgv8Ybbrs3ns6NxAM5B50FoGCSCzGG1Atdb2EWuTJ4_0vwLQhoFT2-Qks2j23eUDyj6rIb5gvPTJH6Z/s640/ror4.png" title="Rack handlers" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_f-iYZHW4_bXcX94aP8M0ygFDbHjDvHGLEGFl_ytw1F-PFwRmWzhv_IKGRVAOniotpRDRDcbQy0lCu2M-RIyaj81NEsJxJqbwFZWSNUagNTJAPkhQaCw9bVLcKEyk2x5PvL3Pk2Nlzrs_/s1600/ror5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Rack in our web frame work" border="0" height="432" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_f-iYZHW4_bXcX94aP8M0ygFDbHjDvHGLEGFl_ytw1F-PFwRmWzhv_IKGRVAOniotpRDRDcbQy0lCu2M-RIyaj81NEsJxJqbwFZWSNUagNTJAPkhQaCw9bVLcKEyk2x5PvL3Pk2Nlzrs_/s640/ror5.png" title="Rack in our web frame work" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRnTWtg1hUtEh1pIgjKTwrbrYvtfjCC-CjzwQaU4PxOrnNDkzRiX-FXh9yOk3Iw84w-hEiypTmSYLU10_0Tjs5gwtN4UZe9hyphenhyphenjrbEQwJ2QaH5BtBy_H7JP6Gnkjnktv4NrGxiNM6IpAEFG/s1600/ror6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<br />
Installation<br />
<ul style="text-align: left;">
<li>gem install rack</li>
<li>Require 'rack' for further usage</li>
<li>"rake middle ware" gives you the list of classes/modules usable as middle ware in our application</li>
</ul>
Rack specification<br />
<br />
A Rack application is a Ruby object(not a class) that responds to call. It takes exactly one argument, the environment, and returns an Array of exactly three values: The status, the headers and the body.<br />
<br />
class HelloWorld<br />
<br />
def call(env)<br />
[200, {"Content-Type" => "text/html" }, "Hello Rack !"]<br />
end<br />
<br />
end<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
sample Rack environment is pasted here</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3JLcNsYczz4dxL74hGeyI25QTCt5TTs0kjA5dlnLahBS6xNpECCWi3CwsFNuEwZjfCX88H4-FgQY7PLiUEs_nQj-CvTtLmtZGi63AFW10KJImX7PkW2A5iPLy3_3-1CAoF73SMqalL2g/s1600/ror-rack-env.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="sample Rack environment" border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3JLcNsYczz4dxL74hGeyI25QTCt5TTs0kjA5dlnLahBS6xNpECCWi3CwsFNuEwZjfCX88H4-FgQY7PLiUEs_nQj-CvTtLmtZGi63AFW10KJImX7PkW2A5iPLy3_3-1CAoF73SMqalL2g/s640/ror-rack-env.png" title="sample Rack environment" width="640" /></a></div>
<br />
<br />
We will have another syntax to bring a Rack server up and running, Using various handlers.<br />
<br />
<blockquote class="tr_bq">
require 'rubygems' <br />
require 'rack'<br />
<br />
<i>Rack::Handler::WEBrick.run proc{|env| [200, {"Content-Type" => "text/html"}, "Hello Rack"]}, :Port => 9292</i><br />
...<br />
...<br />
<i>INFO WEBrick::HTTPServer#start: pid=4557 port=19292</i><br />
<br />
Now the server is running on 19292 port and 'http://localhost:19292/' gives "Hello Rack"</blockquote>
<br />
Some of the other Rack handlers are listed below,<br />
<ul style="text-align: left;">
<li>Rack::Handler::CGI</li>
<li>Rack::Handler::EventedMongrel</li>
<li>Rack::Handler::FastCGI</li>
<li>Rack::Handler::LSWS</li>
<li>Rack::Handler::Mongrel</li>
<li>Rack::Handler::SCGI</li>
<li>Rack::Handler::WEBrick</li>
<li>Rack::Handler::Thin </li>
</ul>
<br />
Custom middle ware for Rails<br />
<br />
Use an existing rails application or create a new one.<br />
$ rackup #will bring up the rack server. This depends on the values in config.ru file in RAILS_ROOT.<br />
<br />
# config.ru<br />
rub Proc.new {|env| [200, {"Content-Type" => ""text/html"}, "Hello Rack!"]}<br />
<br />
#environment.rb<br />
config.middleware.use(new_middleware, args) # adds a new middle ware at the end of middle ware stack.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpgu4M7zfmUAmfcxZonoa-2fQpeOrB1jVv2a0t67qEwY0g_f_9lsrHT4wMDumJ6ZCE_nGCi8EBq4H_tx9GgLvacaW0pjRxLYL18DkWd-YWiZXDE-XwjBDZwZaZ4OxiB6PDLfIkhtB3Wvdb/s1600/ror8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<br />
Example :<br />
Adding a middle ware to an existing Rails application. This filter redirects page to 'google' if the requested resource is not present with in rails app.<br />
<br />
<span style="color: #674ea7;">my_rack_middle_ware.rb</span><br />
<blockquote class="tr_bq">
<span style="color: #674ea7;">require 'rubygems'<br />require 'rack'<br /><br />class MyRackMiddleWare<br /> def initialize(app)<br /> @app = app<br /> end<br /><br /> def call(env)<br /> <span style="color: black;">#executes the request using Rails app</span><br /> status, headers, body = @app.call(env)<br /> if status == 404<br /> [301, {"Location" => 'http://www.google.com'}, 'redirecting to google as the requested resource is not available']<br /> else<br /> [status, headers, body]<br /> end<br /> end <br />end </span></blockquote>
Add middle ware details in the 'environment.rb'<br />
<span style="color: #674ea7;"> config.middleware.use(MyRackMiddleWare) # Make sure to require the file. </span><br />
<br />
<span style="color: #674ea7;"> </span>Run the application and try for an invalid page in the URL, the page should get redirected to google.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOyXkcovs3qOuCfTf80PzH_eqOWStnMrbaHyYf6oReC02wdJu0ht7bsDFWR-wWgsF4bK29SyOdm9Zkx65Oi_sg1RvLjy0FHoaHucAE_IxdvNyQACipoOiEaQSxzRAW0Bcxfr2GWFeumnfs/s1600/ror11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOyXkcovs3qOuCfTf80PzH_eqOWStnMrbaHyYf6oReC02wdJu0ht7bsDFWR-wWgsF4bK29SyOdm9Zkx65Oi_sg1RvLjy0FHoaHucAE_IxdvNyQACipoOiEaQSxzRAW0Bcxfr2GWFeumnfs/s1600/ror11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOyXkcovs3qOuCfTf80PzH_eqOWStnMrbaHyYf6oReC02wdJu0ht7bsDFWR-wWgsF4bK29SyOdm9Zkx65Oi_sg1RvLjy0FHoaHucAE_IxdvNyQACipoOiEaQSxzRAW0Bcxfr2GWFeumnfs/s1600/ror11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOyXkcovs3qOuCfTf80PzH_eqOWStnMrbaHyYf6oReC02wdJu0ht7bsDFWR-wWgsF4bK29SyOdm9Zkx65Oi_sg1RvLjy0FHoaHucAE_IxdvNyQACipoOiEaQSxzRAW0Bcxfr2GWFeumnfs/s1600/ror11.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvwUfIVNuuUVmT8qNhf-Gkx-ngqX0asXDDJ8EB-RW4DG6BWD5tSexh_fh20szUxR25w-Y8SGZKhA6yWbkkjaGw7aEu_H3HeBswDo2JGeqOm7CkajWUUPoAsyoJllxBspJS5LFjuXxaxV_c/s1600/ror12.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7SymynH4cTkfr_Thd-WxRWXNdV3yZqzNjduhj8R9rBjM8Marn4cqMEmvIfxNFnIjs40LO8GTNn1yE1fuVTcwthALRHIEoQPUbcTYx_xVSm6XSC90y8cptTepn2SqkpkKN9Phc6305UWD8/s1600/ror14.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
<br /></div>
shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com1tag:blogger.com,1999:blog-5077232514658762431.post-77935651118186625282011-06-03T12:50:00.000+05:302011-06-15T15:49:36.250+05:30rails - bundle exec<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;"><br /></span></span><br /><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;">"It’s worth noting that typing in<span class="Apple-converted-space"> </span><code>rake foo</code><span class="Apple-converted-space"> </span>(or<span class="Apple-converted-space"> </span><code>anyexecutable foo</code>) in the presence of a<code>Gemfile.lock</code>, and expecting it to execute in the bundler sandbox doesn’t make any sense" - Yahuda</span></span><br /><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;"><br /></span></span><br /><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;">Ex: "rake middleware" should be replaced as "bundle exec rake middleware"</span></span><br /><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;"><br /></span></span><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;"> </span></span><br /><span class="Apple-style-span" style="border-collapse: separate; color: black; font-family: 'Times New Roman'; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="font-family: Arial,sans-serif; font-size: 14px; line-height: 20px;"><br /></span></span></div>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-10101350047130350612011-05-25T15:38:00.000+05:302011-06-15T15:49:36.250+05:30Testing your email notifications with MailCatcher.<div dir="ltr" style="text-align: left;" trbidi="on"> Often its hard to test email notifications sent from our application. MailCatcher is a gem which helps you to check those mails sent from your application.<br />Install the gem as '<code>gem install mailcatcher</code>' and run 'mailcatcher' on your console. This will start two servers. One smtp server(on 1025 port), use this server to sent mails. Another server, web server, helps us to view the 'sent' email on our browser '<a href="http://localhost:1080/">http://localhost:1080/</a>'. I tested it on Chrome 5.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9ov3dG2YA6rLzNSW7lF0yAnWqfoPbFK1OyzP93d-OlFZkuJij8mdDV6wcPsi-2mj_BoAWWxzSYqf5hPv-92jQT5BHy9p6YnN2q3G5eV2Pn8TFPuxhVzn7XyKC4h-W04u4FicyBBhDb0sJ/s1600/Screenshot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="151" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9ov3dG2YA6rLzNSW7lF0yAnWqfoPbFK1OyzP93d-OlFZkuJij8mdDV6wcPsi-2mj_BoAWWxzSYqf5hPv-92jQT5BHy9p6YnN2q3G5eV2Pn8TFPuxhVzn7XyKC4h-W04u4FicyBBhDb0sJ/s320/Screenshot.png" width="320" /></a></div></div>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com1tag:blogger.com,1999:blog-5077232514658762431.post-66338739421085617052011-05-24T13:03:00.000+05:302011-06-15T15:49:36.251+05:30Art of Light: plugin for loading application constants in rails.<a href="http://shyleshkumar.blogspot.com/2011/05/plugin-for-loading-application.html">Art of Light: plugin for loading application constants in rails.</a>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-12524661636525669972011-05-24T12:52:00.000+05:302011-06-15T15:49:36.251+05:30plugin for loading application constants in rails.<div dir="ltr" style="text-align: left;" trbidi="on"><a href="https://github.com/shilesh/app_config">https://github.com/shilesh/app_config</a><br /><br /><br />I have created a simple plugin which could be helpful in your rails projects. It is available at <a href="https://github.com/shilesh/app_config">https://github.com/shilesh/app_config</a> . This plugin, once installed , loads constants from a config file, while the application gets initialized (server start/restart, rails console etc ...). <br /><br />There will be situations when application specific constants are required in our application. Which we could configure as needed.<br /><br /><div style="text-align: justify;"><pre><div class="line" id="LC4" style="background-color: transparent; text-align: left;">Summary:</div><div class="line" id="LC5" style="background-color: transparent; text-align: left;">=======</div></pre><blockquote><div class="line" id="LC6" style="background-color: transparent; text-align: left;">This plugin helps to load values from a config file(yml) file based on the </div><div class="line" id="LC9" style="background-color: transparent; text-align: left;">environment, with out writing extra code. ie: if you have a config file as 'app_config.yml' and has values in it as title: 'Caption'.The plugin helps you to call as "AppConfig::TITLE". If your config file name is 'ror_values.yml' then the values can be accessed as RorValue::TITLE". In short <filename>::<key caps="" in="">.</key></filename></div><div class="line" id="LC9" style="background-color: transparent; text-align: left;"> </div><div class="line" id="LC10" style="background-color: transparent; text-align: left;">I have tested against ruby 1.9 and rails 3.0</div></blockquote><pre><div class="line" id="LC11" style="background-color: transparent;"><br /></div><div class="line" id="LC12" style="background-color: transparent;">How to use:</div><div class="line" id="LC13" style="background-color: transparent;">==========</div></pre><ol><li> Install the plugin. </li><li> This will create a folder 'app_config' inside 'config' folder of your rails application. </li><li> A mock config file, named 'app_config.yml', will be created with sample data. </li><li> User can edit the file with proper values. </li><li> The file name can be renamed</li><li> Based on the file name the namescope will be created to access the values( <filename>::<key> ).</key></filename></li><li> Restart the server if you change the file name. </li><li> You can expect helpful error messages being raised on invalid access.</li><li> When you un-install the files in config/app_config/* will be retained, </li><li>expecting that it would contain useful data. You can manually delete it if needed.</li></ol><pre><div class="line" id="LC24" style="background-color: transparent;"> </div><div class="line" id="LC25" style="background-color: transparent;"></div></pre></div><br /> I have tested it against rails 3.0.x and 2.3.8 . </div>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-75197858372410946122010-10-25T10:56:00.000+05:302011-06-15T15:49:36.251+05:30exception handling in rubyNormally we don't explicitly specify the Exception type while 'rescue' ing it. ex:<br /><div style="font-family: "Courier New",Courier,monospace;"><i>begin</i></div><div style="font-family: "Courier New",Courier,monospace;"><i> raise 'alert'</i></div><div style="font-family: "Courier New",Courier,monospace;"><i>rescue => e</i></div><div style="font-family: "Courier New",Courier,monospace;"><i> p "Error"</i></div><div style="font-family: "Courier New",Courier,monospace;"><i>end </i></div><div style="font-family: "Courier New",Courier,monospace;">=> Error</div>Everything is fine here, But look at another case,<br /><div style="font-family: "Courier New",Courier,monospace;">begin</div><div style="font-family: "Courier New",Courier,monospace;"> require 'IamNotThere'</div><div style="font-family: "Courier New",Courier,monospace;">rescue => e</div><div style="font-family: "Courier New",Courier,monospace;"> p "Error"</div><div style="font-family: "Courier New",Courier,monospace;">end </div><div style="font-family: "Courier New",Courier,monospace;">=> LoadError: no such file to load -- IamNotThere</div>Never expected ?, Our rescue block didn't handle this case.<br /><div style="font-family: "Courier New",Courier,monospace;">begin</div><div style="font-family: "Courier New",Courier,monospace;"> require 'IamNotThere'</div><div style="font-family: "Courier New",Courier,monospace;">rescue Exception=> e</div><div style="font-family: "Courier New",Courier,monospace;"> p "Error"</div><div style="font-family: "Courier New",Courier,monospace;">end </div><div style="font-family: "Courier New",Courier,monospace;">=> Error</div>Again, everything is safe here.<br /><br />So, It's always better narrow down our expectation or use 'Exception => e'. Default is 'StandardError'.<br /><br /><br />Heirarchy:<br /><div style="font-family: "Courier New",Courier,monospace;"><br /></div><div style="font-family: "Courier New",Courier,monospace;">Exception</div><div style="font-family: "Courier New",Courier,monospace;"> NoMemoryError</div><div style="font-family: "Courier New",Courier,monospace;"> ScriptError</div><div style="font-family: "Courier New",Courier,monospace;"> LoadError</div><div style="font-family: "Courier New",Courier,monospace;"> NotImplementedError</div><div style="font-family: "Courier New",Courier,monospace;"> SyntaxError</div><div style="font-family: "Courier New",Courier,monospace;"> SignalException</div><div style="font-family: "Courier New",Courier,monospace;"> Interrupt</div><div style="font-family: "Courier New",Courier,monospace;"> StandardError</div><div style="font-family: "Courier New",Courier,monospace;"> ArgumentError</div><div style="font-family: "Courier New",Courier,monospace;"> IOError</div><div style="font-family: "Courier New",Courier,monospace;"> EOFError</div><div style="font-family: "Courier New",Courier,monospace;"> IndexError</div><div style="font-family: "Courier New",Courier,monospace;"> LocalJumpError</div><div style="font-family: "Courier New",Courier,monospace;"> NameError</div><div style="font-family: "Courier New",Courier,monospace;"> NoMethodError</div><div style="font-family: "Courier New",Courier,monospace;"> RangeError</div><div style="font-family: "Courier New",Courier,monospace;"> FloatDomainError</div><div style="font-family: "Courier New",Courier,monospace;"> RegexpError</div><div style="font-family: "Courier New",Courier,monospace;"> RuntimeError</div><div style="font-family: "Courier New",Courier,monospace;"> SecurityError</div><div style="font-family: "Courier New",Courier,monospace;"> SystemCallError</div><div style="font-family: "Courier New",Courier,monospace;"> SystemStackError</div><div style="font-family: "Courier New",Courier,monospace;"> ThreadError</div><div style="font-family: "Courier New",Courier,monospace;"> TypeError</div><div style="font-family: "Courier New",Courier,monospace;"> ZeroDivisionError</div><div style="font-family: "Courier New",Courier,monospace;"> SystemExit</div><div style="font-family: "Courier New",Courier,monospace;"> fatal</div>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-19662652420508199572010-07-20T11:54:00.000+05:302011-06-15T15:49:36.251+05:30Test ruby after installationSounds silly and obvious, But if we miss to run './rubytest' after installing ruby(any software, especially from source) we might land in big trouble. We might get the feeling that it got installed correctly but it may not. A random check in irb could show something like "123.12".to_f => 123123.0 Which is wrong, But ruby was installed fine. <br /><br />I got the tests ran successfully later and "123.12".to_f gave me 123.12.shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-29410210745571658272009-10-28T11:04:00.000+05:302011-06-15T15:49:36.251+05:30Rails ScrapsAsynchronous ...mails using workling.<br /><br />http://playtype.net/past/2008/11/11/sending_mail_asynchronously_in_rails/shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-77053961935565529312008-09-17T11:45:00.000+05:302011-06-15T15:49:36.251+05:30Ruby thoughts ... !!! Modules and Super classesRuby Consider Modules as super classes [Internally]. But My confusion is that there can be many modules either included or extended to a class where as only one Parent class is allowed [as in java] in Ruby... ? why.<br /><br />Some thing to do with the meta class and the super pointers ..?<br /><br /><br /><a href="http://www.ruby-forum.com/user/edit?user_id=9378&key=07a73e03b847d2d6cc2767d9dde21829" target="_blank">http://www.ruby-forum.com/<wbr>user/edit?user_id=9378&key=<wbr>07a73e03b847d2d6cc2767d9dde218<wbr>29</a>shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0tag:blogger.com,1999:blog-5077232514658762431.post-80956349681480910792008-09-17T11:43:00.000+05:302011-06-15T15:49:36.251+05:30Ruby thoughts ... !!! Modules and ClassesActually... the Module class of module is the superclass of the Class class of class. Got that? No? - good Now you have a reason to spent some time on Ruby :)shyl...http://www.blogger.com/profile/09755304059110514400noreply@blogger.com0