padrino-gen 0.16.0.pre4 → 0.16.0

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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/bin/padrino-gen +4 -4
  4. data/lib/padrino-gen/command.rb +2 -2
  5. data/lib/padrino-gen/generators/actions.rb +68 -64
  6. data/lib/padrino-gen/generators/app/app.rb.tt +6 -6
  7. data/lib/padrino-gen/generators/app.rb +19 -19
  8. data/lib/padrino-gen/generators/cli.rb +16 -19
  9. data/lib/padrino-gen/generators/component.rb +18 -19
  10. data/lib/padrino-gen/generators/components/actions.rb +42 -42
  11. data/lib/padrino-gen/generators/components/mocks/mocha.rb +7 -7
  12. data/lib/padrino-gen/generators/components/mocks/rr.rb +7 -7
  13. data/lib/padrino-gen/generators/components/orms/activerecord.rb +158 -156
  14. data/lib/padrino-gen/generators/components/orms/couchrest.rb +33 -33
  15. data/lib/padrino-gen/generators/components/orms/datamapper.rb +108 -103
  16. data/lib/padrino-gen/generators/components/orms/dynamoid.rb +40 -40
  17. data/lib/padrino-gen/generators/components/orms/minirecord.rb +114 -114
  18. data/lib/padrino-gen/generators/components/orms/mongoid.rb +65 -65
  19. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +20 -20
  20. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +63 -59
  21. data/lib/padrino-gen/generators/components/orms/ohm.rb +49 -47
  22. data/lib/padrino-gen/generators/components/orms/ripple.rb +45 -45
  23. data/lib/padrino-gen/generators/components/orms/sequel.rb +51 -46
  24. data/lib/padrino-gen/generators/components/renderers/erb.rb +1 -1
  25. data/lib/padrino-gen/generators/components/renderers/liquid.rb +1 -1
  26. data/lib/padrino-gen/generators/components/scripts/dojo.rb +6 -6
  27. data/lib/padrino-gen/generators/components/scripts/extcore.rb +6 -6
  28. data/lib/padrino-gen/generators/components/scripts/jquery.rb +6 -6
  29. data/lib/padrino-gen/generators/components/scripts/mootools.rb +6 -6
  30. data/lib/padrino-gen/generators/components/scripts/prototype.rb +8 -8
  31. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
  32. data/lib/padrino-gen/generators/components/stylesheets/less.rb +4 -4
  33. data/lib/padrino-gen/generators/components/tests/bacon.rb +66 -66
  34. data/lib/padrino-gen/generators/components/tests/cucumber.rb +61 -61
  35. data/lib/padrino-gen/generators/components/tests/minitest.rb +70 -70
  36. data/lib/padrino-gen/generators/components/tests/rspec.rb +74 -74
  37. data/lib/padrino-gen/generators/components/tests/shoulda.rb +72 -72
  38. data/lib/padrino-gen/generators/components/tests/testunit.rb +69 -69
  39. data/lib/padrino-gen/generators/controller.rb +16 -17
  40. data/lib/padrino-gen/generators/helper.rb +8 -9
  41. data/lib/padrino-gen/generators/mailer.rb +8 -9
  42. data/lib/padrino-gen/generators/migration.rb +6 -6
  43. data/lib/padrino-gen/generators/model.rb +20 -21
  44. data/lib/padrino-gen/generators/plugin.rb +9 -9
  45. data/lib/padrino-gen/generators/project/config/apps.rb.tt +4 -4
  46. data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
  47. data/lib/padrino-gen/generators/project/config.ru +1 -1
  48. data/lib/padrino-gen/generators/project.rb +49 -51
  49. data/lib/padrino-gen/generators/runner.rb +25 -24
  50. data/lib/padrino-gen/generators/task.rb +7 -8
  51. data/lib/padrino-gen/generators/templates/Gemfile.tt +5 -5
  52. data/lib/padrino-gen/generators/templates/controller.rb.tt +3 -3
  53. data/lib/padrino-gen/generators/templates/mailer.rb.tt +15 -15
  54. data/lib/padrino-gen/generators/templates/project_bin.tt +1 -1
  55. data/lib/padrino-gen/generators/templates/task.rb.tt +1 -1
  56. data/lib/padrino-gen/padrino-tasks/activerecord.rb +152 -160
  57. data/lib/padrino-gen/padrino-tasks/database.rb +2 -2
  58. data/lib/padrino-gen/padrino-tasks/datamapper.rb +31 -31
  59. data/lib/padrino-gen/padrino-tasks/minirecord.rb +3 -3
  60. data/lib/padrino-gen/padrino-tasks/mongoid.rb +39 -41
  61. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +18 -14
  62. data/lib/padrino-gen/padrino-tasks/sequel.rb +28 -28
  63. data/lib/padrino-gen/padrino-tasks/sql-helpers.rb +45 -45
  64. data/lib/padrino-gen.rb +4 -4
  65. data/padrino-gen.gemspec +19 -19
  66. data/test/fixtures/admin_template.rb +5 -5
  67. data/test/fixtures/database_template.rb +19 -22
  68. data/test/fixtures/example_template.rb +8 -8
  69. data/test/fixtures/git_template.rb +2 -2
  70. data/test/fixtures/plugin_template.rb +3 -3
  71. data/test/fixtures/rake_template.rb +5 -5
  72. data/test/helper.rb +23 -21
  73. data/test/test_app_generator.rb +13 -13
  74. data/test/test_cli.rb +4 -5
  75. data/test/test_component_generator.rb +17 -17
  76. data/test/test_controller_generator.rb +62 -63
  77. data/test/test_generator.rb +6 -6
  78. data/test/test_helper_generator.rb +23 -24
  79. data/test/test_mailer_generator.rb +7 -7
  80. data/test/test_migration_generator.rb +31 -31
  81. data/test/test_model_generator.rb +80 -80
  82. data/test/test_plugin_generator.rb +35 -36
  83. data/test/test_project_generator.rb +171 -169
  84. data/test/test_sql_helpers.rb +49 -50
  85. data/test/test_task_generator.rb +13 -13
  86. metadata +10 -10
