railstar 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/README.rdoc +68 -1
  2. data/app/views/railstar/general/code.html.erb +2 -1
  3. data/app/views/railstar/general/routes.html.erb +1 -2
  4. data/lib/railstar/active_record_ext.rb +15 -5
  5. data/lib/railstar/code_holder.rb +15 -5
  6. data/lib/railstar/column_comment.rb +67 -0
  7. data/lib/railstar/version.rb +1 -1
  8. data/lib/railstar.rb +2 -0
  9. data/test/dummy/config/database.yml +8 -0
  10. data/test/dummy/log/development.log +1790 -0
  11. data/test/dummy/tmp/cache/assets/BD2/850/sprockets%2F212d40170837515304b9063333be003f +0 -0
  12. data/test/dummy/tmp/cache/assets/C16/850/sprockets%2Ff4c43aa1311657553d81a21368338645 +0 -0
  13. data/test/dummy/tmp/cache/assets/C6E/730/sprockets%2F91874fafd1045394dd491568659e7926 +0 -0
  14. data/test/dummy/tmp/cache/assets/C7A/550/sprockets%2F8130e207e861a29e1b3411c0fd728858 +0 -0
  15. data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  16. data/test/dummy/tmp/cache/assets/CD0/A50/sprockets%2Faf1a52f4402e0d40b20f84cb17536598 +0 -0
  17. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  18. data/test/dummy/tmp/cache/assets/CE0/760/sprockets%2F337cad824c44b29db86894b1d12b2990 +0 -0
  19. data/test/dummy/tmp/cache/assets/CE9/4A0/sprockets%2F2677fb28f82f2351e55fd8a87c16503a +0 -0
  20. data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  21. data/test/dummy/tmp/cache/assets/CF7/8E0/sprockets%2Fc7246096aa7393cf2d9b295ef766f619 +0 -0
  22. data/test/dummy/tmp/cache/assets/CFB/BC0/sprockets%2F06712eb9b4546c3ace17f21e2de20701 +0 -0
  23. data/test/dummy/tmp/cache/assets/CFF/920/sprockets%2F978f196f9aebd8f2427385ad60455e87 +0 -0
  24. data/test/dummy/tmp/cache/assets/D02/180/sprockets%2Fa2b299d2e064d59021a229159fcb3be1 +0 -0
  25. data/test/dummy/tmp/cache/assets/D06/910/sprockets%2Fcd3a511c04c4949626d23b83de17c37b +0 -0
  26. data/test/dummy/tmp/cache/assets/D10/0E0/sprockets%2Fc99ee79715dc1e42acc661251f720b44 +0 -0
  27. data/test/dummy/tmp/cache/assets/D1D/F20/sprockets%2Fd6bb8c79b5667def69f4301e7013628b +0 -0
  28. data/test/dummy/tmp/cache/assets/D2C/E30/sprockets%2F1142f2a14b9b84e21b28f864d223bdbb +0 -0
  29. data/test/dummy/tmp/cache/assets/D31/ED0/sprockets%2F9913807526d036cb3fa19b0bbca3e54b +0 -0
  30. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  31. data/test/dummy/tmp/cache/assets/D38/A90/sprockets%2F60870f38f70884cdfb1caa382311d2ce +0 -0
  32. data/test/dummy/tmp/cache/assets/D46/0F0/sprockets%2F268fc8d914b620b386f2abcdf846085c +0 -0
  33. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  34. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  35. data/test/dummy/tmp/cache/assets/D78/2A0/sprockets%2F24afdb9e785b7c66cb5c0ee16347a297 +0 -0
  36. data/test/dummy/tmp/cache/assets/D7D/E40/sprockets%2F5bae168d39d154d44c68a848fbbf09c9 +0 -0
  37. data/test/dummy/tmp/cache/assets/D89/460/sprockets%2Fd3da7452aa3ad6cf1528dcf542af0043 +0 -0
  38. data/test/dummy/tmp/cache/assets/DA5/4B0/sprockets%2Fae01bf1936611de0fe2aa0a4e3a0aa43 +0 -0
  39. data/test/dummy/tmp/cache/assets/DC0/120/sprockets%2Fe5ce1f8a1f71614cd25b45dbbc4a36c3 +0 -0
  40. data/test/dummy/tmp/cache/assets/DC3/C70/sprockets%2F4d00f6d834e5d6a4fbde56341baa84ab +0 -0
  41. data/test/dummy/tmp/cache/assets/DD5/E00/sprockets%2F23ad9be17726d9cfeeb23450b29dfd8e +0 -0
  42. data/test/dummy/tmp/cache/assets/DD6/E70/sprockets%2Fb37f1888c20e8a6bfe17e753fce3b4bd +0 -0
  43. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  44. data/test/dummy/tmp/cache/assets/DE5/170/sprockets%2Fef6f9b493262394abdb85beafc88e9e3 +0 -0
  45. data/test/dummy/tmp/cache/assets/E04/5A0/sprockets%2Fc8052f0d827a69d3feef3e3efef0e4b2 +0 -0
  46. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  47. data/test/dummy/tmp/cache/assets/E09/CF0/sprockets%2Fe42ceae7f6bf3e688024e463baefcf39 +0 -0
  48. data/test/dummy/tmp/cache/assets/E28/6A0/sprockets%2F7d5af50b0e7b5ca1eaaf9f7a87c51e1d +0 -0
  49. metadata +17 -8
