mack-orm_common 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ README
2
+ ========================================================================
3
+ mack-orm_common was developed by: markbates
data/lib/errors.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Mack
2
+ module Errors
3
+ # Raised if there are migrations that need to be run before a task is performed.
4
+ class UnrunMigrations < StandardError
5
+ # Taks the number of migrations that need to be run.
6
+ def initialize(number)
7
+ super("You currently have #{number} #{number == 1 ? "migration" : "migrations"} that #{number == 1 ? "needs" : "need"} to be run.")
8
+ end
9
+
10
+ end
11
+ end # Errors
12
+ end # Mack
@@ -0,0 +1,38 @@
1
+ module Mack
2
+ module Genosaurus
3
+ module Helpers
4
+
5
+ def columns(name = param(:name))
6
+ ivar_cache("form_columns") do
7
+ cs = []
8
+ cols = (param(:cols) || param(:columns))
9
+ if cols
10
+ cols.split(",").each do |x|
11
+ cs << Mack::Genosaurus::ModelColumn.new(name, x)
12
+ end
13
+ end
14
+ cs
15
+ end
16
+ end
17
+
18
+ def db_directory
19
+ File.join(Mack::Configuration.root, "db")
20
+ end
21
+
22
+ def migrations_directory
23
+ File.join(db_directory, "migrations")
24
+ end
25
+
26
+ def next_migration_number
27
+ last = Dir.glob(File.join(migrations_directory, "*.rb")).last
28
+ if last
29
+ return File.basename(last).match(/^\d+/).to_s.succ
30
+ end
31
+ return "001"
32
+ end
33
+
34
+ ::Genosaurus.send(:include, self)
35
+
36
+ end # Helpers
37
+ end # Genosaurus
38
+ end # Mack
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), 'genosaurus_helpers')
2
+ require File.join(File.dirname(__FILE__), 'model_column')
3
+ require File.join(File.dirname(__FILE__), 'errors')
4
+
5
+ module Mack
6
+ module Configuration
7
+
8
+ def self.database_configurations
9
+ YAML::load(Erubis::Eruby.new(IO.read(File.join(Mack::Configuration.config_directory, "database.yml"))).result)
10
+ end
11
+
12
+ end # Configuration
13
+ end # Mack
@@ -0,0 +1,55 @@
1
+ module Mack
2
+ module Genosaurus
3
+
4
+ # Used to represent a 'column' from the param cols or columns for generators.
5
+ class ModelColumn
6
+
7
+ # The name of the column.
8
+ attr_accessor :column_name
9
+ # The type of the column. Ie. string, integer, datetime, etc...
10
+ attr_accessor :column_type
11
+ # The name of the model associated with the column. Ie. user, post, etc...
12
+ attr_accessor :model_name
13
+
14
+ # Takes in the model_name (user, post, etc...) and the column (username:string, body:text, etc...)
15
+ def initialize(model_name, column_unsplit)
16
+ self.model_name = model_name.singular.underscore
17
+ cols = column_unsplit.split(":")
18
+ self.column_name = cols.first.singular.underscore
19
+ self.column_type = cols.last.singular.underscore
20
+ end
21
+
22
+ # Examples:
23
+ # Mack::Generator::ColumnObject.new("user", "username:string").form_element_name # => "user[username]"
24
+ # Mack::Generator::ColumnObject.new("Post", "body:text").form_element_name # => "post[body]"
25
+ def form_element_name
26
+ "#{self.model_name}[#{self.column_name}]"
27
+ end
28
+
29
+ # Examples:
30
+ # Mack::Generator::ColumnObject.new("user", "username:string").form_element_id # => "user_username"
31
+ # Mack::Generator::ColumnObject.new("Post", "body:text").form_element_id # => "post_body"
32
+ def form_element_id
33
+ "#{self.model_name}_#{self.column_name}"
34
+ end
35
+
36
+ # Generates the appropriate HTML form field for the type of column represented.
37
+ #
38
+ # Examples:
39
+ # Mack::Generator::ColumnObject.new("user", "username:string").form_field
40
+ # => "<input type="text" name="user[username]" id="user_username" size="30" value="<%= user.username %>" />"
41
+ # Mack::Generator::ColumnObject.new("Post", "body:text").form_field
42
+ # => "<textarea name="post[body]" id="post_id"><%= post.body %></textarea>"
43
+ def form_field
44
+ case self.column_type
45
+ when "text"
46
+ %{<textarea name="#{self.form_element_name}" id="#{self.form_element_id}" cols="60" rows="20"><%= @#{self.model_name}.#{self.column_name} %></textarea>}
47
+ else
48
+ %{<input type="text" name="#{self.form_element_name}" id="#{self.form_element_id}" size="30" value="<%= @#{self.model_name}.#{self.column_name} %>" />}
49
+ end
50
+ end
51
+
52
+ end # ModelColumn
53
+
54
+ end # Generator
55
+ end # Mack
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class Mack-ormCommonTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # replace this with tests of your own.
12
+ def test_truth
13
+ assert true
14
+ end
15
+
16
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+
3
+ class Test::Unit::TestCase
4
+
5
+ # place common methods, assertions, and other type things in this file so
6
+ # other tests will have access to them.
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mack-orm_common
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - markbates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-06 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "mack-orm_common was developed by: markbates"
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/errors.rb
26
+ - lib/genosaurus_helpers.rb
27
+ - lib/mack-orm_common.rb
28
+ - lib/model_column.rb
29
+ - README
30
+ has_rdoc: true
31
+ homepage:
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project: magrathea
53
+ rubygems_version: 1.0.1
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: Common files shared with all Mack ORM gems.
57
+ test_files:
58
+ - test/mack-orm_common_test.rb
59
+ - test/test_helper.rb