Module: Maestrano::Generators::OrmHelpers
- Included in:
- ActiveRecord::Generators::MaestranoGroupGenerator, ActiveRecord::Generators::MaestranoUserGenerator, Mongoid::Generators::MaestranoGroupGenerator, Mongoid::Generators::MaestranoUserGenerator
- Defined in:
- lib/generators/maestrano/orm_helpers.rb
Instance Method Summary collapse
- #model_contents ⇒ Object
- #model_type ⇒ Object
- #needs_attr_accessible? ⇒ Boolean
- #rails_3? ⇒ Boolean
- #strong_parameters_enabled? ⇒ Boolean
Instance Method Details
#model_contents ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/maestrano/orm_helpers.rb', line 5 def model_contents if model_type == 'user' buffer = <<-CONTENT # Enable Maestrano for this user maestrano_user_via :provider, :uid, :tenant do |user,maestrano| user.name = maestrano.first_name user.surname = maestrano.last_name user.email = maestrano.email # user.country_alpha2 = maestrano.country # user.some_required_field = 'some-appropriate-default-value' end CONTENT else buffer = <<-CONTENT # Enable Maestrano for this group maestrano_group_via :provider, :uid, :tenant do |group, maestrano| group.name = (maestrano.company_name || "Default Group name") # group.principal_email = maestrano.email # group.city = maestrano.city # group.olson_tz = maestrano.timezone # group.country_alpha2 = maestrano.country # group.currency_code = maestrano.currency # group.some_required_field = 'some-appropriate-default-value' end CONTENT end buffer += <<-CONTENT if needs_attr_accessible? # Setup protected attributes for your model attr_protected :provider, :uid CONTENT buffer end |
#model_type ⇒ Object
44 45 46 |
# File 'lib/generators/maestrano/orm_helpers.rb', line 44 def model_type self.class.name.split("::").last.gsub("Maestrano","").gsub("Generator","").downcase end |
#needs_attr_accessible? ⇒ Boolean
48 49 50 |
# File 'lib/generators/maestrano/orm_helpers.rb', line 48 def needs_attr_accessible? rails_3? && !strong_parameters_enabled? end |
#rails_3? ⇒ Boolean
52 53 54 |
# File 'lib/generators/maestrano/orm_helpers.rb', line 52 def rails_3? ::Rails::VERSION::MAJOR == 3 end |
#strong_parameters_enabled? ⇒ Boolean
56 57 58 |
# File 'lib/generators/maestrano/orm_helpers.rb', line 56 def strong_parameters_enabled? defined?(ActionController::StrongParameters) end |