data/README.rdoc CHANGED
@@ -1,3 +1,70 @@
1
1
  = Railstar
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ == generator
4
+
5
+ === install
6
+ 初期設定ファイルを配置
7
+
8
+ === scaffold
9
+ 確認画面付きscaffold
10
+
11
+ rails generate railstar:scaffold NAME [field[:type] field[:type]] [options]
12
+ rails g railstar:scaffold article title:string body:text
13
+
14
+ モデルは作らない。コントローラとビューのみ生成
15
+
16
+ == CodeHolder
17
+ RAILS_ROOT/resources/code配下にcsvを配置することで定数を管理することができる。
18
+
19
+ 例)RAILS_ROOT/resources/code/blood_type.csv
20
+ title,血液型
21
+ #DATA
22
+ key,value,position,name,hoge
23
+ A,a,1,A型,三角
24
+ B,b,2,B型,台形
25
+ AB,ab,3,AB型,星形
26
+ O,o,4,O型,丸
27
+
28
+ key,value,position,name 必須
29
+
30
+ > C.blood_type.A => "a"
31
+ > C.blood_type.A.name => "A型"
32
+ > C.blood_type["a"] => "a"
33
+ > C.blood_type["a"].key => "A"
34
+ > C.blood_type["a"].name => "A型"
35
+ > C.blood_type["a"].hoge => "三角"
36
+
37
+ この後に任意の項目を付け足すことが可能(上記例ではhoge)
38
+
39
+ このセレクトボックスを作りたければ
40
+
41
+ <%= f.select :blood_type, C.blood_types.to_opt, :include_blank => "選択してください" %>
42
+
43
+ CSVのpositionカラムの数字を入れ替えることで、セレクトボックスの順番を変えることも可能
44
+
45
+ == ページ毎の<head>要素コントロール
46
+ layoutファイルにおいて、
47
+ <head>
48
+ <title><%= yield :title %></title>
49
+ <%= stylesheet_link_tag "application", :media => "all" %>
50
+ <%= javascript_include_tag "application" %>
51
+ <%= csrf_meta_tags %>
52
+ <%= yield :head %>
53
+ </head>
54
+
55
+ としておくことで、各viewで、
56
+
57
+ <% title "ページタイトル" %> タイトル設定
58
+ <% stylesheet "hoge", "fuga" %> そのviewのみでhoge.cssとfuga.cssを読み込む
59
+ <% javascript "hoge", "fuga" %> そのviewのみでhoge.jsとfuga.jsを読み込む
60
+
61
+ など、各viewから、親となるlayoutファイルのhead要素を追加することができる
62
+
63
+
64
+
65
+ == 開発サポート
66
+ config/routes.rbに以下の1行を記載することで、アプリケーション内の定数やルーティングを閲覧することができる
67
+
68
+ mount Railstar::Engine => "/railstar"
69
+
70
+ 現在はproductionでも見れているので注意
@@ -17,8 +17,9 @@
17
17
  <table class="table table-bordered table-condensed">
