From 8cb083927e2e7de2bd838aa98841eefceeb6ebdb Mon Sep 17 00:00:00 2001 From: Arthur Chiu Date: Sun, 29 Mar 2026 15:10:52 -0700 Subject: [PATCH 1/2] chore: remove deprecated ORM generators (DataMapper, MongoMapper, CouchRest, Ripple) --- padrino-admin/README.rdoc | 2 +- padrino-admin/lib/padrino-admin.rb | 2 +- .../lib/padrino-admin/generators/actions.rb | 2 +- .../lib/padrino-admin/generators/admin_app.rb | 3 +- .../lib/padrino-admin/generators/orm.rb | 38 +--- .../templates/account/couchrest.rb.tt | 67 ------- .../templates/account/datamapper.rb.tt | 61 ------- .../templates/account/mongomapper.rb.tt | 47 ----- .../templates/erb/app/base/index.erb.tt | 2 +- .../templates/haml/app/base/index.haml.tt | 2 +- .../templates/slim/app/base/index.slim.tt | 2 +- .../test_account_model_generator.rb | 35 ---- .../generators/test_admin_app_generator.rb | 23 +-- padrino-core/lib/padrino-core/loader.rb | 2 +- padrino-gen/README.rdoc | 4 +- .../lib/padrino-gen/generators/actions.rb | 2 +- .../generators/components/orms/couchrest.rb | 55 ------ .../generators/components/orms/datamapper.rb | 170 ------------------ .../generators/components/orms/mongomapper.rb | 44 ----- .../generators/components/orms/ripple.rb | 75 -------- .../padrino-gen/padrino-tasks/datamapper.rb | 96 ---------- .../padrino-gen/padrino-tasks/mongomapper.rb | 59 ------ padrino-gen/test/test_migration_generator.rb | 45 ----- padrino-gen/test/test_model_generator.rb | 124 +------------ padrino-gen/test/test_project_generator.rb | 72 +------- .../test/fixtures/apps/.components | 2 +- 26 files changed, 27 insertions(+), 1009 deletions(-) delete mode 100644 padrino-admin/lib/padrino-admin/generators/templates/account/couchrest.rb.tt delete mode 100644 padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt delete mode 100644 padrino-admin/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt delete mode 100644 padrino-gen/lib/padrino-gen/generators/components/orms/couchrest.rb delete mode 100644 padrino-gen/lib/padrino-gen/generators/components/orms/datamapper.rb delete mode 100644 padrino-gen/lib/padrino-gen/generators/components/orms/mongomapper.rb delete mode 100644 padrino-gen/lib/padrino-gen/generators/components/orms/ripple.rb delete mode 100644 padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb delete mode 100644 padrino-gen/lib/padrino-gen/padrino-tasks/mongomapper.rb diff --git a/padrino-admin/README.rdoc b/padrino-admin/README.rdoc index 6a63931ba..c68d7ff47 100644 --- a/padrino-admin/README.rdoc +++ b/padrino-admin/README.rdoc @@ -4,7 +4,7 @@ Padrino has a beautiful Admin management dashboard with these features: -Orm Agnostic:: Data Adapters for Datamapper, Activerecord, Sequel, Mongomapper, Mongoid, Couchrest, Dynamoid +Orm Agnostic:: Data Adapters for Activerecord, Sequel, Mongoid, Ohm, Dynamoid Template Agnostic:: Erb, Erubis and Haml Renderer Authentication:: Support for Account authentication, Account Permission management Scaffold:: You can simply create a new "admin interface" by providing a Model diff --git a/padrino-admin/lib/padrino-admin.rb b/padrino-admin/lib/padrino-admin.rb index 487947b82..da904d255 100644 --- a/padrino-admin/lib/padrino-admin.rb +++ b/padrino-admin/lib/padrino-admin.rb @@ -8,7 +8,7 @@ module Padrino ## # Padrino::Admin is beautiful Ajax Admin, with these features: # - # Orm Agnostic:: Adapters for datamapper, activerecord, mongomapper, couchdb (now only: datamapper and activerecord), ohm + # Orm Agnostic:: Adapters for activerecord, sequel, mongoid, ohm, and more # Authentication:: Support for Account authentication, Account Permission management # Scaffold:: You can simply create a new "admin interface" simply providing a Model # Ajax Uploads:: You can upload file, manage them and attach them to any model in a quick and simple way (coming soon) diff --git a/padrino-admin/lib/padrino-admin/generators/actions.rb b/padrino-admin/lib/padrino-admin/generators/actions.rb index 8e6ab91bb..bd70dc113 100644 --- a/padrino-admin/lib/padrino-admin/generators/actions.rb +++ b/padrino-admin/lib/padrino-admin/generators/actions.rb @@ -27,7 +27,7 @@ def ext # Tell us for now which orm we support # def supported_orm - %i[minirecord datamapper activerecord mongomapper mongoid couchrest sequel ohm dynamoid] + %i[minirecord activerecord mongoid sequel ohm dynamoid] end ## diff --git a/padrino-admin/lib/padrino-admin/generators/admin_app.rb b/padrino-admin/lib/padrino-admin/generators/admin_app.rb index ef27b27a8..05e2312bf 100644 --- a/padrino-admin/lib/padrino-admin/generators/admin_app.rb +++ b/padrino-admin/lib/padrino-admin/generators/admin_app.rb @@ -78,7 +78,6 @@ def create_admin unless options[:destroy] insert_middleware 'ConnectionPoolManagement', @admin_path if %i[minirecord activerecord].include?(orm) - insert_middleware 'IdentityMap', @admin_path if orm == :datamapper end params = [ @@ -147,7 +146,7 @@ def create_admin instructions = [] instructions << "Run 'bundle'" - if %i[activerecord datamapper sequel].include?(orm) + if %i[activerecord sequel].include?(orm) instructions << "Run 'bundle exec rake db:create' if you have not created a database yet" instructions << "Run 'bundle exec rake db:migrate'" end diff --git a/padrino-admin/lib/padrino-admin/generators/orm.rb b/padrino-admin/lib/padrino-admin/generators/orm.rb index 8409c3a8d..7c48e32bc 100644 --- a/padrino-admin/lib/padrino-admin/generators/orm.rb +++ b/padrino-admin/lib/padrino-admin/generators/orm.rb @@ -33,7 +33,7 @@ def activerecord? end def field_type(type) - type = :string if type.nil? # couchrest-Hack to avoid the next line to fail + type = :string if type.nil? type = type.to_s.demodulize.downcase.to_sym unless type.is_a?(Symbol) case type @@ -52,10 +52,7 @@ def columns case orm when :activerecord then @klass.columns when :minirecord then @klass.columns - when :datamapper then @klass.properties.map { |p| dm_column(p) } - when :couchrest then @klass.properties when :mongoid then @klass.fields.values.reject { |col| %w[_id _type].include?(col.name) } - when :mongomapper then @klass.keys.values.reject { |key| key.name == '_id' } # On MongoMapper keys are an hash when :sequel then @klass.db_schema.map { |k, v| v[:type] = :text if v[:db_type] =~ /^text/i; Column.new(k, v[:type]) } when :ohm then @klass.attributes.map { |a| Column.new(a.to_s, :string) } # ohm has strings when :dynamoid then @klass.attributes.map { |k, v| Column.new(k.to_s, v[:type]) } @@ -63,25 +60,6 @@ def columns end end - def dm_column(property) - case property - when DataMapper::Property::Text - Column.new(property.name, :text) - when DataMapper::Property::Boolean - Column.new(property.name, :boolean) - when DataMapper::Property::Integer - Column.new(property.name, :integer) - when DataMapper::Property::Decimal - Column.new(property.name, :decimal) - when DataMapper::Property::Float - Column.new(property.name, :float) - when DataMapper::Property::String - Column.new(property.name, :string) - else # if all fails, lets assume its string-ish - Column.new(property.name, :string) - end - end - def column_fields excluded_columns = %w[created_at updated_at] << (orm == :mongoid ? '_id' : 'id') column_fields = columns.dup @@ -97,8 +75,7 @@ def all def find(params = nil) case orm - when :activerecord, :minirecord, :mongomapper, :mongoid, :dynamoid then "#{klass_name}.find(#{params})" - when :datamapper, :couchrest then "#{klass_name}.get(#{params})" + when :activerecord, :minirecord, :mongoid, :dynamoid then "#{klass_name}.find(#{params})" when :sequel, :ohm then "#{klass_name}[#{params}]" else raise OrmError, "Adapter #{orm} is not yet supported!" end @@ -118,8 +95,8 @@ def save def update_attributes(params = nil) case orm - when :mongomapper, :mongoid, :couchrest, :dynamoid then "@#{name_singular}.update_attributes(#{params})" - when :activerecord, :minirecord, :datamapper, :ohm then "@#{name_singular}.update(#{params})" + when :mongoid, :dynamoid then "@#{name_singular}.update_attributes(#{params})" + when :activerecord, :minirecord, :ohm then "@#{name_singular}.update(#{params})" when :sequel then "@#{name_singular}.modified! && @#{name_singular}.update(#{params})" else raise OrmError, "Adapter #{orm} is not yet supported!" end @@ -132,10 +109,8 @@ def destroy def find_by_ids(params = nil) case orm when :ohm then "#{klass_name}.fetch(#{params})" - when :datamapper then "#{klass_name}.all(id: #{params})" when :sequel then "#{klass_name}.where(id: #{params})" when :mongoid then "#{klass_name}.find(#{params})" - when :couchrest then "#{klass_name}.all(keys: #{params})" when :dynamoid then "#{klass_name}.find(#{params})" else find(params) end @@ -145,15 +120,14 @@ def multiple_destroy(params = nil) case orm when :ohm then "#{params}.each(&:delete)" when :sequel then "#{params}.destroy" - when :datamapper then "#{params}.destroy" - when :couchrest, :mongoid, :mongomapper, :dynamoid then "#{params}.each(&:destroy)" + when :mongoid, :dynamoid then "#{params}.each(&:destroy)" else "#{klass_name}.destroy #{params}" end end def has_error(field) case orm - when :datamapper, :ohm, :sequel then "@#{name_singular}.errors.key?(:#{field}) && @#{name_singular}.errors[:#{field}].count > 0" + when :ohm, :sequel then "@#{name_singular}.errors.key?(:#{field}) && @#{name_singular}.errors[:#{field}].count > 0" else "@#{name_singular}.errors.include?(:#{field})" end end diff --git a/padrino-admin/lib/padrino-admin/generators/templates/account/couchrest.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/account/couchrest.rb.tt deleted file mode 100644 index 0b513c8b3..000000000 --- a/padrino-admin/lib/padrino-admin/generators/templates/account/couchrest.rb.tt +++ /dev/null @@ -1,67 +0,0 @@ -class <%= @model_name %> < CouchRest::Model::Base - attr_accessor :password, :password_confirmation - - # Properties - property :name - property :surname - property :email - property :crypted_password - property :role - - view_by :email - - # Validations - validates_presence_of :email, :role - validates_presence_of :password, if: :password_required - validates_presence_of :password_confirmation, if: :password_required - validates_length_of :password, within: 4..40, if: :password_required - validates_confirmation_of :password, if: :password_required - validates_length_of :email, within: 3..100 - validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i - validates_format_of :role, with: /[A-Za-z]/ - validate :unique_email_validator - - # Callbacks - after_validation :encrypt_password, if: :password_required - - ## - # This method is for authentication purpose. - # - def self.authenticate(email, password) - account = find_by_email(email) - account if account&.has_password?(password) - end - - def has_password?(password) - ::BCrypt::Password.new(crypted_password) == password - end - - ## - # This method is used by AuthenticationHelper. - # - def self.find_by_id(id) - get(id) - end - - private - - def encrypt_password - self.crypted_password = ::BCrypt::Password.create(password) - end - - def password_required - crypted_password.blank? || password.present? - end - - def unique_email_validator - account = self.class.find_by_email(email) - - # Didn't find email in the database. - return if account.nil? - - # Account with same email in database is this account. - return if has_key?('_id') && self['_id'] == account['_id'] - - errors.add(:email, 'is not unique') - end -end diff --git a/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt deleted file mode 100644 index ef1450f6d..000000000 --- a/padrino-admin/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +++ /dev/null @@ -1,61 +0,0 @@ -class <%= @model_name %> - include DataMapper::Resource - include DataMapper::Validate - attr_accessor :password, :password_confirmation - - # Properties - property :id, Serial - property :name, String - property :surname, String - property :email, String - property :crypted_password, String, length: 70 - property :role, String - - # Validations - validates_presence_of :email, :role - validates_presence_of :password, if: :password_required - validates_presence_of :password_confirmation, if: :password_required - validates_length_of :password, min: 4, max: 40, if: :password_required - validates_confirmation_of :password, if: :password_required - validates_length_of :email, min: 3, max: 100 - validates_uniqueness_of :email, case_sensitive: false - validates_format_of :email, with: :email_address - validates_format_of :role, with: /[A-Za-z]/ - - # Callbacks - before :save, :encrypt_password - - ## - # This method is for authentication purpose. - # - def self.authenticate(email, password) - account = first(conditions: ['lower(email) = lower(?)', email]) if email.present? - account if account&.has_password?(password) - end - - ## - # This method is used by AuthenticationHelper - # - def self.find_by_id(id) - get(id) rescue nil - end - - def has_password?(password) - ::BCrypt::Password.new(crypted_password) == password - end - - def password=(password) - self.crypted_password = nil if password.present? - @password = password - end - - private - - def password_required - crypted_password.blank? || password.present? - end - - def encrypt_password - self.crypted_password = ::BCrypt::Password.create(password) if password.present? - end -end diff --git a/padrino-admin/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt b/padrino-admin/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt deleted file mode 100644 index 876b8f593..000000000 --- a/padrino-admin/lib/padrino-admin/generators/templates/account/mongomapper.rb.tt +++ /dev/null @@ -1,47 +0,0 @@ -class <%= @model_name %> - include MongoMapper::Document - attr_accessor :password, :password_confirmation - - # Keys - key :name, String - key :surname, String - key :email, String - key :crypted_password, String - key :role, String - - # Validations - validates_presence_of :email, :role - validates_presence_of :password, if: :password_required - validates_presence_of :password_confirmation, if: :password_required - validates_length_of :password, within: 4..40, if: :password_required - validates_confirmation_of :password, if: :password_required - validates_length_of :email, within: 3..100 - validates_uniqueness_of :email, case_sensitive: false - validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i - validates_format_of :role, with: /[A-Za-z]/ - - # Callbacks - before_save :encrypt_password, if: :password_required - - ## - # This method is for authentication purpose. - # - def self.authenticate(email, password) - account = first(email: /#{Regexp.escape(email)}/i) if email.present? - account if account&.has_password?(password) - end - - def has_password?(password) - ::BCrypt::Password.new(crypted_password) == password - end - - private - - def encrypt_password - self.crypted_password = ::BCrypt::Password.create(password) - end - - def password_required - crypted_password.blank? || password.present? - end -end diff --git a/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt b/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt index 61ddc05bf..3df240e43 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt @@ -6,7 +6,7 @@
-
<%%= tag_icon("cogs fa-2x", "Orm Agnostic") %>
+
<%%= tag_icon("cogs fa-2x", "Orm Agnostic") %>
<%%= tag_icon("group fa-2x", "Authentication") %>
<%%= tag_icon("tasks fa-2x", "Template Agnostic") %>
<%%= tag_icon("flag fa-2x", "Multi Language") %>
diff --git a/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt b/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt index 71be6b5a5..9239f8cf3 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt @@ -5,7 +5,7 @@ .base-icons .btn-group - .btn.btn-primary{title: 'Adapters for datamapper, sequel, activerecord, minirecord, mongomapper, mongoid, couchrest'} + .btn.btn-primary{title: 'Adapters for sequel, activerecord, minirecord, mongoid'} = tag_icon('cogs fa-2x', 'Orm Agnostic') .btn.btn-success{title: 'User Authentication Support, User Authorization Management'} = tag_icon('group fa-2x', 'Authentication') diff --git a/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt b/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt index fd294d19c..55d318159 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt @@ -5,7 +5,7 @@ div class="base-text" div class="base-icons" div class="btn-group" - div class="btn btn-primary" title="Adapters for datamapper, sequel, activerecord, minirecord, mongomapper, mongoid, couchrest" = tag_icon("cogs fa-2x", "Orm Agnostic") + div class="btn btn-primary" title="Adapters for sequel, activerecord, minirecord, mongoid" = tag_icon("cogs fa-2x", "Orm Agnostic") div class="btn btn-success" title="User Authentication Support, User Authorization Management" = tag_icon("group fa-2x", "Authentication") div class="btn btn-info" title="Erb, Haml, Slim Rendering Support" = tag_icon("tasks fa-2x", "Template Agnostic") div class="btn btn-warning" title="English, German, Russian, Danish, French, Brazilian and Italian localizations" = tag_icon("flag fa-2x", "Multi Language") diff --git a/padrino-admin/test/generators/test_account_model_generator.rb b/padrino-admin/test/generators/test_account_model_generator.rb index 8f547d6e6..7abc73aae 100644 --- a/padrino-admin/test/generators/test_account_model_generator.rb +++ b/padrino-admin/test/generators/test_account_model_generator.rb @@ -34,18 +34,6 @@ end end - describe 'datamapper' do - before do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper') } - capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") } - @model = "#{@apptmp}/sample_project/models/account.rb" - end - - it 'should include the datamapper resource' do - assert_match_in_file(/include DataMapper::Resource/m, @model) - end - end - describe 'mongoid' do before do capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=mongoid') } @@ -58,18 +46,6 @@ end end - describe 'mongomapper' do - before do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=mongomapper') } - capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") } - @model = "#{@apptmp}/sample_project/models/account.rb" - end - - it 'should include the mongomapper document' do - assert_match_in_file(/include MongoMapper::Document/m, @model) - end - end - describe 'ohm' do before do capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=ohm') } @@ -94,15 +70,4 @@ end end - describe 'couchrest' do - before do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=couchrest') } - capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") } - @model = "#{@apptmp}/sample_project/models/account.rb" - end - - it 'should be a couchrest model instance' do - assert_match_in_file(/class Account < CouchRest::Model::Base/m, @model) - end - end end diff --git a/padrino-admin/test/generators/test_admin_app_generator.rb b/padrino-admin/test/generators/test_admin_app_generator.rb index f40bc2faa..da6f5c481 100644 --- a/padrino-admin/test/generators/test_admin_app_generator.rb +++ b/padrino-admin/test/generators/test_admin_app_generator.rb @@ -12,8 +12,6 @@ describe 'the admin app generator' do before do - # Account gets created by Datamapper's migration and then gets - # rejected by model generator as already defined Object.send(:remove_const, :Account) if defined?(Account) end @@ -29,7 +27,7 @@ end it 'should store and apply session_secret' do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') } + capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=sequel', '-e=haml') } assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb") end @@ -192,25 +190,6 @@ assert_match_in_file(/ use ConnectionPoolManagement/m, "#{@apptmp}/sample_project/admin/app.rb") end - it 'should not add it for #datamapper' do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') } - capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") } - assert_no_match_in_file(/ use ConnectionPoolManagement/m, "#{@apptmp}/sample_project/admin/app.rb") - end - end - - describe 'datamapper middleware' do - it 'should add it for #datamapper' do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=datamapper', '-e=haml') } - capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") } - assert_match_in_file(/ use IdentityMap/m, "#{@apptmp}/sample_project/admin/app.rb") - end - - it 'should not add it for #activerecord' do - capture_io { generate(:project, 'sample_project', '-e=slim', "--root=#{@apptmp}", '-d=activerecord', '-e=haml') } - capture_io { generate(:admin_app, "--root=#{@apptmp}/sample_project") } - assert_no_match_in_file(/ use IdentityMap/m, "#{@apptmp}/sample_project/admin/app.rb") - end end it 'should not conflict with existing seeds file' do diff --git a/padrino-core/lib/padrino-core/loader.rb b/padrino-core/lib/padrino-core/loader.rb index 81a3e580a..2b72917c5 100644 --- a/padrino-core/lib/padrino-core/loader.rb +++ b/padrino-core/lib/padrino-core/loader.rb @@ -31,7 +31,7 @@ def before_load(&block) # # @example # after_load do - # DataMapper.finalize + # SomeORM.finalize # end # def after_load(&block) diff --git a/padrino-gen/README.rdoc b/padrino-gen/README.rdoc index b0037d74c..40cb870c8 100644 --- a/padrino-gen/README.rdoc +++ b/padrino-gen/README.rdoc @@ -30,7 +30,7 @@ setup performed for the default components. You can define specific components to be used: - $ padrino-gen project demo_project -t rspec -r haml -m rr -s jquery -d datamapper + $ padrino-gen project demo_project -t rspec -r haml -m rr -s jquery -d sequel You can also instruct the generator to skip a certain component to avoid using one at all (or to use your own): @@ -43,7 +43,7 @@ renderer:: none (default), slim, erb, erubis, liquid, haml stylesheet:: none (default), less, compass, sass, scss mock:: none (default), mocha, rr script:: none (default), jquery, prototype, mootools, extcore, dojo -orm:: none (default), datamapper, mongomapper, mongoid, activerecord, minirecord, sequel, couchrest, ohm, mongomatic, ripple, dynamoid +orm:: none (default), mongoid, activerecord, minirecord, sequel, ohm, mongomatic, dynamoid In addition, you can generate projects based on existing templates: diff --git a/padrino-gen/lib/padrino-gen/generators/actions.rb b/padrino-gen/lib/padrino-gen/generators/actions.rb index da92f0a5e..40ab7444d 100644 --- a/padrino-gen/lib/padrino-gen/generators/actions.rb +++ b/padrino-gen/lib/padrino-gen/generators/actions.rb @@ -347,7 +347,7 @@ def insert_into_gemfile(name, options = {}) # method hook to call from Padrino, i.e :after_load, :before_load. # # @example - # insert_hook("DataMapper.finalize", :after_load) + # insert_hook("SomeORM.finalize", :after_load) # def insert_hook(include_text, where) inject_into_file('config/boot.rb', " #{include_text}\n", after: "Padrino.#{where} do\n") diff --git a/padrino-gen/lib/padrino-gen/generators/components/orms/couchrest.rb b/padrino-gen/lib/padrino-gen/generators/components/orms/couchrest.rb deleted file mode 100644 index e93237cad..000000000 --- a/padrino-gen/lib/padrino-gen/generators/components/orms/couchrest.rb +++ /dev/null @@ -1,55 +0,0 @@ -COUCHREST = <<~COUCHREST unless defined?(COUCHREST) - case Padrino.env - when :development then db_name = '!NAME!_development' - when :production then db_name = '!NAME!_production' - when :test then db_name = '!NAME!_test' - end - - CouchRest::Model::Base.configure do |conf| - conf.model_type_key = 'type' # compatibility with CouchModel 1.1 - conf.database = CouchRest.database!(db_name) - conf.environment = Padrino.env - # conf.connection = { - # protocol: 'http', - # host: 'localhost', - # port: '5984', - # prefix: 'padrino', - # suffix: nil, - # join: '_', - # username: nil, - # password: nil - # } - end -COUCHREST - -def setup_orm - require_dependencies 'couchrest_model', version: '~>1.1.0' - require_dependencies 'json_pure' - create_file('config/database.rb', COUCHREST.gsub(/!NAME!/, @project_name.underscore)) -end - -CR_MODEL = <<~MODEL unless defined?(CR_MODEL) - class !NAME! < CouchRest::Model::Base - unique_id :id - # property - !FIELDS! - end -MODEL - -# options => { fields: ['title:string', 'body:string'], app: 'app' } -def create_model_file(name, options = {}) - model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb") - field_tuples = options[:fields].map { |value| value.split(':') } - column_declarations = field_tuples.map { |field, _kind| "property :#{field}" }.join("\n ") - model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize) - model_contents.gsub!(/!FIELDS!/, column_declarations) - create_file(model_path, model_contents) -end - -def create_model_migration(filename, name, fields) - # NO MIGRATION NEEDED -end - -def create_migration_file(migration_name, name, columns) - # NO MIGRATION NEEDED -end diff --git a/padrino-gen/lib/padrino-gen/generators/components/orms/datamapper.rb b/padrino-gen/lib/padrino-gen/generators/components/orms/datamapper.rb deleted file mode 100644 index 1ede1c451..000000000 --- a/padrino-gen/lib/padrino-gen/generators/components/orms/datamapper.rb +++ /dev/null @@ -1,170 +0,0 @@ -DM = <<~DM unless defined?(DM) - ## - # A MySQL connection: - # DataMapper.setup(:default, 'mysql://user:password@localhost/the_database_name') - # - # # A Postgres connection: - # DataMapper.setup(:default, 'postgres://user:password@localhost/the_database_name') - # - # # A Sqlite3 connection - # DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "development.db")) - # - # # Setup DataMapper using config/database.yml - # DataMapper.setup(:default, YAML.load_file(Padrino.root('config/database.yml'))[RACK_ENV]) - # - # config/database.yml file: - # - # --- - # development: &defaults - # adapter: mysql - # database: example_development - # username: user - # password: Pa55w0rd - # host: 127.0.0.1 - # - # test: - # <<: *defaults - # database: example_test - # - # production: - # <<: *defaults - # database: example_production - # - - DataMapper.logger = logger - DataMapper::Property::String.length(255) - - case Padrino.env - when :development then DataMapper.setup(:default, !DB_DEVELOPMENT!) - when :production then DataMapper.setup(:default, !DB_PRODUCTION!) - when :test then DataMapper.setup(:default, !DB_TEST!) - end -DM - -IDENTITY_MAP_MIDDLEWARE = <<~MIDDLEWARE - class IdentityMap - def initialize(app, name = :default) - @app = app - @name = name.to_sym - end - - def call(env) - ::DataMapper.repository(@name) do - @app.call(env) - end - end - end -MIDDLEWARE - -def setup_orm - dm = DM - db = @project_name.underscore - %w[ - dm-core - dm-types - dm-aggregates - dm-constraints - dm-migrations - dm-timestamps - dm-validations - ].each { |dep| require_dependencies dep } - - begin - case adapter ||= options[:adapter] - when 'mysql', 'mysql2' - dm.gsub!(/!DB_DEVELOPMENT!/, "\"mysql://root@localhost/#{db}_development\"") - dm.gsub!(/!DB_PRODUCTION!/, "\"mysql://root@localhost/#{db}_production\"") - dm.gsub!(/!DB_TEST!/, "\"mysql://root@localhost/#{db}_test\"") - require_dependencies 'dm-mysql-adapter' - when 'postgres' - dm.gsub!(/!DB_DEVELOPMENT!/, "\"postgres://root@localhost/#{db}_development\"") - dm.gsub!(/!DB_PRODUCTION!/, "\"postgres://root@localhost/#{db}_production\"") - dm.gsub!(/!DB_TEST!/, "\"postgres://root@localhost/#{db}_test\"") - require_dependencies 'dm-postgres-adapter' - when 'sqlite' - dm.gsub!(/!DB_DEVELOPMENT!/, "\"sqlite3://\" + Padrino.root('db', \"#{db}_development.db\")") - dm.gsub!(/!DB_PRODUCTION!/, "\"sqlite3://\" + Padrino.root('db', \"#{db}_production.db\")") - dm.gsub!(/!DB_TEST!/, "\"sqlite3://\" + Padrino.root('db', \"#{db}_test.db\")") - require_dependencies 'dm-sqlite-adapter' - else - say "Failed to generate `config/database.rb` for ORM adapter `#{options[:adapter]}`", :red - raise ArgumentError - end - rescue ArgumentError - adapter = ask('Please, choose a proper adapter:', limited_to: %w[mysql mysql2 postgres sqlite]) - retry - end - - create_file('config/database.rb', dm) - insert_hook('DataMapper.finalize', :after_load) - middleware :identity_map, IDENTITY_MAP_MIDDLEWARE -end - -DM_MODEL = <<~MODEL unless defined?(DM_MODEL) - class !NAME! - include DataMapper::Resource - - # property , - property :id, Serial - !FIELDS! - end -MODEL - -# options => { fields: ['title:string', 'body:string'], app: 'app' } -def create_model_file(name, options = {}) - model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb") - model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize) - field_tuples = options[:fields].map { |value| value.split(':') } - field_tuples.map! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime - column_declarations = field_tuples.map { |field, kind| "property :#{field}, #{kind.underscore.camelize}" }.join("\n ") - model_contents.gsub!(/!FIELDS!/, column_declarations) - create_file(model_path, model_contents) -end - -DM_MIGRATION = <<~MIGRATION unless defined?(DM_MIGRATION) - migration !VERSION!, :!FILENAME! do - up do - !UP! - end - - down do - !DOWN! - end - end -MIGRATION - -DM_MODEL_UP_MG = <<~MIGRATION.gsub(/^/, ' ') unless defined?(DM_MODEL_UP_MG) - create_table :!TABLE! do - column :id, Integer, serial: true - !FIELDS! - end -MIGRATION - -DM_MODEL_DOWN_MG = <<~MIGRATION unless defined?(DM_MODEL_DOWN_MG) - drop_table :!TABLE! -MIGRATION - -def create_model_migration(migration_name, name, columns) - output_model_migration( - migration_name, name, columns, - column_format: proc { |field, kind| "column :#{field}, DataMapper::Property::#{kind.classify}#{', length: 255' if kind =~ /string/i}" }, - base: DM_MIGRATION, - up: DM_MODEL_UP_MG, - down: DM_MODEL_DOWN_MG - ) -end - -DM_CHANGE_MG = <<~MIGRATION.gsub(/^/, ' ') unless defined?(DM_CHANGE_MG) - modify_table :!TABLE! do - !COLUMNS! - end -MIGRATION - -def create_migration_file(migration_name, name, columns) - output_migration_file( - migration_name, name, columns, - base: DM_MIGRATION, change_format: DM_CHANGE_MG, - add: proc { |field, kind| "add_column :#{field}, #{kind.classify}" }, - remove: proc { |field, _kind| "drop_column :#{field}" } - ) -end diff --git a/padrino-gen/lib/padrino-gen/generators/components/orms/mongomapper.rb b/padrino-gen/lib/padrino-gen/generators/components/orms/mongomapper.rb deleted file mode 100644 index 547e2ec9a..000000000 --- a/padrino-gen/lib/padrino-gen/generators/components/orms/mongomapper.rb +++ /dev/null @@ -1,44 +0,0 @@ -MONGO = <<~MONGO unless defined?(MONGO) - MongoMapper.connection = Mongo::Connection.new('localhost', nil, logger: logger) - - case Padrino.env - when :development then MongoMapper.database = '!NAME!_development' - when :production then MongoMapper.database = '!NAME!_production' - when :test then MongoMapper.database = '!NAME!_test' - end -MONGO - -def setup_orm - require_dependencies 'mongo_mapper' - require_dependencies 'bson_ext', require: 'mongo' - require_dependencies 'activemodel', version: '< 5' - create_file('config/database.rb', MONGO.gsub(/!NAME!/, @project_name.underscore)) -end - -MM_MODEL = <<~MODEL unless defined?(MM_MODEL) - class !NAME! - include MongoMapper::Document - - # key , - !FIELDS! - timestamps! - end -MODEL - -# options => { fields: ['title:string', 'body:string'], app: 'app' } -def create_model_file(name, options = {}) - model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb") - field_tuples = options[:fields].map { |value| value.split(':') } - column_declarations = field_tuples.map { |field, kind| "key :#{field}, #{kind.underscore.camelize}" }.join("\n ") - model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize) - model_contents.gsub!(/!FIELDS!/, column_declarations) - create_file(model_path, model_contents) -end - -def create_model_migration(filename, name, fields) - # NO MIGRATION NEEDED -end - -def create_migration_file(migration_name, name, columns) - # NO MIGRATION NEEDED -end diff --git a/padrino-gen/lib/padrino-gen/generators/components/orms/ripple.rb b/padrino-gen/lib/padrino-gen/generators/components/orms/ripple.rb deleted file mode 100644 index 460e2707c..000000000 --- a/padrino-gen/lib/padrino-gen/generators/components/orms/ripple.rb +++ /dev/null @@ -1,75 +0,0 @@ -RIPPLE_DB = <<~RIAK unless defined?(RIPPLE_DB) - development: - http_port: 8098 - pb_port: 8087 - host: localhost - - # The test environment has additional keys for configuring the - # Riak::TestServer for your test/spec suite: - # - # * bin_dir specifies the path to the "riak" script that you use to - # start Riak (just the directory) - # * js_source_dir specifies where your custom Javascript functions for - # MapReduce should be loaded from. Usually app/mapreduce. - test: - http_port: 9000 - pb_port: 9002 - host: localhost - bin_dir: /usr/local/bin # Default for Homebrew. - js_source_dir: <%%= Padrino.root + 'app/mapreduce' %> - - production: - http_port: 8098 - pb_port: 8087 - host: localhost -RIAK -RIPPLE_CFG = <<~RIAK unless defined?(RIPPLE_CFG) - # encoding: utf-8 - - require 'ripple' - - if File.exist?(Padrino.root + 'config/riak.yml') - Ripple.load_configuration Padrino.root.join('config', 'riak.yml'), [Padrino.env] - end -RIAK - -def setup_orm - require_dependencies 'ripple' - create_file('config/riak.yml', RIPPLE_DB.gsub(/!NAME!/, @project_name.underscore)) - create_file('config/database.rb', RIPPLE_CFG) -end - -RIPPLE_MODEL = <<~MODEL unless defined?(RIPPLE_MODEL) - # encoding: utf-8 - - class !NAME! - include Ripple::Document - - # Standart properties - # property :name, String - !FIELDS! - - # Relations - # many :addresses - # many :friends, class_name: 'Person' - # one :account - end - -MODEL -# options => { fields: ['title:string', 'body:string'], app: 'app' } -def create_model_file(name, options = {}) - model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb") - field_tuples = options[:fields].map { |value| value.split(':') } - column_declarations = field_tuples.map { |field, kind| "property :#{field}, #{kind.underscore.camelize}" }.join("\n ") - model_contents = RIPPLE_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize) - model_contents.gsub!(/!FIELDS!/, column_declarations) - create_file(model_path, model_contents) -end - -def create_model_migration(filename, name, fields) - # NO MIGRATION NEEDED -end - -def create_migration_file(migration_name, name, columns) - # NO MIGRATION NEEDED -end diff --git a/padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb b/padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb deleted file mode 100644 index 26a780d08..000000000 --- a/padrino-gen/lib/padrino-gen/padrino-tasks/datamapper.rb +++ /dev/null @@ -1,96 +0,0 @@ -if PadrinoTasks.load?(:datamapper, defined?(DataMapper)) - namespace :dm do - namespace :auto do - desc 'Perform auto migration (reset your db data)' - task migrate: :environment do - ::DataMapper.repository.auto_migrate! - puts '<= dm:auto:migrate executed' - end - - desc 'Perform non destructive auto migration' - task upgrade: :environment do - ::DataMapper.repository.auto_upgrade! - puts '<= dm:auto:upgrade executed' - end - end - - namespace :migrate do - task load: :environment do - require 'dm-migrations/migration_runner' - FileList['db/migrate/*.rb'].each do |migration| - load migration - end - end - - desc 'Migrate up using migrations' - task :up, [:version] => :load do |_t, args| - version = args[:version] || env_migration_version - migrate_up!(version) - puts "<= dm:migrate:up #{version} executed" - end - - desc 'Migrate down using migrations' - task :down, [:version] => :load do |_t, args| - version = args[:version] || env_migration_version - migrate_down!(version) - puts "<= dm:migrate:down #{version} executed" - end - end - - desc 'Migrate the database to the latest version' - task :migrate do - migrate_task = if Dir['db/migrate/*.rb'].empty? - 'dm:auto:upgrade' - else - 'dm:migrate:up' - end - - Rake::Task[migrate_task].invoke - end - - desc 'Create the database' - task create: :environment do - config = Padrino::Utils.symbolize_keys(DataMapper.repository.adapter.options) - adapter = config[:adapter] - user, password, host = config[:user], config[:password], config[:host] - - database = config[:database] || config[:path] - database.sub!(%r{^/}, '') unless adapter.start_with?('sqlite') - - charset = config[:charset] || ENV['CHARSET'] || 'utf8' - collation = config[:collation] || ENV['COLLATION'] || 'utf8_unicode_ci' - - puts "=> Creating database '#{database}'" - Padrino::Generators::SqlHelpers.create_db(adapter, user, password, host, database, charset, collation) - puts '<= dm:create executed' - end - - desc 'Drop the database (postgres and mysql only)' - task drop: :environment do - config = Padrino::Utils.symbolize_keys(DataMapper.repository.adapter.options) - adapter = config[:adapter] - user, password, host = config[:user], config[:password], config[:host] - - database = config[:database] || config[:path] - database.sub!(%r{^/}, '') unless adapter.start_with?('sqlite') - - puts "=> Dropping database '#{database}'" - Padrino::Generators::SqlHelpers.drop_db(adapter, user, password, host, database) - puts '<= dm:drop executed' - end - - desc 'Drop the database, migrate from scratch and initialize with the seed data' - task reset: %i[drop setup] - - desc 'Create the database migrate and initialize with the seed data' - task setup: %i[create migrate seed] - end - - task 'db:migrate:down' => 'dm:migrate:down' - task 'db:migrate:up' => 'dm:migrate:up' - task 'db:migrate' => 'dm:migrate' - task 'db:create' => 'dm:create' - task 'db:drop' => 'dm:drop' - task 'db:reset' => 'dm:reset' - task 'db:setup' => 'dm:setup' -end diff --git a/padrino-gen/lib/padrino-gen/padrino-tasks/mongomapper.rb b/padrino-gen/lib/padrino-gen/padrino-tasks/mongomapper.rb deleted file mode 100644 index e64be16a6..000000000 --- a/padrino-gen/lib/padrino-gen/padrino-tasks/mongomapper.rb +++ /dev/null @@ -1,59 +0,0 @@ -if defined?(MongoMapper) - begin - require 'i18n' - rescue LoadError - # Only do this for I18n check later. - end - - namespace :mm do - desc 'Drops all the collections for the database for the current Padrino.env' - task drop: :environment do - MongoMapper.database.collections.reject { |c| c.name =~ /system/ }.each(&:drop) - end - - desc 'Generates .yml files for I18n translations' - task translate: :environment do - models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, '.rb') } - - models.each do |m| - # Get the model class. - klass = m.camelize.constantize - - # Init the processing - print "Processing #{m.humanize}: " - FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}") - langs = Array(I18n.locale) - - # Create models for it and en locales. - langs.each do |lang| - filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml" - columns = klass.keys.values.map(&:name).reject { |name| name =~ /id/i } - # If the lang file already exist we need to check it - if File.exist?(filename) - locale = File.open(filename).read - columns.each do |c| - locale += "\n #{c}: #{c.humanize}" unless locale.include?("#{c}:") - end - else - locale = <<~YAML - #{lang}: - models: - #{m}: - name: #{klass.model_name.human} - attributes: - YAML - - columns.each { |c| locale += " #{c}: #{c.humanize}\n" } - locale.chomp! - end - - $stdout.flush - File.open(filename, 'w') { |f| f.puts locale } - end - puts - end - end - end - - task 'db:drop' => 'mm:drop' -end diff --git a/padrino-gen/test/test_migration_generator.rb b/padrino-gen/test/test_migration_generator.rb index a522dbadc..df528599d 100644 --- a/padrino-gen/test/test_migration_generator.rb +++ b/padrino-gen/test/test_migration_generator.rb @@ -125,51 +125,6 @@ def teardown end end - describe 'the migration generator for datamapper' do - before do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') } - end - - it 'should generate migration for generic needs' do - capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") } - migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb" - assert_match_in_file(/migration\s1.*?:modify_user_fields/m, migration_file_path) - assert_match_in_file(/up\sdo\s+end/m, migration_file_path) - assert_match_in_file(/down\sdo\s+end/m, migration_file_path) - end - - it 'should generate migration for adding columns' do - migration_params = ['AddEmailToUsers', 'email:string', 'age:integer', "-r=#{@apptmp}/sample_project"] - capture_io { generate(:migration, *migration_params) } - migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb" - assert_match_in_file(/migration\s1.*?:add_email_to_users/m, migration_file_path) - assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path) - assert_match_in_file(/add_column :age, Integer/m, migration_file_path) - assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path) - assert_match_in_file(/drop_column :age/m, migration_file_path) - end - - it 'should generate migration for removing columns' do - migration_params = ['RemoveEmailFromUsers', 'email:string', 'age:integer', "-r=#{@apptmp}/sample_project"] - capture_io { generate(:migration, *migration_params) } - migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb" - assert_match_in_file(/migration\s1.*?:remove_email_from_users/m, migration_file_path) - assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path) - assert_match_in_file(/drop_column :age/m, migration_file_path) - assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path) - assert_match_in_file(/add_column :age, Integer/m, migration_file_path) - end - - it 'should properly version migration files' do - capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") } - capture_io { generate(:migration, 'ModifyUserFields2', "-r=#{@apptmp}/sample_project") } - capture_io { generate(:migration, 'ModifyUserFields3', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/migration\s1.*?:modify_user_fields/m, "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb") - assert_match_in_file(/migration\s2.*?:modify_user_fields2/m, "#{@apptmp}/sample_project/db/migrate/002_modify_user_fields2.rb") - assert_match_in_file(/migration\s3.*?:modify_user_fields3/m, "#{@apptmp}/sample_project/db/migrate/003_modify_user_fields3.rb") - end - end - describe 'the migration generator for sequel' do before do capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') } diff --git a/padrino-gen/test/test_model_generator.rb b/padrino-gen/test/test_model_generator.rb index f105bed79..1cfebf856 100644 --- a/padrino-gen/test/test_model_generator.rb +++ b/padrino-gen/test/test_model_generator.rb @@ -18,13 +18,13 @@ def teardown end it 'should generate filename properly' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') } + capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') } capture_io { generate(:model, 'DemoItem', 'name:string', 'age', 'email:string', "-r=#{@apptmp}/sample_project") } assert_file_exists("#{@apptmp}/sample_project/models/demo_item.rb") end it 'should fail if field name is not acceptable' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') } + capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') } out, = capture_io { generate(:model, 'DemoItem', 're@l$ly:string', 'display-name:string', 'age&year:datetime', 'email_two:string', "-r=#{@apptmp}/sample_project") } assert_match(/Invalid field name:/, out) assert_match(/display-name:string/, out) @@ -48,13 +48,10 @@ def teardown end it 'should generate model in specified app' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=datamapper', '--script=none', '-t=bacon') } + capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=sequel', '--script=none', '-t=bacon') } capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") } capture_io { generate(:model, 'Post', 'body:string', '-a=/subby', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class Post\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/subby/models/post.rb") - assert_match_in_file(/property :body, String/m, "#{@apptmp}/sample_project/subby/models/post.rb") - assert_match_in_file(/migration 1, :create_posts do/m, "#{@apptmp}/sample_project/db/migrate/001_create_posts.rb") - assert_match_in_file(/DataMapper.finalize/m, "#{@apptmp}/sample_project/config/boot.rb") + assert_match_in_file(/class Post < Sequel::Model/m, "#{@apptmp}/sample_project/subby/models/post.rb") end it 'should generate migration file versions properly' do @@ -193,77 +190,6 @@ def teardown end end - # COUCHREST - describe 'model generator using couchrest' do - it 'should generate model file with no properties' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') } - capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class User < CouchRest::Model::Base/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/# property [\s\n]+?end/m, "#{@apptmp}/sample_project/models/user.rb") - end - - it 'should generate model file with given fields' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') } - capture_io { generate(:model, 'person', 'name:string', 'age', 'email:string', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class Person < CouchRest::Model::Base/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/property :name/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/property :age/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/property :email/m, "#{@apptmp}/sample_project/models/person.rb") - end - end - - # DATAMAPPER - describe 'model generator using datamapper' do - it 'should add activerecord middleware' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') } - assert_match_in_file(/ use IdentityMap/m, "#{@apptmp}/sample_project/app/app.rb") - assert_file_exists("#{@apptmp}/sample_project/lib/identity_map_middleware.rb") - end - - it 'should generate model file with camelized name' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') } - capture_io { generate(:model, 'ChunkyBacon', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class ChunkyBacon\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/chunky_bacon.rb") - assert_match_in_file(/ChunkyBacon Model/, "#{@apptmp}/sample_project/test/models/chunky_bacon_test.rb") - end - - it 'should generate model file with fields' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') } - capture_io { generate(:model, 'user', 'name:string', 'age:integer', 'created_at:datetime', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/property :name, String/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/property :age, Integer/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/property :created_at, DateTime/m, "#{@apptmp}/sample_project/models/user.rb") - end - - it 'should properly generate version numbers' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') } - capture_io { generate(:model, 'user', 'name:string', 'age:integer', 'created_at:datetime', "-r=#{@apptmp}/sample_project") } - capture_io { generate(:model, 'friend', 'name:string', 'age:integer', 'created_at:datetime', "-r=#{@apptmp}/sample_project") } - capture_io { generate(:model, 'account', 'name:string', 'age:integer', 'created_at:datetime', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/migration 1, :create_users do/m, "#{@apptmp}/sample_project/db/migrate/001_create_users.rb") - assert_match_in_file(/class Friend\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/friend.rb") - assert_match_in_file(/migration 2, :create_friends do/m, "#{@apptmp}/sample_project/db/migrate/002_create_friends.rb") - assert_match_in_file(/class Account\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/account.rb") - assert_match_in_file(/migration 3, :create_accounts do/m, "#{@apptmp}/sample_project/db/migrate/003_create_accounts.rb") - end - - it 'should generate migration with given fields' do - stop_time_for_test - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') } - capture_io { generate(:model, 'friend', 'name:string', 'created_at:date_time', 'email:string', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class Friend\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/friend.rb") - migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_friends.rb" - assert_match_in_file(/migration 1, :create_friends do/m, migration_file_path) - assert_match_in_file(/create_table :friends do/m, migration_file_path) - assert_match_in_file(/column :name, DataMapper::Property::String/m, migration_file_path) - assert_match_in_file(/column :created_at, DataMapper::Property::DateTime/m, migration_file_path) - assert_match_in_file(/column :email, DataMapper::Property::String/m, migration_file_path) - assert_match_in_file(/drop_table :friends/m, migration_file_path) - end - end - # SEQUEL describe 'model generator using sequel' do it 'should generate model file with given properties' do @@ -294,27 +220,6 @@ def teardown end end - # MONGODB - describe 'model generator using mongomapper' do - it 'should generate model file with no properties' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongomapper') } - capture_io { generate(:model, 'person', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/# key , /m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/timestamps![\n\s]+end/m, "#{@apptmp}/sample_project/models/person.rb") - end - - it 'should generate model file with given fields' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongomapper') } - capture_io { generate(:model, 'user', 'name:string', 'age:integer', 'email:string', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class User\n\s+include MongoMapper::Document/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/key :name, String/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/key :age, Integer/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/key :email, String/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/timestamps!/m, "#{@apptmp}/sample_project/models/user.rb") - end - end - describe 'model generator using mongoid' do it 'should generate model file with no properties' do capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongoid') } @@ -374,27 +279,6 @@ def teardown end end - # RIPPLE - describe 'model generator using ripple' do - it 'should generate model file with no properties' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=ripple') } - capture_io { generate(:model, 'person', 'name:string', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class Person\n\s+include Ripple::Document/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/# property :name, String/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/# many :addresses/m, "#{@apptmp}/sample_project/models/person.rb") - assert_match_in_file(/# one :account/m, "#{@apptmp}/sample_project/models/person.rb") - end - - it 'should generate model file with given fields' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=ripple') } - capture_io { generate(:model, 'user', 'name:string', 'age:integer', 'email:string', "-r=#{@apptmp}/sample_project") } - assert_match_in_file(/class User\n\s+include Ripple::Document/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/property :name, String/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/property :age, Integer/m, "#{@apptmp}/sample_project/models/user.rb") - assert_match_in_file(/property :email, String/m, "#{@apptmp}/sample_project/models/user.rb") - end - end - # DYNAMOID describe 'model generator using dynamoid' do it 'should generate model file with no properties' do diff --git a/padrino-gen/test/test_project_generator.rb b/padrino-gen/test/test_project_generator.rb index 6a79f218d..0bc97a8ac 100644 --- a/padrino-gen/test/test_project_generator.rb +++ b/padrino-gen/test/test_project_generator.rb @@ -179,10 +179,10 @@ def teardown end it 'should create components file containing options chosen' do - component_options = ['--orm=datamapper', '--test=rspec', '--mock=mocha', '--script=prototype', '--renderer=erb', '--stylesheet=less'] + component_options = ['--orm=sequel', '--test=rspec', '--mock=mocha', '--script=prototype', '--renderer=erb', '--stylesheet=less'] capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", *component_options) } components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components") - assert_equal 'datamapper', components_chosen[:orm] + assert_equal 'sequel', components_chosen[:orm] assert_equal 'rspec', components_chosen[:test] assert_equal 'mocha', components_chosen[:mock] assert_equal 'prototype', components_chosen[:script] @@ -191,9 +191,9 @@ def teardown end it 'should output to log components being applied' do - component_options = ['--orm=datamapper', '--test=rspec', '--mock=mocha', '--script=prototype', '--renderer=erb', '--stylesheet=less'] + component_options = ['--orm=sequel', '--test=rspec', '--mock=mocha', '--script=prototype', '--renderer=erb', '--stylesheet=less'] out, = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", *component_options) } - assert_match(/applying.*?datamapper.*?orm/, out) + assert_match(/applying.*?sequel.*?orm/, out) assert_match(/applying.*?rspec.*?test/, out) assert_match(/applying.*?mocha.*?mock/, out) assert_match(/applying.*?prototype.*?script/, out) @@ -376,54 +376,6 @@ def teardown end end - describe 'for datamapper' do - it 'should properly generate default' do - out, = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=datamapper', '--script=none') } - assert_match(/applying.*?datamapper.*?orm/, out) - assert_match_in_file(/gem 'dm-core'/, "#{@apptmp}/project.com/Gemfile") - assert_match_in_file(/gem 'dm-sqlite-adapter'/, "#{@apptmp}/project.com/Gemfile") - assert_match_in_file(/DataMapper.setup/, "#{@apptmp}/project.com/config/database.rb") - assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb") - end - - it 'should properly generate for mysql' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=mysql') } - assert_match_in_file(/gem 'dm-mysql-adapter'/, "#{@apptmp}/sample_project/Gemfile") - assert_match_in_file(%r{"mysql://}, "#{@apptmp}/sample_project/config/database.rb") - assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb") - end - - # DataMapper has do_mysql that is the version of MySQL driver. - it 'should properly generate for mysql2' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=mysql2') } - assert_match_in_file(/gem 'dm-mysql-adapter'/, "#{@apptmp}/sample_project/Gemfile") - assert_match_in_file(%r{"mysql://}, "#{@apptmp}/sample_project/config/database.rb") - assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb") - end - - it 'should properly generate for sqlite' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=sqlite') } - assert_match_in_file(/gem 'dm-sqlite-adapter'/, "#{@apptmp}/sample_project/Gemfile") - assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb") - end - - it 'should properly generate for postgres' do - capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=postgres') } - assert_match_in_file(/gem 'dm-postgres-adapter'/, "#{@apptmp}/sample_project/Gemfile") - assert_match_in_file(%r{"postgres://}, "#{@apptmp}/sample_project/config/database.rb") - assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb") - end - end - - it 'should properly generate for mongomapper' do - out, = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=mongomapper', '--script=none') } - assert_match(/applying.*?mongomapper.*?orm/, out) - assert_match_in_file(/gem 'mongo_mapper'/, "#{@apptmp}/project.com/Gemfile") - assert_match_in_file(/gem 'bson_ext'/, "#{@apptmp}/project.com/Gemfile") - assert_match_in_file(/MongoMapper.database/, "#{@apptmp}/project.com/config/database.rb") - assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb") - end - it 'should properly generate for mongoid' do out, = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=mongoid', '--script=none') } assert_match(/applying.*?mongoid.*?orm/, out) @@ -431,14 +383,6 @@ def teardown assert_match_in_file(/Mongoid::Config.sessions =/, "#{@apptmp}/project.com/config/database.rb") end - it 'should properly generate for couchrest' do - out, = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=couchrest', '--script=none') } - assert_match(/applying.*?couchrest.*?orm/, out) - assert_match_in_file(/gem 'couchrest_model'/, "#{@apptmp}/project.com/Gemfile") - assert_match_in_file(/CouchRest.database!/, "#{@apptmp}/project.com/config/database.rb") - assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb") - end - it 'should properly generate for ohm' do out, = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=ohm', '--script=none') } assert_match(/applying.*?ohm.*?orm/, out) @@ -454,14 +398,6 @@ def teardown assert_match_in_file(/Mongomatic.db = Mongo::Connection.new.db/, "#{@apptmp}/sample_project/config/database.rb") end - it 'should properly generate for ripple' do - out, = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=ripple', '--script=none') } - assert_match(/applying.*?ripple.*?orm/, out) - assert_match_in_file(/gem 'ripple'/, "#{@apptmp}/sample_project/Gemfile") - assert_match_in_file(/Ripple.load_configuration/, "#{@apptmp}/sample_project/config/database.rb") - assert_match_in_file(/http_port: 8098/, "#{@apptmp}/sample_project/config/riak.yml") - end - it 'should properly generate for dynamoid' do out, = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=dynamoid', '--script=none') } assert_match(/applying.*?dynamoid.*?orm/, out) diff --git a/padrino-helpers/test/fixtures/apps/.components b/padrino-helpers/test/fixtures/apps/.components index 516c4a230..7ee6755b6 100644 --- a/padrino-helpers/test/fixtures/apps/.components +++ b/padrino-helpers/test/fixtures/apps/.components @@ -1,6 +1,6 @@ --- :test: bacon :mock: mocha -:orm: datamapper +:orm: none :renderer: erb :script: jquery From 55d89a4987b88217c4eeee78285701b645f95f4d Mon Sep 17 00:00:00 2001 From: Arthur Chiu Date: Sun, 29 Mar 2026 16:53:55 -0700 Subject: [PATCH 2/2] fix: add missing ORMs to admin tooltips/README, remove DM rake task refs --- padrino-admin/README.rdoc | 6 +++--- .../generators/templates/erb/app/base/index.erb.tt | 2 +- .../generators/templates/haml/app/base/index.haml.tt | 2 +- .../generators/templates/slim/app/base/index.slim.tt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/padrino-admin/README.rdoc b/padrino-admin/README.rdoc index c68d7ff47..bf6d5fd94 100644 --- a/padrino-admin/README.rdoc +++ b/padrino-admin/README.rdoc @@ -4,7 +4,7 @@ Padrino has a beautiful Admin management dashboard with these features: -Orm Agnostic:: Data Adapters for Activerecord, Sequel, Mongoid, Ohm, Dynamoid +Orm Agnostic:: Data Adapters for Activerecord, MiniRecord, Sequel, Mongoid, Ohm, Dynamoid Template Agnostic:: Erb, Erubis and Haml Renderer Authentication:: Support for Account authentication, Account Permission management Scaffold:: You can simply create a new "admin interface" by providing a Model @@ -27,7 +27,7 @@ Create the admin subapplication: Next, follow the admin setup steps: * configure your config/database.rb to connect to the correct data. -* run padrino rake dm:migrate # or ar:migrate if you use activerecord +* run padrino rake ar:migrate # if you use activerecord * run padrino rake seed Your admin panel now is ready and you can start your server with padrino start and point your browser to /admin! @@ -35,7 +35,7 @@ Your admin panel now is ready and you can start your server with padrino sta To create a new "scaffold" you need to provide only a Model name to the command: demo$ padrino-gen model post --skip-migration # edit your post.rb model and add some fields - demo$ padrino-gen rake dm:auto:migrate + demo$ padrino-gen rake ar:migrate demo$ padrino-gen admin_page post demo$ padrino start # and go to http://localhost:3000/admin diff --git a/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt b/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt index 3df240e43..4ad2fc087 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt @@ -6,7 +6,7 @@
-
<%%= tag_icon("cogs fa-2x", "Orm Agnostic") %>
+
<%%= tag_icon("cogs fa-2x", "Orm Agnostic") %>
<%%= tag_icon("group fa-2x", "Authentication") %>
<%%= tag_icon("tasks fa-2x", "Template Agnostic") %>
<%%= tag_icon("flag fa-2x", "Multi Language") %>
diff --git a/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt b/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt index 9239f8cf3..2af63142d 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/haml/app/base/index.haml.tt @@ -5,7 +5,7 @@ .base-icons .btn-group - .btn.btn-primary{title: 'Adapters for sequel, activerecord, minirecord, mongoid'} + .btn.btn-primary{title: 'Adapters for activerecord, minirecord, sequel, mongoid, ohm, dynamoid'} = tag_icon('cogs fa-2x', 'Orm Agnostic') .btn.btn-success{title: 'User Authentication Support, User Authorization Management'} = tag_icon('group fa-2x', 'Authentication') diff --git a/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt b/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt index 55d318159..ce390c420 100644 --- a/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt +++ b/padrino-admin/lib/padrino-admin/generators/templates/slim/app/base/index.slim.tt @@ -5,7 +5,7 @@ div class="base-text" div class="base-icons" div class="btn-group" - div class="btn btn-primary" title="Adapters for sequel, activerecord, minirecord, mongoid" = tag_icon("cogs fa-2x", "Orm Agnostic") + div class="btn btn-primary" title="Adapters for activerecord, minirecord, sequel, mongoid, ohm, dynamoid" = tag_icon("cogs fa-2x", "Orm Agnostic") div class="btn btn-success" title="User Authentication Support, User Authorization Management" = tag_icon("group fa-2x", "Authentication") div class="btn btn-info" title="Erb, Haml, Slim Rendering Support" = tag_icon("tasks fa-2x", "Template Agnostic") div class="btn btn-warning" title="English, German, Russian, Danish, French, Brazilian and Italian localizations" = tag_icon("flag fa-2x", "Multi Language")