@@ -1,46 +1,46 @@
1
- COUCHREST = (<<-COUCHREST) unless defined?(COUCHREST)
2
- case Padrino.env
3
- when :development then db_name = '!NAME!_development'
4
- when :production then db_name = '!NAME!_production'
5
- when :test then db_name = '!NAME!_test'
6
- end
1
+ COUCHREST = <<~COUCHREST unless defined?(COUCHREST)
2
+ case Padrino.env
3
+ when :development then db_name = '!NAME!_development'
4
+ when :production then db_name = '!NAME!_production'
5
+ when :test then db_name = '!NAME!_test'
6
+ end
7
7
 
8
- CouchRest::Model::Base.configure do |conf|
9
- conf.model_type_key = 'type' # compatibility with CouchModel 1.1
10
- conf.database = CouchRest.database!(db_name)
11
- conf.environment = Padrino.env
12
- # conf.connection = {
13
- # :protocol => 'http',
14
- # :host => 'localhost',
15
- # :port => '5984',
16
- # :prefix => 'padrino',
17
- # :suffix => nil,
18
- # :join => '_',
19
- # :username => nil,
20
- # :password => nil
21
- # }
22
- end
8
+ CouchRest::Model::Base.configure do |conf|
9
+ conf.model_type_key = 'type' # compatibility with CouchModel 1.1
10
+ conf.database = CouchRest.database!(db_name)
11
+ conf.environment = Padrino.env
12
+ # conf.connection = {
13
+ # protocol: 'http',
14
+ # host: 'localhost',
15
+ # port: '5984',
16
+ # prefix: 'padrino',
17
+ # suffix: nil,
18
+ # join: '_',
19
+ # username: nil,
20
+ # password: nil
21
+ # }
22
+ end
23
23
  COUCHREST