18
18
  <thead>
19
19
  <tr>
20
+ <% sample = C.send(code).values.first %>
20
21
  <% C.send(code).headers.each do |c| %>
21
- <th><%= c %></th>
22
+ <th><%= c %>:<%= sample.send(c).class.to_s %></th>
22
23
  <% end %>
23
24
  </tr>
24
25
  </thead>
@@ -10,10 +10,9 @@
10
10
  </tr>
11
11
  </thead>
12
12
  <tbody>
13
- <% name = nil %>
14
13
  <% @routes.each do |route| %>
15
14
  <tr>
16
- <td><%= name = route.name || name %></td>
15
+ <td><%= route.name %></td>
17
16
  <td><%= route.constraints[:request_method].inspect.gsub(/(nil)|[\/^$]/,"") %></td>
18
17
  <td><%= route.path.spec %></td>
19
18
  <td><%= route.defaults %></td>
@@ -7,11 +7,12 @@ module Railstar
7
7
  self.truncation!
8
8
  end
9
9
 
10
- def truncation!
10
+ def truncation!(sym=:yml)
11
11
  table_name = self.to_s.underscore.pluralize
12
- file_name = "#{table_name}.yml"
12
+ file_name = "#{table_name}.#{sym.to_s}"
13
13
  file_path = File.join(Rails.root, "resources", "db", file_name)
14
14
  raise "#{file_path} file not found." unless File.exist?(file_path)
15
+
15
16
  self.transaction do
16
17
  case self.connection.adapter_name
17
18
  when "SQLite"
@@ -19,11 +20,20 @@ module Railstar
19
20
  else
20
21
  self.connection.execute("TRUNCATE TABLE `#{self.table_name}`")
21
22
  end
22
- YAML.load_file(file_path).each do |key, value|
23
- self.create value
24
- end
23
+ self.send("create_from_#{sym.to_s}", file_path)
24
+ end
25
+ end
26
+
27
+ def create_from_yml(file_path)
28
+ YAML.load_file(file_path).each do |value|
29
+ self.create value.is_a?(Array) ? value.last : value
25
30
  end
26
31
  end
32
+
33
+ def create_from_csv(file_path)
34
+ CSV.foreach(file_path, :headers => true) {|row| self.create Hash[*row.to_a.flatten] }
35
+ end
36
+
27
37
  end
28
38
 
29
39
  module InstanceMethods
@@ -35,16 +35,20 @@ module Railstar
35
35
  super(nil)
36
36
 
37
37
  @order = []
38
+ @type = {}
38
39
 
39
40
  mode = "config"
40
41
  CSV.foreach(search_file(name), :encoding => "UTF-8") do |row|
41
- if mode == "config" && row.first == "#DATA"
42
- mode = "header"
42
+ if mode == "config"
43
+ if row.first == "type"
44
+ @type[row[1].to_sym] = row[2]
45
+ end
46
+ mode = "header" if row.first == "#DATA"
43
47
  elsif mode == "header"
44
48
  @headers = row.map(&:to_sym)
45
49
  mode = "data"
46
50
  elsif mode == "data" && row.first.present?
47
- code = Code.new(@headers.zip(row).flatten)
51
+ code = Code.new(@headers.zip(row).flatten, @type)
48
52
  raise DuplicateValue, code.value if self[code.value]
49
53
  self[code.value.to_s] = code
50
54
  self.instance_eval <<-EOS
@@ -81,8 +85,9 @@ module Railstar
81
85
  end
