<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mknayak</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mknayak"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Mknayak"/>
	<updated>2026-09-12T07:05:24Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=82098</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=82098"/>
		<updated>2013-10-31T03:00:34Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Introduction to Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The source code is available at [https://github.com/expertiza/expertiza github].&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Design Changes=&lt;br /&gt;
Due to a lot of duplication of code that occurred in the AssignmentAnalytic, AssignmentTeamAnalytic and CourseAnalytic module, there was a definite need to refactor the duplicate code and extract out the duplication by moving the common trends in the code to a common module named as CommonAnalytic. &lt;br /&gt;
&lt;br /&gt;
Here is the original design which has a lot of code duplication particularly in the modules AssignmentAnalytic, AssignmentTeamAnalytic and CourseAnalytic. &lt;br /&gt;
&lt;br /&gt;
[[File:Original_expertiza.jpg]]&lt;br /&gt;
&lt;br /&gt;
Thus the figure below gives the refactored design which removes the common and duplicate code from AssignmentAnalytic, AssignmentTeamAnalytic and CourseAnalytic module and moves them to a common module CommonAnalytic.&lt;br /&gt;
&lt;br /&gt;
[[File:New_refactor.jpg|center|refactored expertiza design for analytic]]&lt;br /&gt;
&lt;br /&gt;
In a similar way the modules ScoreAnalytic and QuestionAnalytic had redundant and duplicate code for getting word count, character count and unique character count. Thus again there was a need to refactor the duplicate code and extract out the duplication and move it  a CountAnalytic module which would act as a center module thereby allowing ScoreAnalytic and QuestionAnalytic to delegate functions such as word count, character count and unique character count to the CountAnalytic module as shown below.&lt;br /&gt;
&lt;br /&gt;
[[File:Slide1.jpg|center|countQuestion]]&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
=== Usage of inbuilt methods.===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After refactoring'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
===Use of hashes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Methods complexity===&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 '''Code before refactoring [average_num_team_reviews in assignment_analytic ]'''. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;br /&gt;
&lt;br /&gt;
=External Links=&lt;br /&gt;
&lt;br /&gt;
#http://guides.rubyonrails.org/ A guide for Ruby on Rails&lt;br /&gt;
#http://c2.com/cgi/wiki?WhatIsRefactoring What is Refactoring?&lt;br /&gt;
#https://codeclimate.com/ Automated Code Review&lt;br /&gt;
#https://github.com/expertiza/expertiza&lt;br /&gt;
#https://github.com/bbatsov/ruby-style-guide Ruby Style Guide&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81128</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81128"/>
		<updated>2013-10-30T19:07:02Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Refactoring in AnalyticController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Design Changes=&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
=== Usage of inbuilt methods.===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After refactoring'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
===Use of hashes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Methods complexity===&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 '''Code before refactoring [average_num_team_reviews in assignment_analytic ]'''. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81125</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81125"/>
		<updated>2013-10-30T19:06:29Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Refactoring in AnalyticController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Design Changes=&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''After refactoring'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 '''Code before refactoring [average_num_team_reviews in assignment_analytic ]'''. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81123</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81123"/>
		<updated>2013-10-30T19:05:54Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Refactoring in AnalyticController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Design Changes=&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
:Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 '''Code before refactoring [average_num_team_reviews in assignment_analytic ]'''. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81116</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81116"/>
		<updated>2013-10-30T19:04:16Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Design Changes=&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 '''Code before refactoring [average_num_team_reviews in assignment_analytic ]'''. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81114</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81114"/>
		<updated>2013-10-30T19:03:50Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 '''Code before refactoring [average_num_team_reviews in assignment_analytic ]'''. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81108</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81108"/>
		<updated>2013-10-30T19:00:46Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:'''Code after refactoring.''' Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Code after refactoring:''' The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
:'''Code after refactoring:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&amp;lt;br/&amp;gt;&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81101</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81101"/>
		<updated>2013-10-30T18:59:15Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81100</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81100"/>
		<updated>2013-10-30T18:58:46Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
:&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81097</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81097"/>
		<updated>2013-10-30T18:58:17Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Refactoring in Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
===Code movement===&lt;br /&gt;
The modules were initially placed in '''app/models/''' . They were moved to '''/lib/''' folder&lt;br /&gt;
&lt;br /&gt;
===Code Changes===&lt;br /&gt;
&lt;br /&gt;
:At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81081</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=81081"/>
		<updated>2013-10-30T18:53:28Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Refactoring in AnalyticController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods.&lt;br /&gt;
Before&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;After&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Methods complexity&lt;br /&gt;
Complex methods were broken down into smaller methods to enhance readability.&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80994</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80994"/>
		<updated>2013-10-30T18:26:15Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
==Refactoring in AnalyticController==&lt;br /&gt;
:1 Usage of inbuilt methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Refactoring in Modules == &lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80989</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80989"/>
		<updated>2013-10-30T18:24:52Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
Refactoring in AnalyticController&lt;br /&gt;
:1 Usage of inbuilt methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = Array.new&lt;br /&gt;
    courses.each do |course|&lt;br /&gt;
      course_list &amp;lt;&amp;lt; [course.name, course.id]&lt;br /&gt;
    end&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.json { render :json =&amp;gt; sort_by_name(course_list) }&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def course_list&lt;br /&gt;
    courses = associated_courses(session[:user])&lt;br /&gt;
    course_list = courses.map { |course| [course.name, course.id] }&lt;br /&gt;
    render :json =&amp;gt; sort_by_name(course_list)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above refactoring was applied to team_list and assignment_list as well.&lt;br /&gt;
&lt;br /&gt;
:2 Use of hashes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 case params[:type]&lt;br /&gt;
      when &amp;quot;line&amp;quot;&lt;br /&gt;
        chart_data = line_graph_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;bar&amp;quot;&lt;br /&gt;
        chart_data = bar_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;scatter&amp;quot;&lt;br /&gt;
        chart_data = scatter_plot_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
      when &amp;quot;pie&amp;quot;&lt;br /&gt;
        chart_data = pie_chart_data(params[:scope], params[:id], params[:data_type])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hash was used to adhere to the DRY principle.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    graph_method_name = {'line' =&amp;gt; 'line_graph_data',&lt;br /&gt;
                         'bar' =&amp;gt; 'bar_chart_data',&lt;br /&gt;
                         'scatter' =&amp;gt; 'scatter_plot_data',&lt;br /&gt;
                         'pie' =&amp;gt; 'pie_graph_data'}&lt;br /&gt;
    graph_data = send(graph_method_name[graph_type], scope, id, data_type)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80934</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80934"/>
		<updated>2013-10-30T18:11:24Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The logic of the method was exactly what the &amp;lt;b&amp;gt;map&amp;lt;/b&amp;gt; method does. Futher, a ternary if-else was used to enhance readability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80901</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80901"/>
		<updated>2013-10-30T17:53:41Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* What was done: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent. Rest of the modules had duplicate code, which was refactored out.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80890</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80890"/>
		<updated>2013-10-30T17:49:58Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the classes also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80883</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80883"/>
		<updated>2013-10-30T17:46:40Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the methods also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
= Post-refactoring report=&lt;br /&gt;
[[File:code_clime_new.png]]&lt;br /&gt;
&lt;br /&gt;
Here is a summary of the results.&lt;br /&gt;
&lt;br /&gt;
[[File:Report.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Report.png&amp;diff=80881</id>
		<title>File:Report.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Report.png&amp;diff=80881"/>
		<updated>2013-10-30T17:46:09Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_clime_new.png&amp;diff=80878</id>
		<title>File:Code clime new.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_clime_new.png&amp;diff=80878"/>
		<updated>2013-10-30T17:43:46Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80875</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80875"/>
		<updated>2013-10-30T17:38:19Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;b&amp;gt;High complexity&amp;lt;/b&amp;gt; - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Duplication&amp;lt;/b&amp;gt; – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
*&amp;lt;b&amp;gt;Smells&amp;lt;/b&amp;gt; - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
&amp;lt;br&amp;gt;As regards complexity, along with a high overall complexity, the methods also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80871</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80871"/>
		<updated>2013-10-30T17:35:24Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
We used [https://codeclimate.com/github/expertiza/expertiza/code?q=analytic CodeClimate] to analyse the existing code. As can been be seen, there are several classes with duplicate code, high complexity and code smells.&lt;br /&gt;
&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
High complexity - AnalyticController, CourseAnalytic, QuestionnaireAnalytic&lt;br /&gt;
Duplication – AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
Smells - AnalyticController, AssignmentAnalytic, AssignmentTeamAnalytic, CourseAnalytic, ResponseAnalytic&lt;br /&gt;
As regards complexity, along with a high overall complexity, the methods also have a high complexity per method ratio&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_clime_old.png&amp;diff=80868</id>
		<title>File:Code clime old.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_clime_old.png&amp;diff=80868"/>
		<updated>2013-10-30T17:33:05Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: uploaded a new version of &amp;amp;quot;File:Code clime old.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80860</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80860"/>
		<updated>2013-10-30T17:30:34Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent.&lt;br /&gt;
&lt;br /&gt;
= Analysis =&lt;br /&gt;
[[File:code_clime_old.png]]&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_clime_old.png&amp;diff=80859</id>
		<title>File:Code clime old.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Code_clime_old.png&amp;diff=80859"/>
		<updated>2013-10-30T17:29:44Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80842</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80842"/>
		<updated>2013-10-30T17:23:28Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E818 Refactoring and testing -- analytics=&lt;br /&gt;
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image &amp;quot;Ruby on Rails&amp;quot;. If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza wiki(provide hyperlink) on developing Expertiza on the VCL.&lt;br /&gt;
&lt;br /&gt;
= Overview of project =&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What was done:===&lt;br /&gt;
Analytic_controller.rb and course_analytic.rb had much duplicated code, which was be factored out. Additionally, analytic_controller.rb had methods that were too complicated, and were be separated into shorter, well-named methods, to make the operation of the class more transparent.&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
:1. &amp;lt;b&amp;gt;Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;Here the inbuilt uniq method was used&amp;lt;/b&amp;gt;. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:2. &amp;lt;b&amp;gt;Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. &amp;lt;b&amp;gt;The find method was used here.&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:3 Code before refactoring [average_num_team_reviews in assignment_analytic ]. This pattern existed in many classes.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above pattern accounted for majority of the duplicate code.&lt;br /&gt;
Code before refactoring [self.types in QuestionnaireAnalytic ] &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
      type_list = Array.new&lt;br /&gt;
      self.all.each do |questionnaire|&lt;br /&gt;
        if !type_list.include?(questionnaire.type)&lt;br /&gt;
          type_list &amp;lt;&amp;lt; questionnaire.type&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
      type_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.types&lt;br /&gt;
    type_list = extract_from_list self.all, :type&lt;br /&gt;
    type_list.uniq&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80793</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80793"/>
		<updated>2013-10-30T16:46:47Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Topic and short description (E818 Refactoring and testing -- analytics)=&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What needs to be done:===&lt;br /&gt;
At least analytic_controller.rb and course_analytic.rb have much duplicated code, which should be factored out. Additionally, analytic_controller.rb has methods that are too complicated, and should be separated into shorter, well-named methods, to make the operation of the class more transparent. Also, there are absolutely no tests for any of these methods.&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
#Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#Code before refactoring [average_num_team_reviews in assignment_analytic ]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80792</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80792"/>
		<updated>2013-10-30T16:46:07Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Topic and short description (E818 Refactoring and testing -- analytics)=&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What needs to be done:===&lt;br /&gt;
At least analytic_controller.rb and course_analytic.rb have much duplicated code, which should be factored out. Additionally, analytic_controller.rb has methods that are too complicated, and should be separated into shorter, well-named methods, to make the operation of the class more transparent. Also, there are absolutely no tests for any of these methods.&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
# At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
##Code before refactor [self.questionnaire_unique? in assignment_analytic.rb]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##Code before refactoring [ questionnaire_of_type(type_name_in_string) in assignment_analytic.rb ]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.each do |questionnaire|&lt;br /&gt;
      if questionnaire.type == type_name_in_string&lt;br /&gt;
        return questionnaire&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. The find method was used here.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire_of_type(type_name_in_string)&lt;br /&gt;
    self.questionnaires.find { |questionnaire| questionnaire == type_name_in_string }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code before refactoring [average_num_team_reviews in assignment_analytic ]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    if num_teams == 0&lt;br /&gt;
      0&lt;br /&gt;
    else&lt;br /&gt;
      total_num_team_reviews.to_f/num_teams&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code after refactoring.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def average_num_team_reviews&lt;br /&gt;
    total_num_team_reviews.to_f/num_teams&lt;br /&gt;
  rescue ZeroDivisionError&lt;br /&gt;
    0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80775</id>
		<title>CSC/ECE 517 Fall 2013/oss E818 mra</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E818_mra&amp;diff=80775"/>
		<updated>2013-10-30T16:39:09Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Code changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Topic and short description (E818 Refactoring and testing -- analytics)=&lt;br /&gt;
===Classes:===&lt;br /&gt;
* analytic_controller.rb (163 lines)&lt;br /&gt;
* assignment_analytic.rb (206 lines)&lt;br /&gt;
* assignment_team_analytic.rb (126 lines)&lt;br /&gt;
* course_analytic.rb (142 lines)&lt;br /&gt;
* question_analytic.rb (12 lines)&lt;br /&gt;
* questionnaire_analytic.rb (55 lines)&lt;br /&gt;
* response_analytic.rb (101 lines)&lt;br /&gt;
* score_analytic.rb (12 lines)&lt;br /&gt;
&lt;br /&gt;
===What they do:===&lt;br /&gt;
Display information about various system components in summary form, to aid in analysis.&lt;br /&gt;
&lt;br /&gt;
===What needs to be done:===&lt;br /&gt;
At least analytic_controller.rb and course_analytic.rb have much duplicated code, which should be factored out. Additionally, analytic_controller.rb has methods that are too complicated, and should be separated into shorter, well-named methods, to make the operation of the class more transparent. Also, there are absolutely no tests for any of these methods.&lt;br /&gt;
&lt;br /&gt;
=Code changes=&lt;br /&gt;
&lt;br /&gt;
# At many places the developers had added the logic to find, map, get unique object, etc. which already exist in Enumerable module. We changed the code to use these in-built methods. Some of the examples of such changes are:&lt;br /&gt;
Code before refactor&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      assignment.questionnaire_types.each do |questionnaire_type|&lt;br /&gt;
        questionnaire_list = Array.new&lt;br /&gt;
        assignment.questionnaires.each do |questionnaire|&lt;br /&gt;
          if questionnaire.type == questionnaire_type&lt;br /&gt;
            questionnaire_list &amp;lt;&amp;lt; questionnaire&lt;br /&gt;
          end&lt;br /&gt;
          if questionnaire_list.count &amp;gt; 1&lt;br /&gt;
            return false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code after refactoring. Here the inbuilt uniq method was used. If there are duplicates, then unique array length will be less than actual length.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.questionnaire_unique?&lt;br /&gt;
    self.all.each do |assignment|&lt;br /&gt;
      questionnaires = assignment.questionnaires&lt;br /&gt;
      return false if questionnaires.uniq { |q| q.type }.length &amp;lt; questionnaires.length&lt;br /&gt;
    end&lt;br /&gt;
    return true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
##self.questionnaire_unique? in assignment_analytic.rb&lt;br /&gt;
##questionnaire_of_type(type_name_in_string) in assignment_analytic.rb&lt;br /&gt;
#The code consisted of several functions with unnecessary complexity. We refactored the code to reduce the complexity.&lt;br /&gt;
#The code consisted of several functions that had duplicate code. These methods transformed a list of objects into a list of one of the object’s attributes. This pattern was removed by creating a generic function.&lt;br /&gt;
Following was one of the pattern that existed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Expertiza code before refactoring in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
  list = Array.new     &lt;br /&gt;
  self.teams.each do |team|       &lt;br /&gt;
         list &amp;lt;&amp;lt; team.num_reviews     &lt;br /&gt;
  end      &lt;br /&gt;
  if (list.empty?)       &lt;br /&gt;
          [0]     &lt;br /&gt;
  else      &lt;br /&gt;
          list&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The refactored code for the above logic:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
# Helper function moved to common_analytic.rb&lt;br /&gt;
def extract_from_list(list, property)&lt;br /&gt;
      list.map { |item| item.send(property) }&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
# Method in assignment_analytic.rb&lt;br /&gt;
def team_review_counts     &lt;br /&gt;
      extract_from_list self.teams, :num_reviews&lt;br /&gt;
      (list.empty?) ? [0] : list    &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a list of methods and classes changed for refactoring:&lt;br /&gt;
#assignment_analytic.rb&lt;br /&gt;
##self.questionnaire_unique?&lt;br /&gt;
##questionnaire_of_type&lt;br /&gt;
##team_review_counts&lt;br /&gt;
##team_scores&lt;br /&gt;
#course_analytic.rb&lt;br /&gt;
##average_num_assignment_teams&lt;br /&gt;
##average_assignment_score&lt;br /&gt;
##assignment_review_counts&lt;br /&gt;
##assignment_team_counts&lt;br /&gt;
##assignment_average_scores&lt;br /&gt;
##assignment_max_scores&lt;br /&gt;
##assignment_min_scores&lt;br /&gt;
#assignment_team_analytic.rb&lt;br /&gt;
##average_review_word_count&lt;br /&gt;
##average_review_score&lt;br /&gt;
##average_review_character_count&lt;br /&gt;
##review_character_counts&lt;br /&gt;
##review_scores&lt;br /&gt;
##review_word_counts&lt;br /&gt;
#questionnaire_analytic.rb&lt;br /&gt;
##questions_text_list&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
#response_analytic.rb&lt;br /&gt;
##word_count_list&lt;br /&gt;
##character_count_list&lt;br /&gt;
##question_score_list&lt;br /&gt;
##comments_text_list&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
#Currently only bar charts can be seen. Further work can be done to get different kinds of graphs such as pie chart, scatter plot, etc.&lt;br /&gt;
#There are some requests that take a long time to respond. For example, View Scores Request. They can be optimized to reduce the response time.&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79023</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79023"/>
		<updated>2013-09-25T00:39:47Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* app/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, [http://en.wikipedia.org/wiki/JSON JSON]. The view does not do any processing, but simply acts as the [http://en.wikipedia.org/wiki/Presentation_layer presentation layer] , displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers are only concerned with the model structure and need not know the underlying architecture, &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it is the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates. The application data is used to fill these templates. The resultant HTML response is sent to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://ruby-on-rails.wonderhowto.com/how-to/work-with-mvc-architecture-when-writing-ruby-rails-application-405802/ How to work with MVC in Ruby on Rails]&lt;br /&gt;
*[http://www.devarticles.com/c/a/Ruby-on-Rails/The-MVC-Pattern-in-the-Rails-Framework/ The MVC pattern in Rails framework]&lt;br /&gt;
*[http://ruby.railstutorial.org/chapters/a-demo-app Learn MVC development in Rails]&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79021</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79021"/>
		<updated>2013-09-25T00:38:31Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Further Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, [http://en.wikipedia.org/wiki/JSON JSON]. The view does not do any processing, but simply acts as the [http://en.wikipedia.org/wiki/Presentation_layer presentation layer] , displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers are only concerned with the model structure and need not know the underlying architecture, &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it is the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://ruby-on-rails.wonderhowto.com/how-to/work-with-mvc-architecture-when-writing-ruby-rails-application-405802/ How to work with MVC in Ruby on Rails]&lt;br /&gt;
*[http://www.devarticles.com/c/a/Ruby-on-Rails/The-MVC-Pattern-in-the-Rails-Framework/ The MVC pattern in Rails framework]&lt;br /&gt;
*[http://ruby.railstutorial.org/chapters/a-demo-app Learn MVC development in Rails]&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79018</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79018"/>
		<updated>2013-09-25T00:34:25Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* How Rails MVC Works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, [http://en.wikipedia.org/wiki/JSON JSON]. The view does not do any processing, but simply acts as the [http://en.wikipedia.org/wiki/Presentation_layer presentation layer] , displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers are only concerned with the model structure and need not know the underlying architecture, &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it is the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79010</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=79010"/>
		<updated>2013-09-25T00:32:43Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, [http://en.wikipedia.org/wiki/JSON JSON]. The view does not do any processing, but simply acts as the [http://en.wikipedia.org/wiki/Presentation_layer presentation layer] , displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers are only concerned with the model structure and need not know the underlying architecture, &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78994</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78994"/>
		<updated>2013-09-25T00:29:15Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* app/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, [http://en.wikipedia.org/wiki/JSON JSON]. The view does not do any processing, but simply acts as the [http://en.wikipedia.org/wiki/Presentation_layer presentation layer] , displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78993</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78993"/>
		<updated>2013-09-25T00:28:01Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* View */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, [http://en.wikipedia.org/wiki/JSON JSON]. The view does not do any processing, but simply acts as the [http://en.wikipedia.org/wiki/Presentation_layer presentation layer] , displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78990</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78990"/>
		<updated>2013-09-25T00:22:51Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces [http://en.wikipedia.org/wiki/Agile_software_development agile web development]. Rails framework leverages the features of the Ruby language. Ruby is a [http://en.wikipedia.org/wiki/Dynamic_programming_language dynamically typed], object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78985</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78985"/>
		<updated>2013-09-25T00:19:27Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3] [http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78981</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78981"/>
		<updated>2013-09-25T00:17:58Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* MVC Architecture Structure In Ruby on Rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== MVC Architecture Structure In Ruby on Rails ==&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3][http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78976</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78976"/>
		<updated>2013-09-25T00:14:02Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Decision of convention over configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. This is referred to as [http://en.wikipedia.org/wiki/Convention_over_configuration Convention over configuration]&lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3][http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78975</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78975"/>
		<updated>2013-09-25T00:12:55Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
:[1] [http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[2] [http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[3][http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[4] [http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[5] [http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[6] [http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[7] [http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
:[8] [http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78970</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78970"/>
		<updated>2013-09-25T00:11:15Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* What is MVC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram. Image Credit: Wikipedia]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78250</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78250"/>
		<updated>2013-09-18T22:11:51Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* How Rails MVC Works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|center|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78249</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78249"/>
		<updated>2013-09-18T22:11:37Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* How Rails MVC Works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG|frame| MVC Architecture working and control flow]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78247</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78247"/>
		<updated>2013-09-18T22:11:02Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* How Rails MVC Works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
The model, view and controller are referred to as Active Record, Action View and Action Controller respectively here.&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78241</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78241"/>
		<updated>2013-09-18T21:41:28Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Pitfalls of the Ruby on Rails Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
#Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
#Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
#Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78239</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78239"/>
		<updated>2013-09-18T21:38:50Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* What is MVC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
1.Static web sites.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
3.Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
4.Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78238</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78238"/>
		<updated>2013-09-18T21:37:41Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram &amp;lt;ref&amp;gt;MVC Flow Diagram&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
1.Static web sites.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
3.Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
4.Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
 &amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78237</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78237"/>
		<updated>2013-09-18T21:36:11Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* What is MVC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|frame|center| MVC Flow Diagram &amp;lt;ref&amp;gt;MVC Flow Diagram&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
1.Static web sites.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
3.Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
4.Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78236</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78236"/>
		<updated>2013-09-18T21:33:12Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* What is MVC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|center| MVC Flow Diagram]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
1.Static web sites.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
3.Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
4.Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78234</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78234"/>
		<updated>2013-09-18T21:25:22Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* Further Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|center]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
1.Static web sites.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
3.Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
4.Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
*[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78233</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w27 ma</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w27_ma&amp;diff=78233"/>
		<updated>2013-09-18T21:24:57Z</updated>

		<summary type="html">&lt;p&gt;Mknayak: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= MVC Architecture Structure In Ruby on Rails =&lt;br /&gt;
&lt;br /&gt;
The aim of this wiki is to explain the explain the different components of a Rails application. It is  directed towards a novice user who can read and get an overview, '''not''' the details of any particular kind of component. In depth discussion links are made available in the further reading section.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails (RoR)] is open source web framework that is focused on productivity and enforces agile web development. Rails framework leverages the features of the Ruby language. Ruby is a dynamically typed, object-oriented, scripting language that was designed to have an elegant syntax and made as human readable as possible.&lt;br /&gt;
&lt;br /&gt;
The Ruby on Rails framework was designed for database-backed web applications. In order to make the development process faster, Ruby on Rails uses conventions and assumptions which eliminates configuration code and increases productivity. Many tasks like email management, object-database mappers, file structures, code generation etc are built in.&lt;br /&gt;
&lt;br /&gt;
== What is MVC ==&lt;br /&gt;
&lt;br /&gt;
MVC stands for [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model-View-Controller] and is a design pattern and was developed in 1979 by [http://en.wikipedia.org/wiki/Trygve_Reenskaug Trygve Reenskaug]. MVC dictates that the system be split into three distinct parts, a Model, View and Controller. These correspond to the business logic, the presentation logic and the application flow respectively. This approach organizes the code into separate components, thereby achieving separation of concerns and facilitating maintainability.&lt;br /&gt;
&lt;br /&gt;
[[File:Mvc process.png|center]]&lt;br /&gt;
&lt;br /&gt;
=== Model ===&lt;br /&gt;
: The Model generally contains the data for the application and is usually linked to a database back-end. It contains the application state, validation and also the business logic. A central component of Rails is the class [http://guides.rubyonrails.org/active_record_querying.html ActiveRecord], which maps relational tables to Ruby objects and thereby to the data manipulated by controllers and shown in views. Models in Rails inherit this class.&lt;br /&gt;
&lt;br /&gt;
:Rails provides tools to implement the [http://en.wikipedia.org/wiki/Create,_read,_update_and_delete CRUD] functionality with zero-configuration. CRUD allows creating, reading, updating and deleting records from the database through ruby objects. An model object in Rails represents a row in a database table. Additionally, Rails provides advance search capabilities and the ability to create relationships or associations between models. The model has no knowledge of the user interfaces [the view].&lt;br /&gt;
&lt;br /&gt;
=== View ===&lt;br /&gt;
:The view refers to the interface that is presented to the end-user and includes HTML, CSS, XML, Javascript, JSON. The view does not do any processing, but simply acts as the presentation layer, displaying the application data. Views in Rails consist of '''''.erb''''' files that combines pure HTML with embedded Ruby code.&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
:The controller receives events from the outside world [ or through some view]. It is the facility within the application that directs traffic. It interacts with the model and redirects to the appropriate view. The controller queries the models for specific data, and also organizes that data (searching, sorting, massaging it) into a form that fits the needs of a given view. In Rails, controllers should descend from '''ApplicationController''' which itself descends from [http://api.rubyonrails.org/classes/ActionController/Base.html ActionController::Base]&lt;br /&gt;
&lt;br /&gt;
Thus the decoupled nature of MVC gives us more flexibility and allows us to easily maintain our application. For example, we can have multiple possible views for the same model and can switch between them if required. Also, view developers need not know of the underlying architecture, and are only concerned with the model structure.&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How Rails MVC Works ==&lt;br /&gt;
[[File:wiki.PNG]]&lt;br /&gt;
&lt;br /&gt;
MVC Architecture working can be explained as follows:&lt;br /&gt;
&lt;br /&gt;
:1. The browser makes a request, such as http://myblog.com/videos/show/10&lt;br /&gt;
&lt;br /&gt;
:2. The web server receives the request. It uses routes to find out which controller to use. The default route pattern is '''''/controller/action/id''''' as defined in '''''config/routes.rb'''''. In this case, it’s the '''''video''''' controller, method '''''show''''', id '''''10'''''. Controllers do the work of parsing user requests, data submissions, cookies, sessions. In this case, the show method in the video controller knows it needs to lookup a video. It asks the model to get video 10, and will eventually display it to the user.&lt;br /&gt;
&lt;br /&gt;
:3.The ''' Model(ActiveRecord)''' is implemented in '''ActiveRecord''' library which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.&lt;br /&gt;
&lt;br /&gt;
:4. In this case, the model retrieves video 10 from the database.&lt;br /&gt;
&lt;br /&gt;
:5. Model sends the retrieved data ie video 10 in this case to the controller.&lt;br /&gt;
&lt;br /&gt;
:6. The '''Views(ActionView)''' subsystem is implemented in ActionView library which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. In our example, the controller gives video 10 to the '''''show''''' view. &lt;br /&gt;
&lt;br /&gt;
:7. The show view generates the HTML: divs, tables, text, descriptions, footers, etc and returns it to the controller.&lt;br /&gt;
&lt;br /&gt;
:8. The controller returns the response body (HTML, XML, etc.) &amp;amp; metadata (caching headers, redirects) to the server. The controller subsystem is implemented in '''ActionController''' which is a data broker sitting between '''ActiveRecord''' (the database interface) and '''ActionView''' (the presentation engine). The server combines the raw data into a proper HTTP response and sends it to the user's browser.&lt;br /&gt;
&lt;br /&gt;
== Directory Structure &amp;amp; Components ==&lt;br /&gt;
The primary components of Rails are&lt;br /&gt;
* Application components like model, view, controller, helpers&lt;br /&gt;
* Environment &amp;amp; Routing Configuration&lt;br /&gt;
* Database Migration Components&lt;br /&gt;
* Test classes &lt;br /&gt;
&lt;br /&gt;
Now we look at how these components are organised into different directories. The default directory structure of a generated Rails application is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  |-- app&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   |   |-- images&lt;br /&gt;
  |   |   |-- javascripts&lt;br /&gt;
  |   |   `-- stylesheets&lt;br /&gt;
  |   |-- controllers&lt;br /&gt;
  |   |-- helpers&lt;br /&gt;
  |   |-- mailers&lt;br /&gt;
  |   |-- models&lt;br /&gt;
  |   `-- views&lt;br /&gt;
  |       `-- layouts&lt;br /&gt;
  |-- config&lt;br /&gt;
  |   |-- environments&lt;br /&gt;
  |   |-- initializers&lt;br /&gt;
  |   `-- locales&lt;br /&gt;
  |-- db&lt;br /&gt;
  |-- doc&lt;br /&gt;
  |-- lib&lt;br /&gt;
  |   |-- assets&lt;br /&gt;
  |   `-- tasks&lt;br /&gt;
  |-- log&lt;br /&gt;
  |-- public&lt;br /&gt;
  |-- script&lt;br /&gt;
  |-- test&lt;br /&gt;
  |   |-- fixtures&lt;br /&gt;
  |   |-- functional&lt;br /&gt;
  |   |-- integration&lt;br /&gt;
  |   |-- performance&lt;br /&gt;
  |   `-- unit&lt;br /&gt;
  |-- tmp&lt;br /&gt;
  |   `-- cache&lt;br /&gt;
  |       `-- assets&lt;br /&gt;
  `-- vendor&lt;br /&gt;
      |-- assets&lt;br /&gt;
      |   |-- javascripts&lt;br /&gt;
      |   `-- stylesheets&lt;br /&gt;
      `-- plugins&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== app/ ====&lt;br /&gt;
&lt;br /&gt;
This folder organizes the different application components. These include view (views and helpers), controller (controllers), and the backend business logic (models).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''app/controllers:''' This is the sub-directory where Rails looks for the controller classes. &lt;br /&gt;
&lt;br /&gt;
*'''app/models:''' The directory for the models&lt;br /&gt;
&lt;br /&gt;
*'''app/view:''' The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.&lt;br /&gt;
&lt;br /&gt;
*'''app/view/layouts:''' Layouts directory contains the template files for layouts to be used with views. Examples of layouts are the common header/footer for the views. &lt;br /&gt;
&lt;br /&gt;
*'''app/mailers:''' This directory contains all the mailer files used to send emails. The [http://guides.rubyonrails.org/action_mailer_basics.html ActionMailer] module in Rails can handle simple text or complex rich-format emails. Also it has common tasks built-in, such as, sending out forgotten passwords, welcome messages, and fulfilling any other written-communication’s need. &lt;br /&gt;
&lt;br /&gt;
*'''app/helpers:'''  These are the helper classes used to assist the MVC classes. We need to keep as much Ruby code out of the views as possible, so helpers are mainly for use in that context. Helpers are the only methods one can access in the views, other than instance methods for an instance you have access to. Helpers make it possible to keep rest of the MVC code uncluttered.&lt;br /&gt;
&lt;br /&gt;
*'''app/assets:'''  The assets folder has sub-directories to store images, javascripts and stylesheets. Rails has an asset pipeline which  concatenates and minifies JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== config/ ====&lt;br /&gt;
This directory contains the configuration code that the application needs. This includes database configuration, environment structure , routing of incoming web requests. &lt;br /&gt;
&lt;br /&gt;
*'''config/environments:''' It is possible to execute some environment specific code in Rails. Rails automatically detects your current environment [development, test or production] and executes the environment file in this directory. For example, it will run '''''config/environments/development.rb''''' for the development environment. Thus we can tailor the behavior of the three Rails environments for test, development, and deployment with files in the environments directory.&lt;br /&gt;
&lt;br /&gt;
*'''config/initializers:''' Any Ruby file stored in this directory is considered to be an initializer. It holds configuration settings that should be made after all of the frameworks and gems are loaded. Initializers can be further organised into sub-directories. If there are any   ordering dependencies for the initializers,we can control the load order by naming. The initializers are run in alphabetical order.&lt;br /&gt;
&lt;br /&gt;
*'''routes.rb:''' The routing system in Rails is the system that examines the URL of an incoming request and determines what action should be taken by the application. Thus it recognizes URLs and dispatches them to a controller's action. The routes.rb file contains the rules .&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== db/ ====&lt;br /&gt;
&lt;br /&gt;
Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.&lt;br /&gt;
&lt;br /&gt;
*'''db/migrate:''' Has all the [http://guides.rubyonrails.org/migrations.html migrations] that you created. Migrations are a convenient way to alter your database schema over time in a consistent and easy way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.&lt;br /&gt;
&lt;br /&gt;
*'''schema.rb:''' It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. It is used by the tests to populate the database schema.&lt;br /&gt;
&lt;br /&gt;
*'''seeds.rb:''' The purpose of seed data is to [http://en.wikipedia.org/wiki/Bootstrapping bootstrap] your database. Thus in this file, we initialize the database with default values. For example, things like administrative accounts, or other data that's necessary to run your application for the first time. One shouldn't add anything to a seeds.rb file that isn't necessary to bootstrap your database or its relations&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== test/ ====&lt;br /&gt;
The tests you write and those Rails creates for you all go here. You'll see a sub-directory for unit tests (unit), fixtures (fixtures), and functional tests (functional).&lt;br /&gt;
There are the following sub-directories&lt;br /&gt;
&lt;br /&gt;
*'''test/unit:''' Unit testing is a testing technique to validate that individual “units” of code are working properly. A “unit” refers to the smallest testable part of the code. When unit testing, we are not interested in how all the units fit together, just in make sure that each unit is functioning properly on its own.&lt;br /&gt;
&lt;br /&gt;
*'''test/fixtures:''' Fixtures are a way of organizing test data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent written in YAML. There is one file per model. When you run ''''''rails generate model'''''' to create a new model, fixture stubs will be automatically created and placed in this directory. &lt;br /&gt;
&lt;br /&gt;
*'''test/functional:''' Functional tests live inside of the test/functional directory. These tests are designed to exercise your controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/integration:''' To write an integration test, standard convention is to put them into a test/integration directory. Whereas unit tests exercise models and functional tests focus on single actions within a specific controller, integration tests are meant to test complete workflows, that likely step through multiple actions across one or more controllers.&lt;br /&gt;
&lt;br /&gt;
*'''test/performance:''' Rails performance tests are a special type of integration tests, designed for bench-marking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Other Directories ====&lt;br /&gt;
*'''public:''' This directory contains static files and compiled assets, such as JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public). The files in this directory are accessible by anyone visiting the site, irrespective of authentication. Error pages (404) are usually stored here&lt;br /&gt;
&lt;br /&gt;
*'''tmp:''' Temporary files are stored here.&lt;br /&gt;
&lt;br /&gt;
*'''vendor:''' This folder contains plugins, gems &amp;amp; libraries provided by third-party vendors. Example: database utilities library&lt;br /&gt;
&lt;br /&gt;
*'''script:''' This directory holds scripts to launch and manage the various tools that you'll use with Rails.&lt;br /&gt;
&lt;br /&gt;
*'''lib:''' For library [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html modules].&lt;br /&gt;
&lt;br /&gt;
*'''log:''' Error logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).&lt;br /&gt;
&lt;br /&gt;
*'''doc:''' Rails can generate the documentation for your code automatically, if you provide comments in a certain expected format in your code. The generated documentation is placed in this directory.&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Gemfile ====&lt;br /&gt;
[http://en.wikipedia.org/wiki/RubyGems Gems] are Ruby software packages available online. The gemfile is a list of all gems that you want to include in the project. The bundler tool uses the gem file to install, update, remove and otherwise manage existing gems.It is possible to  group gems in ''':development, :test, :assets &amp;amp; :production''' groups and Rails will know when to include the gems.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Rakefile ====&lt;br /&gt;
The [http://rake.rubyforge.org/doc/rakefile_rdoc.html Rakefile] is similar to [http://capone.mtsu.edu/csdept/FacilitiesAndResources/make.htm Unix Makefile] which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== README ====&lt;br /&gt;
This file contains a basic detail about Rail Application and description of the directory structure explained above&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls of the Ruby on Rails Architecture ==&lt;br /&gt;
&lt;br /&gt;
=== Build on interpreted language ===&lt;br /&gt;
:As Rails is built on the top of the Ruby language, it inherits its goodness and weakness as well. Ruby is totally object oriented and a dynamic scripting language with an elegant syntax. As it is an interpreted language it is slower than other languages that are compiled like Java or C++. In most cases, this difference in speed is not a problem but the performance starts to degrade when the web application needs to scale to millions of concurrent users. &lt;br /&gt;
&lt;br /&gt;
=== Not suited for high concurrency ===&lt;br /&gt;
:The Ruby language is not suited for high concurrency applications, because it is not optimized for speed computing. Ruby was designed to be used for rapid development. It does not have good thread support and has trouble dealing with long-lived processes. Another shortcoming is that Ruby’s garbage collector cannot be compared to that of Java. Thus each process requires much more memory.&lt;br /&gt;
&lt;br /&gt;
=== Deployment concerns === &lt;br /&gt;
:Although not an architectural flaw, a web application on Ruby on Rails could be harder to deploy than sites that are using more common technologies, such as PHP. That’s because not all the hosting providers support Rails, but the support for Rails is increasing.&lt;br /&gt;
&lt;br /&gt;
=== Scalability concerns ===&lt;br /&gt;
:Often there are talks about scalability issues in Rails. Developers claim that when dealing with large scale application, the ORM layer turns out to be a bottleneck. As stated above, the lack of good thread support is also a contributing factor. Caching can mitigate some of the speed concerns.&lt;br /&gt;
&lt;br /&gt;
=== Decision of convention over configuration ===&lt;br /&gt;
:The Rails architecture sacrifices some flexibility in configuration to increase productivity based on conventions that are considered best practices. &lt;br /&gt;
&lt;br /&gt;
There are some types of applications in which Ruby on Rails Architecture is not suitable:&lt;br /&gt;
&lt;br /&gt;
1.Static web sites.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Sites that depend on large amount of existing code or legacy code or legacy databases.&amp;lt;br&amp;gt;&lt;br /&gt;
3.Requirements where dozens or hundreds of websites are residing in a single server.&amp;lt;br&amp;gt;&lt;br /&gt;
4.Very large-scale web applications (millions of concurrent users) that need to deliver high-performance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
*[http://www.ibm.com/developerworks/linux/library/l-rubyrails/ Ruby on Rails for web application] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://santhoshthepro.in/rails-directory-structure Rails Directory structure] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.tutorialspoint.com/ruby-on-rails/ Ruby on Rails Tutorial] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://www.computerworld.com/s/article/9060861/Ruby_on_Rails_routing_demystified?pageNumber=1 Routing Demytified] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://blog.iandavis.com/2008/12/09/ What-are-the-benefits-of-MVC] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://adrianmejia.com/blog/2011/08/11/ruby-on-rails-architectural-design/ Ruby-on-rails-architectural-design] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/testing.html Testing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
*[http://guides.rubyonrails.org/migrations.html Database Migrations] &amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Further Reading ==&lt;br /&gt;
&lt;br /&gt;
[http://guides.rubyonrails.org/initialization.html Rails Initialization Process] &amp;lt;br/&amp;gt;&lt;br /&gt;
[http://guides.rubyonrails.org/routing.html Routing in Rails] &amp;lt;br/&amp;gt;&lt;br /&gt;
[http://www.informit.com/articles/article.aspx?p=1087656&amp;amp;seqNum=5 Routing Explained] &amp;lt;br/&amp;gt;&lt;br /&gt;
[http://c2.com/cgi/wiki?ModelViewController Model-View-Controller Guide] &amp;lt;br/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mknayak</name></author>
	</entry>
</feed>