24
24
 
25
25
  def setup_orm
26
- require_dependencies 'couchrest_model', :version => '~>1.1.0'
26
+ require_dependencies 'couchrest_model', version: '~>1.1.0'
27
27
  require_dependencies 'json_pure'
28
- create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, @project_name.underscore))
28
+ create_file('config/database.rb', COUCHREST.gsub(/!NAME!/, @project_name.underscore))
29
29
  end
30
30
 
31
- CR_MODEL = (<<-MODEL) unless defined?(CR_MODEL)
32
- class !NAME! < CouchRest::Model::Base
33
- unique_id :id
34
- # property <name>
35
- !FIELDS!
36
- end
31
+ CR_MODEL = <<~MODEL unless defined?(CR_MODEL)
32
+ class !NAME! < CouchRest::Model::Base
33
+ unique_id :id
34
+ # property <name>
35
+ !FIELDS!
36
+ end
37
37
  MODEL
38
38
 
39
- # options => { :fields => ["title:string", "body:string"], :app => 'app' }
40
- def create_model_file(name, options={})
39
+ # options => { fields: ['title:string', 'body:string'], app: 'app' }
40
+ def create_model_file(name, options = {})
41
41
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
42
- field_tuples = options[:fields].map { |value| value.split(":") }
43
- column_declarations = field_tuples.map { |field, kind| "property :#{field}" }.join("\n ")
42
+ field_tuples = options[:fields].map { |value| value.split(':') }
43
+ column_declarations = field_tuples.map { |field, _kind| "property :#{field}" }.join("\n ")
44
44
  model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
45
45
  model_contents.gsub!(/!FIELDS!/, column_declarations)
46
46
  create_file(model_path, model_contents)
@@ -1,65 +1,65 @@
1
- DM = (<<-DM) unless defined?(DM)
2
- ##
3
- # A MySQL connection:
4
- # DataMapper.setup(:default, 'mysql://user:password@localhost/the_database_name')
5
- #
6
- # # A Postgres connection:
7
- # DataMapper.setup(:default, 'postgres://user:password@localhost/the_database_name')
8
- #
9
- # # A Sqlite3 connection
10
- # DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "development.db"))
11
- #
12
- # # Setup DataMapper using config/database.yml
13
- # DataMapper.setup(:default, YAML.load_file(Padrino.root('config/database.yml'))[RACK_ENV])
14
- #
15
- # config/database.yml file:
16
- #
17
- # ---
18
- # development: &defaults
19
- # adapter: mysql
20
- # database: example_development
21
- # username: user
22
- # password: Pa55w0rd
23
- # host: 127.0.0.1
24
- #
25
- # test:
26
- # <<: *defaults
27
- # database: example_test
28
- #
29
- # production:
30
- # <<: *defaults
31
- # database: example_production
32
- #
33
-
34
- DataMapper.logger = logger
35
- DataMapper::Property::String.length(255)
36
-
37
- case Padrino.env
38
- when :development then DataMapper.setup(:default, !DB_DEVELOPMENT!)
39
- when :production then DataMapper.setup(:default, !DB_PRODUCTION!)
40
- when :test then DataMapper.setup(:default, !DB_TEST!)
41
- end
1
+ DM = <<~DM unless defined?(DM)
2
+ ##
3
+ # A MySQL connection:
4
+ # DataMapper.setup(:default, 'mysql://user:password@localhost/the_database_name')
5
+ #
6
+ # # A Postgres connection:
7
+ # DataMapper.setup(:default, 'postgres://user:password@localhost/the_database_name')
8
+ #
9
+ # # A Sqlite3 connection
10
+ # DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "development.db"))
11
+ #
12
+ # # Setup DataMapper using config/database.yml
13
+ # DataMapper.setup(:default, YAML.load_file(Padrino.root('config/database.yml'))[RACK_ENV])
14
+ #
15
+ # config/database.yml file:
16
+ #
17
+ # ---
18
+ # development: &defaults
19
+ # adapter: mysql
20
+ # database: example_development
21
+ # username: user
22
+ # password: Pa55w0rd
23
+ # host: 127.0.0.1
24
+ #
25
+ # test:
26
+ # <<: *defaults
27
+ # database: example_test
28
+ #
29
+ # production:
30
+ # <<: *defaults
31
+ # database: example_production
32
+ #
33
+
34
+ DataMapper.logger = logger
35
+ DataMapper::Property::String.length(255)
36
+
37
+ case Padrino.env
38
+ when :development then DataMapper.setup(:default, !DB_DEVELOPMENT!)
39
+ when :production then DataMapper.setup(:default, !DB_PRODUCTION!)
40
+ when :test then DataMapper.setup(:default, !DB_TEST!)
41
+ end
42
42
  DM
