Commit 3cc6ecfe50c8f9424b4404f5da440ede27db25e4
Committed by
Paulo Meireles
1 parent
66fb1ebe
Exists in
master
and in
23 other branches
[Mezuro] Begginning of refactoring design to MVC, created project and repository models
Showing
2 changed files
with
5 additions
and
5 deletions
Show diff stats
plugins/mezuro/lib/kalibro/model.rb
| @@ -3,7 +3,7 @@ class Kalibro::Model | @@ -3,7 +3,7 @@ class Kalibro::Model | ||
| 3 | def initialize(attributes={}) | 3 | def initialize(attributes={}) |
| 4 | attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | 4 | attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } |
| 5 | end | 5 | end |
| 6 | - | 6 | + |
| 7 | def to_hash | 7 | def to_hash |
| 8 | hash = Hash.new | 8 | hash = Hash.new |
| 9 | fields.each do |field| | 9 | fields.each do |field| |
| @@ -39,7 +39,7 @@ class Kalibro::Model | @@ -39,7 +39,7 @@ class Kalibro::Model | ||
| 39 | instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } | 39 | instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } |
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | - def convert_to_hash(value) | 42 | + def convert_to_hash(value) |
| 43 | return value if value.nil? | 43 | return value if value.nil? |
| 44 | return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) | 44 | return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) |
| 45 | return value.to_hash if value.is_a?(Kalibro::Model) | 45 | return value.to_hash if value.is_a?(Kalibro::Model) |
plugins/mezuro/lib/kalibro/project.rb
| @@ -5,7 +5,7 @@ class Kalibro::Project < Kalibro::Model | @@ -5,7 +5,7 @@ class Kalibro::Project < Kalibro::Model | ||
| 5 | def self.all_names | 5 | def self.all_names |
| 6 | request("Project", :get_project_names)[:project_name] | 6 | request("Project", :get_project_names)[:project_name] |
| 7 | end | 7 | end |
| 8 | - | 8 | + |
| 9 | def self.find_by_name(project_name) | 9 | def self.find_by_name(project_name) |
| 10 | new request("Project", :get_project, :project_name => project_name)[:project] | 10 | new request("Project", :get_project, :project_name => project_name)[:project] |
| 11 | end | 11 | end |
| @@ -18,7 +18,7 @@ class Kalibro::Project < Kalibro::Model | @@ -18,7 +18,7 @@ class Kalibro::Project < Kalibro::Model | ||
| 18 | :repository => { | 18 | :repository => { |
| 19 | :type => content.repository_type, | 19 | :type => content.repository_type, |
| 20 | :address => content.repository_url | 20 | :address => content.repository_url |
| 21 | - }, | 21 | + }, |
| 22 | :configuration_name => content.configuration_name | 22 | :configuration_name => content.configuration_name |
| 23 | }).save | 23 | }).save |
| 24 | end | 24 | end |
| @@ -26,7 +26,7 @@ class Kalibro::Project < Kalibro::Model | @@ -26,7 +26,7 @@ class Kalibro::Project < Kalibro::Model | ||
| 26 | def destroy | 26 | def destroy |
| 27 | self.class.request("Project", :remove_project, {:project_name => name}) | 27 | self.class.request("Project", :remove_project, {:project_name => name}) |
| 28 | end | 28 | end |
| 29 | - | 29 | + |
| 30 | def save | 30 | def save |
| 31 | begin | 31 | begin |
| 32 | self.class.request("Project", :save_project, {:project => to_hash}) | 32 | self.class.request("Project", :save_project, {:project => to_hash}) |