human_attributes 0.1.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 (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +7 -0
  6. data/Gemfile +14 -0
  7. data/Gemfile.lock +187 -0
  8. data/Guardfile +15 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +402 -0
  11. data/Rakefile +10 -0
  12. data/human_attributes.gemspec +30 -0
  13. data/lib/human_attributes/active_record_extension.rb +53 -0
  14. data/lib/human_attributes/config.rb +92 -0
  15. data/lib/human_attributes/engine.rb +24 -0
  16. data/lib/human_attributes/errors.rb +46 -0
  17. data/lib/human_attributes/formatters/base.rb +27 -0
  18. data/lib/human_attributes/formatters/boolean.rb +10 -0
  19. data/lib/human_attributes/formatters/custom.rb +17 -0
  20. data/lib/human_attributes/formatters/date.rb +9 -0
  21. data/lib/human_attributes/formatters/enumerize.rb +11 -0
  22. data/lib/human_attributes/formatters/numeric.rb +11 -0
  23. data/lib/human_attributes/formatters_builder.rb +44 -0
  24. data/lib/human_attributes/method_builder.rb +20 -0
  25. data/lib/human_attributes/version.rb +3 -0
  26. data/lib/human_attributes.rb +26 -0
  27. data/lib/tasks/human_attributes_tasks.rake +32 -0
  28. data/spec/dummy/README.rdoc +28 -0
  29. data/spec/dummy/Rakefile +6 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  31. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  34. data/spec/dummy/app/models/purchase.rb +28 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/spec/dummy/bin/bundle +3 -0
  37. data/spec/dummy/bin/rails +4 -0
  38. data/spec/dummy/bin/rake +4 -0
  39. data/spec/dummy/bin/setup +29 -0
  40. data/spec/dummy/config/application.rb +32 -0
  41. data/spec/dummy/config/boot.rb +5 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +41 -0
  45. data/spec/dummy/config/environments/production.rb +79 -0
  46. data/spec/dummy/config/environments/test.rb +42 -0
  47. data/spec/dummy/config/initializers/assets.rb +11 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  50. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/spec/dummy/config/initializers/inflections.rb +16 -0
  52. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  53. data/spec/dummy/config/initializers/session_store.rb +3 -0
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/spec/dummy/config/locales/en.yml +25 -0
  56. data/spec/dummy/config/routes.rb +56 -0
  57. data/spec/dummy/config/secrets.yml +22 -0
  58. data/spec/dummy/config.ru +4 -0
  59. data/spec/dummy/db/development.sqlite3 +0 -0
  60. data/spec/dummy/db/migrate/20161113032308_create_purchases.rb +15 -0
  61. data/spec/dummy/db/schema.rb +28 -0
  62. data/spec/dummy/db/test.sqlite3 +0 -0
  63. data/spec/dummy/log/development.log +16 -0
  64. data/spec/dummy/log/test.log +25913 -0
  65. data/spec/dummy/public/404.html +67 -0
  66. data/spec/dummy/public/422.html +67 -0
  67. data/spec/dummy/public/500.html +66 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/spec/assets/image.png +0 -0
  70. data/spec/dummy/spec/assets/video.mp4 +0 -0
  71. data/spec/dummy/spec/factories/purchases.rb +26 -0
  72. data/spec/dummy/spec/lib/active_record_extension_spec.rb +402 -0
  73. data/spec/dummy/spec/support/test_helpers.rb +5 -0
  74. data/spec/rails_helper.rb +28 -0
  75. data/spec/spec_helper.rb +9 -0
  76. metadata +293 -0
@@ -0,0 +1,30 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem"s version:
4
+ require "human_attributes/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "human_attributes"
9
+ s.version = HumanAttributes::VERSION
10
+ s.authors = ["Platanus", "Leandro Segovia"]
11
+ s.email = ["rubygems@platan.us", "ldlsegovia@gmail.com"]
12
+ s.homepage = "https://github.com/platanus/human_attributes"
13
+ s.summary = "Gem to generate human readable ActiveRecord attributes"
14
+ s.description = "Gem to convert ActiveRecord attributes and methods to human readable attributes"
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split($/).reject { |fn| fn.start_with? "spec" }
18
+ s.bindir = "exe"
19
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ s.test_files = Dir["spec/**/*"]
21
+
22
+ s.add_dependency "rails", "~> 4.2", ">= 4.2.0"
23
+ s.add_dependency "enumerize", "~> 1.1", ">= 1.1.1"
24
+ s.add_dependency "factory_girl_rails", "~> 4.6.0"
25
+ s.add_development_dependency "pry"
26
+ s.add_development_dependency "pry-rails"
27
+ s.add_development_dependency "sqlite3"
28
+ s.add_development_dependency "rspec-rails", "~> 3.4.0"
29
+ s.add_development_dependency "guard-rspec", "~> 4.7"
30
+ end
@@ -0,0 +1,53 @@
1
+ module HumanAttributes
2
+ module ActiveRecordExtension
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+ def humanize(*attrs, options)
7
+ formatters = HumanAttributes::FormattersBuilder.new(attrs, options).build
8
+ @builder ||= HumanAttributes::MethodBuilder.new(self)
9
+ @humanizers ||= []
10
+ formatters.each { |formatter| @humanizers << @builder.build(formatter) }
11
+ end
12
+
13
+ def humanize_attributes(options = {})
14
+ included_attrs = options.fetch(:only, nil)
15
+ excluded_attrs = options.fetch(:except, nil)
16
+ columns.each do |col|
17
+ next if col.name.ends_with?("_id")
18
+ next if included_attrs && !included_attrs.include?(col.name.to_sym)
19
+ next if excluded_attrs && excluded_attrs.include?(col.name.to_sym)
20
+ humanize_from_type(col)
21
+ end
22
+ end
23
+
24
+ def humanizers
25
+ return [] unless @humanizers
26
+ @humanizers.uniq!
27
+ @humanizers.reject! { |method| !method_defined?(method) }
28
+ @humanizers
29
+ end
30
+
31
+ private
32
+
33
+ def humanize_from_type(col)
34
+ if col.name == "id"
35
+ humanize(:id, custom: { formatter: ->(_o, value) { "#{model_name.human}: ##{value}" } })
36
+ elsif [:date, :datetime].include?(col.type)
37
+ humanize_date(col.name)
38
+ elsif [:decimal, :float, :integer].include?(col.type)
39
+ humanize(col.name, delimiter: true)
40
+ elsif col.type == :boolean
41
+ humanize(col.name, boolean: true)
42
+ end
43
+ end
44
+
45
+ def humanize_date(attr_name)
46
+ humanize(attr_name, date: true)
47
+ humanize(attr_name, date: { format: :short, suffix: "to_short_date" })
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ ActiveRecord::Base.send(:include, HumanAttributes::ActiveRecordExtension)
@@ -0,0 +1,92 @@
1
+ module HumanAttributes
2
+ module Config
3
+ TYPES = [
4
+ {
5
+ name: :currency,
6
+ category: :numeric,
7
+ formatter: :number_to_currency,
8
+ suffix: :to_currency
9
+ },
10
+ {
11
+ name: :number,
12
+ category: :numeric,
13
+ formatter: :number_to_human,
14
+ suffix: :to_human
15
+ },
16
+ {
17
+ name: :size,
18
+ category: :numeric,
19
+ formatter: :number_to_human_size,
20
+ suffix: :to_human_size
21
+ },
22
+ {
23
+ name: :percentage,
24
+ category: :numeric,
25
+ formatter: :number_to_percentage,
26
+ suffix: :to_percentage
27
+ },
28
+ {
29
+ name: :phone,
30
+ category: :numeric,
31
+ formatter: :number_to_phone,
32
+ suffix: :to_phone
33
+ },
34
+ {
35
+ name: :delimiter,
36
+ category: :numeric,
37
+ formatter: :number_with_delimiter,
38
+ suffix: :with_delimiter
39
+ },
40
+ {
41
+ name: :precision,
42
+ category: :numeric,
43
+ formatter: :number_with_precision,
44
+ suffix: :with_precision
45
+ },
46
+ {
47
+ name: :date,
48
+ category: :date,
49
+ suffix: :to_human_date
50
+ },
51
+ {
52
+ name: :boolean,
53
+ category: :boolean,
54
+ suffix: :to_human_boolean
55
+ },
56
+ {
57
+ name: :enumerize,
58
+ category: :enumerize,
59
+ suffix: :to_human_enum
60
+ },
61
+ {
62
+ name: :custom,
63
+ category: :custom,
64
+ suffix: :to_custom_value
65
+ }
66
+ ]
67
+
68
+ def category_by_type(type)
69
+ type_config(type)[:category]
70
+ end
71
+
72
+ def formatter_by_type(type)
73
+ type_config(type)[:formatter]
74
+ end
75
+
76
+ def suffix_by_type(type)
77
+ type_config(type)[:suffix]
78
+ end
79
+
80
+ def known_type?(type)
81
+ !!type_config(type)
82
+ end
83
+
84
+ def type_config(type)
85
+ TYPES.select { |t| t[:name] == type }.first
86
+ end
87
+
88
+ def raise_error(error_class)
89
+ raise "HumanAttributes::Error::#{error_class}".constantize.new
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,24 @@
1
+ module HumanAttributes
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace HumanAttributes
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, fixture: false
7
+ g.fixture_replacement :factory_girl, dir: "spec/factories"
8
+ end
9
+
10
+ initializer "initialize" do
11
+ require_relative "./config"
12
+ require_relative "./errors"
13
+ require_relative "./formatters_builder"
14
+ require_relative "./formatters/base"
15
+ require_relative "./formatters/numeric"
16
+ require_relative "./formatters/date"
17
+ require_relative "./formatters/boolean"
18
+ require_relative "./formatters/enumerize"
19
+ require_relative "./formatters/custom"
20
+ require_relative "./method_builder"
21
+ require_relative "./active_record_extension"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,46 @@
1
+ module HumanAttributes
2
+ module Error
3
+ class NotImplemented < Exception
4
+ def initialize
5
+ super("formatter not implemented")
6
+ end
7
+ end
8
+
9
+ class InvalidHumanizeConfig < Exception
10
+ def initialize
11
+ super("humanize options needs to be a Hash")
12
+ end
13
+ end
14
+
15
+ class NotEnumerizeAttribute < Exception
16
+ def initialize
17
+ super("needs to be an Enumerize::Value object")
18
+ end
19
+ end
20
+
21
+ class MissingFormatterOption < Exception
22
+ def initialize
23
+ super("custom type needs formatter option with a proc")
24
+ end
25
+ end
26
+
27
+ class InvalidType < Exception
28
+ def initialize
29
+ types = HumanAttributes::Config::TYPES.map { |t| t[:name] }
30
+ super("type needs to be one of: #{types.join(', ')}")
31
+ end
32
+ end
33
+
34
+ class RequiredAttributeType < Exception
35
+ def initialize
36
+ super("type is required")
37
+ end
38
+ end
39
+
40
+ class InvalidAttributeOptions < Exception
41
+ def initialize
42
+ super("options needs to be a Hash")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module HumanAttributes
2
+ module Formatters
3
+ class Base
4
+ include HumanAttributes::Config
5
+
6
+ attr_reader :attribute, :type, :options, :default, :suffix
7
+
8
+ def initialize(attribute, type, options)
9
+ @attribute = attribute.to_sym
10
+ @type = type.to_sym
11
+ @default = options.delete(:default)
12
+ @suffix = options.delete(:suffix)
13
+ @options = options
14
+ end
15
+
16
+ def method_name
17
+ return "human_#{attribute}" if suffix.blank?
18
+ return "#{attribute}_#{suffix_by_type(type)}" if suffix == true
19
+ "#{attribute}_#{suffix}"
20
+ end
21
+
22
+ def apply(_instance, _value)
23
+ raise_error('NotImplemented')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module HumanAttributes
2
+ module Formatters
3
+ class Boolean < Base
4
+ def apply(_instance, value)
5
+ key = !!value ? "positive" : "negative"
6
+ I18n.t("boolean.#{key}")
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module HumanAttributes
2
+ module Formatters
3
+ class Custom < Base
4
+ attr_reader :formatter
5
+
6
+ def initialize(attribute, type, options)
7
+ @formatter = options.delete(:formatter)
8
+ raise_error('MissingFormatterOption') unless formatter.is_a?(Proc)
9
+ super
10
+ end
11
+
12
+ def apply(instance, value)
13
+ formatter.call(instance, value)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module HumanAttributes
2
+ module Formatters
3
+ class Date < Base
4
+ def apply(_instance, value)
5
+ I18n.l(value, options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module HumanAttributes
2
+ module Formatters
3
+ class Enumerize < Base
4
+ def apply(_instance, value)
5
+ return unless value
6
+ raise_error('NotEnumerizeAttribute') unless value.class.to_s == "Enumerize::Value"
7
+ value.text
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module HumanAttributes
2
+ module Formatters
3
+ class Numeric < Base
4
+ include ActionView::Helpers::NumberHelper
5
+
6
+ def apply(_instance, value)
7
+ send(formatter_by_type(type), value, options)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ module HumanAttributes
2
+ class FormattersBuilder
3
+ include HumanAttributes::Config
4
+
5
+ def initialize(attributes, config)
6
+ raise_error('InvalidHumanizeConfig') unless config.is_a?(Hash)
7
+ @attributes = attributes
8
+ @config = config
9
+ end
10
+
11
+ def build
12
+ formatters = []
13
+
14
+ get_types(@config).each do |type|
15
+ raise_error('InvalidType') unless known_type?(type)
16
+ options = get_options(@config[type])
17
+ formatters << @attributes.map do |attribute|
18
+ formatter_class(type).new(attribute, type, options)
19
+ end
20
+ end
21
+
22
+ formatters.flatten
23
+ end
24
+
25
+ private
26
+
27
+ def formatter_class(type)
28
+ category = category_by_type(type)
29
+ "HumanAttributes::Formatters::#{category.to_s.classify}".constantize
30
+ end
31
+
32
+ def get_types(options)
33
+ size = options.keys.count
34
+ raise_error('RequiredAttributeType') if size.zero?
35
+ options.keys
36
+ end
37
+
38
+ def get_options(options)
39
+ return {} if options == true
40
+ raise_error('InvalidAttributeOptions') unless options.is_a?(Hash)
41
+ options
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ module HumanAttributes
2
+ class MethodBuilder
3
+ include HumanAttributes::Config
4
+
5
+ attr_reader :model_class
6
+
7
+ def initialize(model_class)
8
+ @model_class = model_class
9
+ end
10
+
11
+ def build(formatter)
12
+ model_class.send(:define_method, formatter.method_name) do
13
+ value = send(formatter.attribute) || formatter.default
14
+ formatter.apply(self, value)
15
+ end
16
+
17
+ formatter.method_name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module HumanAttributes
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ require "enumerize"
2
+ require "human_attributes/engine"
3
+
4
+ module HumanAttributes
5
+ extend self
6
+
7
+ # You can add, in this module, your own configuration options as in the example below...
8
+ #
9
+ # attr_writer :my_option
10
+ #
11
+ # def my_option
12
+ # return "Default Value" unless @my_option
13
+ # @my_option
14
+ # end
15
+ #
16
+ # Then, you can customize the default behaviour (typically in a Rails initializer) like this:
17
+ #
18
+ # HumanAttributes.setup do |config|
19
+ # config.root_url = "Another value"
20
+ # end
21
+
22
+ def setup
23
+ yield self
24
+ require "human_attributes"
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require "factory_girl_rails"
2
+
3
+ namespace :human_attrs do
4
+ desc "Show generated human attributes for ActiveRecord models"
5
+ task :show, [:model] => [:environment] do |_t, args|
6
+ model_name = args[:model].tableize.singularize
7
+ model = args[:model].classify.constantize
8
+ instance = begin
9
+ FactoryGirl.build(model_name)
10
+ rescue
11
+ nil
12
+ end
13
+
14
+ if instance
15
+ instance.id = 1 if instance.respond_to?(:id)
16
+ instance.created_at = DateTime.current if instance.respond_to?(:created_at)
17
+ instance.updated_at = DateTime.current if instance.respond_to?(:updated_at)
18
+ end
19
+
20
+ result = model.humanizers.map do |m|
21
+ value = begin
22
+ instance.send(m)
23
+ rescue
24
+ nil
25
+ end
26
+
27
+ !!value ? "#{m} => #{value}" : m
28
+ end
29
+
30
+ puts result.join("\n")
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,28 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: purchases
4
+ #
5
+ # id :integer not null, primary key
6
+ # paid :boolean
7
+ # commission :decimal(, )
8
+ # quantity :integer
9
+ # state :string
10
+ # expired_at :datetime
11
+ # amount :decimal(, )
12
+ # description :text
13
+ # created_at :datetime not null
14
+ # updated_at :datetime not null
15
+ #
16
+
17
+ class Purchase < ActiveRecord::Base
18
+ extend Enumerize
19
+
20
+ STATES = %i{pending canceled finished}
21
+
22
+ enumerize :state, in: STATES, default: :pending
23
+
24
+ humanize_attributes
25
+ humanize :state, enumerize: true
26
+ humanize :commission, percentage: true
27
+ humanize :amount, currency: true
28
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "action_view/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require(*Rails.groups)
12
+ require "human_attributes"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
+ # config.time_zone = 'Central Time (US & Canada)'
23
+
24
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
+ # config.i18n.default_locale = :de
27
+
28
+ # Do not swallow errors in after_commit/after_rollback callbacks.
29
+ config.active_record.raise_in_transactional_callbacks = true
30
+ end
31
+ end
32
+