43
43
 
44
- IDENTITY_MAP_MIDDLEWARE = <<-MIDDLEWARE
45
- class IdentityMap
46
- def initialize(app, name = :default)
47
- @app = app
48
- @name = name.to_sym
49
- end
44
+ IDENTITY_MAP_MIDDLEWARE = <<~MIDDLEWARE
45
+ class IdentityMap
46
+ def initialize(app, name = :default)
47
+ @app = app
48
+ @name = name.to_sym
49
+ end
50
50
 
51
- def call(env)
52
- ::DataMapper.repository(@name) do
53
- @app.call(env)
51
+ def call(env)
52
+ ::DataMapper.repository(@name) do
53
+ @app.call(env)
54
+ end
54
55
  end
55
56
  end
56
- end
57
57
  MIDDLEWARE
58
58
 
59
59
  def setup_orm
60
60
  dm = DM
61
61
  db = @project_name.underscore
62
- %w(
62
+ %w[
63
63
  dm-core
64
64
  dm-types
65
65
  dm-aggregates
@@ -67,99 +67,104 @@ def setup_orm
67
67
  dm-migrations
68
68
  dm-timestamps
69
69
  dm-validations
70
- ).each { |dep| require_dependencies dep }
70
+ ].each { |dep| require_dependencies dep }
71
71
 
72
72
  begin
73
73
  case adapter ||= options[:adapter]
74
74
  when 'mysql', 'mysql2'
75
- dm.gsub!(/!DB_DEVELOPMENT!/,"\"mysql://root@localhost/#{db}_development\"")
76
- dm.gsub!(/!DB_PRODUCTION!/,"\"mysql://root@localhost/#{db}_production\"")
77
- dm.gsub!(/!DB_TEST!/,"\"mysql://root@localhost/#{db}_test\"")
75
+ dm.gsub!(/!DB_DEVELOPMENT!/, "\"mysql://root@localhost/#{db}_development\"")
76
+ dm.gsub!(/!DB_PRODUCTION!/, "\"mysql://root@localhost/#{db}_production\"")
77
+ dm.gsub!(/!DB_TEST!/, "\"mysql://root@localhost/#{db}_test\"")
78
78
  require_dependencies 'dm-mysql-adapter'
79
79
  when 'postgres'
80
- dm.gsub!(/!DB_DEVELOPMENT!/,"\"postgres://root@localhost/#{db}_development\"")
81
- dm.gsub!(/!DB_PRODUCTION!/,"\"postgres://root@localhost/#{db}_production\"")
82
- dm.gsub!(/!DB_TEST!/,"\"postgres://root@localhost/#{db}_test\"")
80
+ dm.gsub!(/!DB_DEVELOPMENT!/, "\"postgres://root@localhost/#{db}_development\"")
81
+ dm.gsub!(/!DB_PRODUCTION!/, "\"postgres://root@localhost/#{db}_production\"")
82
+ dm.gsub!(/!DB_TEST!/, "\"postgres://root@localhost/#{db}_test\"")
83
83
  require_dependencies 'dm-postgres-adapter'