82
86
 
83
87
  class Code < String
84
- def initialize(args)
88
+ def initialize(args, type={})
85
89
  @data = Hash[*args]
90
+ @type = type
86
91
  super(@data[:value])
87
92
  end
88
93
 
@@ -95,7 +100,12 @@ module Railstar
95
100
  end
96
101
 
97
102
  def method_missing(name, *args)
98
- @data[name.to_sym]
103
+ case @type[name]
104
+ when "integer"
105
+ @data[name.to_sym].to_i
106
+ else
107
+ @data[name.to_sym]
108
+ end
99
109
  end
100
110
  end
101
111
  end
@@ -0,0 +1,67 @@
1
+ #coding: utf-8
2
+ module ActiveRecord
3
+ module ConnectionAdapters # :nodoc:
4
+ class TableDefinition
5
+ def column(name, type, options = {})
6
+ name = name.to_s
7
+ type = type.to_sym
8
+
9
+ column = self[name] || new_column_definition(@base, name, type)
10
+
11
+ limit = options.fetch(:limit) do
12
+ native[type][:limit] if native[type].is_a?(Hash)
13
+ end
14
+
15
+ column.limit = limit
16
+ column.precision = options[:precision]
17
+ column.scale = options[:scale]
18
+ column.default = options[:default]
19
+ column.null = options[:null]
20
+ column.comment = options[:comment]
21
+ self
22
+ end
23
+ end
24
+
25
+ class ColumnDefinition
26
+ attr_accessor :comment
27
+ def to_sql
28
+ column_sql = "#{base.quote_column_name(name)} #{sql_type}"
29
+ column_options = {}
30
+ column_options[:null] = null unless null.nil?
31
+ column_options[:default] = default unless default.nil?
32
+ add_column_options!(column_sql, column_options) unless type.to_sym == :primary_key
33
+ self.comment ? "#{column_sql} COMMENT '#{self.comment}'" : column_sql
34
+ end
35
+ end
36
+
37
+ module SchemaStatement
38
+ def create_table(table_name, options = {})
39
+ td = table_definition
40
+ td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
41
+
42
+ yield td if block_given?
43
+
44
+ drop_table(table_name) if options[:force] && table_exists?(table_name)
45
+
46
+ create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
47
+ create_sql << "#{quote_table_name(table_name)} ("
48
+ create_sql << td.to_sql
49
+ create_sql << ") "
50
+ create_sql << " COMMENT='#{options[:comment]}'" if options[:comment]
51
+ create_sql << " #{options[:options]}"
52
+ execute create_sql
53
+ end
54
+ end
55
+
56
+ class Mysql2Adapter
57
+ def add_column_options!(sql, options) #:nodoc:
58
+ sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
59
+ # must explicitly check for :null to allow change_column to work on migrations
60
+ sql << " NOT NULL" if options[:null] == false
61
+ sql << " COMMENT '#{options[:comment]}'" if !options[:comment].blank?
62
+ sql
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Railstar
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/railstar.rb CHANGED
@@ -7,6 +7,8 @@ ActionView::Base.send(:include, Railstar::Helper)
7
7
  require 'railstar/active_record_ext'
8
8
  ActiveRecord::Base.send(:include, Railstar::ActiveRecordExt)
9
9
 
10
+ #require 'railstar/column_comment' if /mysql/i =~ Rails.configuration.database_configuration[Rails.env]["adapter"]
11
+
10
12
  module Railstar
11
13
  def self.env
12
14
  @env ||= load_env
@@ -9,6 +9,14 @@ development:
9
9
  pool: 5
10
10
  timeout: 5000
11
11
 
12
+ nightly:
13
+ adapter: mysql2
14
+ database: railstar
15
+ pool: 5
16
+ user: root
17
+ password:
18
+
19
+
12
20
  # Warning: The database defined as "test" will be erased and
13
21
  # re-generated from your development database when you run "rake".
14
22
  # Do not set this db to the same as development or production.