84
84
  when 'sqlite'
85
- dm.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite3://\" + Padrino.root('db', \"#{db}_development.db\")")
86
- dm.gsub!(/!DB_PRODUCTION!/,"\"sqlite3://\" + Padrino.root('db', \"#{db}_production.db\")")
87
- dm.gsub!(/!DB_TEST!/,"\"sqlite3://\" + Padrino.root('db', \"#{db}_test.db\")")
85
+ dm.gsub!(/!DB_DEVELOPMENT!/, "\"sqlite3://\" + Padrino.root('db', \"#{db}_development.db\")")
86
+ dm.gsub!(/!DB_PRODUCTION!/, "\"sqlite3://\" + Padrino.root('db', \"#{db}_production.db\")")
87
+ dm.gsub!(/!DB_TEST!/, "\"sqlite3://\" + Padrino.root('db', \"#{db}_test.db\")")
88
88
  require_dependencies 'dm-sqlite-adapter'
89
89
  else
90
90
  say "Failed to generate `config/database.rb` for ORM adapter `#{options[:adapter]}`", :red
91
- fail ArgumentError
91
+ raise ArgumentError
92
92
  end
93
93
  rescue ArgumentError
94
- adapter = ask("Please, choose a proper adapter:", :limited_to => %w[mysql mysql2 postgres sqlite])
94
+ adapter = ask('Please, choose a proper adapter:', limited_to: %w[mysql mysql2 postgres sqlite])
95
95
  retry
96
96
  end
97
97
 
98
- create_file("config/database.rb", dm)
99
- insert_hook("DataMapper.finalize", :after_load)
98
+ create_file('config/database.rb', dm)
99
+ insert_hook('DataMapper.finalize', :after_load)
100
100
  middleware :identity_map, IDENTITY_MAP_MIDDLEWARE
101
101
  end
102
102
 
103
- DM_MODEL = (<<-MODEL) unless defined?(DM_MODEL)
104
- class !NAME!
105
- include DataMapper::Resource
103
+ DM_MODEL = <<~MODEL unless defined?(DM_MODEL)
104
+ class !NAME!
105
+ include DataMapper::Resource
106
106
 
107
- # property <name>, <type>
108
- property :id, Serial
109
- !FIELDS!
110
- end
107
+ # property <name>, <type>
108
+ property :id, Serial
109
+ !FIELDS!
110
+ end
111
111
  MODEL
112
112
 
113
- # options => { :fields => ["title:string", "body:string"], :app => 'app' }
114
- def create_model_file(name, options={})
113
+ # options => { fields: ['title:string', 'body:string'], app: 'app' }
114
+ def create_model_file(name, options = {})
115
115
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
116
116
  model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
117
- field_tuples = options[:fields].map { |value| value.split(":") }
117
+ field_tuples = options[:fields].map { |value| value.split(':') }
118
118
  field_tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
119
- column_declarations = field_tuples.map { |field, kind|"property :#{field}, #{kind.underscore.camelize}" }.join("\n ")
119
+ column_declarations = field_tuples.map { |field, kind| "property :#{field}, #{kind.underscore.camelize}" }.join("\n ")
120
120
  model_contents.gsub!(/!FIELDS!/, column_declarations)
121
121
  create_file(model_path, model_contents)
122
122
  end
123
123
 
124
- DM_MIGRATION = (<<-MIGRATION) unless defined?(DM_MIGRATION)
125
- migration !VERSION!, :!FILENAME! do
126
- up do
127
- !UP!
128
- end
124
+ DM_MIGRATION = <<~MIGRATION unless defined?(DM_MIGRATION)
125
+ migration !VERSION!, :!FILENAME! do
126
+ up do
127
+ !UP!
128
+ end
129
129
 
130
- down do
131
- !DOWN!
130
+ down do
131
+ !DOWN!
132
+ end
132
133
  end
133
- end
134
134
  MIGRATION
135
135
 
136
- DM_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(DM_MODEL_UP_MG)
137
- create_table :!TABLE! do
138
- column :id, Integer, :serial => true
139
- !FIELDS!
140
- end
136
+ DM_MODEL_UP_MG = <<~MIGRATION.gsub(/^/, ' ') unless defined?(DM_MODEL_UP_MG)
137
+ create_table :!TABLE! do
138
+ column :id, Integer, serial: true
139
+ !FIELDS!
140
+ end
141
141
  MIGRATION
142
142
 
143
- DM_MODEL_DOWN_MG = (<<-MIGRATION) unless defined?(DM_MODEL_DOWN_MG)
144
- drop_table :!TABLE!
143
+ DM_MODEL_DOWN_MG = <<~MIGRATION unless defined?(DM_MODEL_DOWN_MG)
144
+ drop_table :!TABLE!
145
145
  MIGRATION
146
146
 
147
147
  def create_model_migration(migration_name, name, columns)
148
- output_model_migration(migration_name, name, columns,
149
- :column_format => Proc.new { |field, kind| "column :#{field}, DataMapper::Property::#{kind.classify}#{', :length => 255' if kind =~ /string/i}" },
150
- :base => DM_MIGRATION, :up => DM_MODEL_UP_MG, :down => DM_MODEL_DOWN_MG)
148
+ output_model_migration(
149
+ migration_name, name, columns,
150
+ column_format: proc { |field, kind| "column :#{field}, DataMapper::Property::#{kind.classify}#{', length: 255' if kind =~ /string/i}" },
151
+ base: DM_MIGRATION,
152
+ up: DM_MODEL_UP_MG,
153
+ down: DM_MODEL_DOWN_MG
154
+ )
151
155
  end
152
156
 
153
- DM_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(DM_CHANGE_MG)
154
- modify_table :!TABLE! do
155
- !COLUMNS!
156
- end
157
+ DM_CHANGE_MG = <<~MIGRATION.gsub(/^/, ' ') unless defined?(DM_CHANGE_MG)
158
+ modify_table :!TABLE! do
159
+ !COLUMNS!
160
+ end
157
161
  MIGRATION
158
162
 
159
163
  def create_migration_file(migration_name, name, columns)
160
- output_migration_file(migration_name, name, columns,
161
- :base => DM_MIGRATION, :change_format => DM_CHANGE_MG,
162
- :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.classify}" },
163
- :remove => Proc.new { |field, kind| "drop_column :#{field}" }
164
+ output_migration_file(
165
+ migration_name, name, columns,
166
+ base: DM_MIGRATION, change_format: DM_CHANGE_MG,
167
+ add: proc { |field, kind| "add_column :#{field}, #{kind.classify}" },
168
+ remove: proc { |field, _kind| "drop_column :#{field}" }
164
169
  )
165
170
  end
@@ -1,57 +1,57 @@
1
- DYNAMOID = (<<-DYNAMOID) unless defined?(DYNAMOID)
1
+ DYNAMOID = <<~DYNAMOID unless defined?(DYNAMOID)
2
2
 
3
- AWS.config({
4
- :access_key_id => ENV['AWS_ACCESS_KEY'],
5
- :secret_access_key => ENV['AWS_SECRET_KEY'],
6
- :dynamo_db_endpoint => 'dynamodb.ap-southeast-1.amazonaws.com'
7
- })
3
+ AWS.config(
4
+ access_key_id: ENV['AWS_ACCESS_KEY'],
5
+ secret_access_key: ENV['AWS_SECRET_KEY'],
6
+ dynamo_db_endpoint: 'dynamodb.ap-southeast-1.amazonaws.com'
7
+ )
8
8
 
9
- Dynamoid.configure do |config|
10
- config.adapter = 'aws_sdk' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem.
11
- config.read_capacity = 100 # Read capacity for your tables
12
- config.write_capacity = 20 # Write capacity for your tables
13
- end
9
+ Dynamoid.configure do |config|
10
+ config.adapter = 'aws_sdk' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem.
11
+ config.read_capacity = 100 # Read capacity for your tables
12
+ config.write_capacity = 20 # Write capacity for your tables
13
+ end
14
14
 
15
- # If you use mock in testing [for example in case of using fake_dynamo],
16
- # the way is as following:
17
- #
18
- # - install fake_dynamo
19
- # gem install fake_dynamo --version 0.1.3
20
- # - run
21
- # fake_dynamo --port 4567
22
- #
23
- # And then setting for AWS.config is as following:
24
- #
25
- # AWS.config({
26
- # :access_key_id => 'xxx', # everything is ok
27
- # :secret_access_key => 'xxx', # everything is ok
28
- # :dynamo_db_endpoint => 'localhost', # fake_dynamo runs hostname
29
- # :dynamo_db_port => 4567, # fake_dynamo listens port
30
- # :use_ssl => false # fake_dynamo don't speak ssl
31
- # })
32
- #
33
- # Additional information on https://github.com/ananthakumaran/fake_dynamo
15
+ # If you use mock in testing [for example in case of using fake_dynamo],
16
+ # the way is as following:
17
+ #
18
+ # - install fake_dynamo
19
+ # gem install fake_dynamo --version 0.1.3
20
+ # - run
21
+ # fake_dynamo --port 4567
22
+ ##{' '}
23
+ # And then setting for AWS.config is as following:
24
+ ##{' '}
25
+ # AWS.config({
26
+ # access_key_id: 'xxx', # everything is ok
27
+ # secret_access_key: 'xxx', # everything is ok
28
+ # dynamo_db_endpoint: 'localhost', # fake_dynamo runs hostname
29
+ # dynamo_db_port: 4567, # fake_dynamo listens port
30
+ # use_ssl: false # fake_dynamo don't speak ssl
31
+ # })
32
+ #
33
+ # Additional information on https://github.com/ananthakumaran/fake_dynamo
34
34
  DYNAMOID
35
35
 
36
36
  def setup_orm
37
37
  require_dependencies 'aws-sdk'
38
- require_dependencies 'dynamoid', :version => '~>0.7.1'
39
- create_file("config/database.rb", DYNAMOID.gsub(/!NAME!/, @project_name.underscore))
38
+ require_dependencies 'dynamoid', version: '~>0.7.1'
39
+ create_file('config/database.rb', DYNAMOID.gsub(/!NAME!/, @project_name.underscore))
40
40
  end
41
41
 
42
- DYNAMOID_MODEL = (<<-MODEL) unless defined?(DYNAMOID_MODEL)
43
- class !NAME!
44
- include Dynamoid::Document
42
+ DYNAMOID_MODEL = <<~MODEL unless defined?(DYNAMOID_MODEL)
43
+ class !NAME!
44
+ include Dynamoid::Document
45
45
 
46
- !FIELDS!
46
+ !FIELDS!
47
47
 
48
- end
48
+ end
49
49
  MODEL
50
50
 
51
- # options => { :fields => ["title:string", "body:string"], :app => 'app' }
52
- def create_model_file(name, options={})
51
+ # options => { fields: ['title:string', 'body:string'], app: 'app' }
52
+ def create_model_file(name, options = {})
53
53
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
54
- field_tuples = options[:fields].map { |value| value.split(":") }
54
+ field_tuples = options[:fields].map { |value| value.split(':') }
55
55
  column_declarations = field_tuples.map { |field, kind| "field :#{field}, :#{kind}" }.join("\n ")
56
56
  model_contents = DYNAMOID_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
57
57
  model_contents.gsub!(/!FIELDS!/, column_declarations)