Module: Softwear::Library

Defined in:
lib/softwear/lib.rb,
lib/softwear/library/spec.rb,
lib/softwear/library/enqueue.rb,
lib/softwear/library/version.rb,
lib/softwear/library/spec_dump.rb,
lib/softwear/library/capistrano.rb,
lib/softwear/library/light_server.rb,
lib/softwear/library/api_controller.rb,
lib/softwear/library/controller_authentication.rb

Defined Under Namespace

Modules: ControllerAuthentication, Enqueue, Spec, SpecDump Classes: ApiController, LightServer

Constant Summary collapse

GEMFILE_OPENER =
"# === BEGIN SOFTWEAR LIB GEMS === #"
GEMFILE_CLOSER =
"# === END SOFTWEAR LIB GEMS === #"
COMMON_GEMS =
%(
gem 'rails', '~> 4.2.3'

gem 'mysql2'
gem 'sass-rails'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'activeresource'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'hirb'
gem 'momentjs-rails', '~> 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '4.7.14'
gem 'js-routes'
gem 'inherited_resources'
gem 'figaro'
gem 'paranoia', '~> 2.0'
gem 'paperclip', '~> 4.3.0'
gem 'kaminari'
gem 'whenever'
gem 'dumpsync', git: 'git://github.com/AnnArborTees/dumpsync.git'
gem 'bootstrap_form'
gem 'acts_as_warnable', git: 'git://github.com/AnnArborTees/acts_as_warnable.git'

group :development do
  gem 'capistrano', '~> 3.2.0'
  gem 'capistrano-rails'
  gem 'capistrano-rvm', github: 'AnnArborTees/rvm'
  gem 'capistrano-bundler', github: 'AnnArborTees/bundler'
  gem 'better_errors', '>= 0.3.2'
  gem 'binding_of_caller'
end

group :development, :test do
  gem 'byebug', platforms: :mri
  gem 'rubinius-debugger', platforms: :rbx
end

group :test do
  gem "rspec-rails", "~> 3.2.0"
  gem 'factory_girl_rails', '>= 4.2.0', require: true
  gem 'capybara', '~> 2.4'
  gem 'capybara-webkit'
  gem 'webmock', require: false
  gem 'rspec-mocks'
  gem 'rspec-retry'
  gem 'email_spec'
  gem 'selenium-webdriver'
  gem 'shoulda-matchers'
end
)
VERSION =
"3.3.5"

Class Method Summary collapse

Class Method Details

.capistrano(context) ⇒ Object



3
4
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/softwear/library/capistrano.rb', line 3

def self.capistrano(context)
  context.instance_eval do
    Rake::Task["deploy:compile_assets"].clear

    ruby = fetch(:rvm_ruby_string) || fetch(:rvm_ruby_version)

    namespace :deploy do

      desc 'Assure softwear-lib is up to date before deploying'
      task :update_softwear_lib do
        on roles(:app), in: :sequence do
          execute "~/.rvm/bin/rvm #{ruby} do gem install --no-ri --no-rdoc softwear-lib"
        end
      end

      desc 'Signal the running rails app to restart'
      task :restart do
        on roles([:web, :app]), in: :sequence, wait: 5 do
          execute :mkdir, '-p', "#{release_path}/tmp"
          execute :touch, release_path.join('tmp/restart.txt')
        end
      end

      after :publishing, :restart_sidekiq_manager do
        on roles(:sidekiq) do
          execute 'sudo restart sidekiq-manager'
        end
      end

      # This is more problematic than helpful
=begin
      if !$LOAD_PATH.grep(/sunspot_solr/).empty? || fetch(:no_reindex)
        before :publishing, :reindex_solr do
          on roles(:db) do
            with rails_env: fetch(:rails_env) || fetch(:stage) do
              within(release_path) do
                execute :rake, 'sunspot:solr:reindex'
              end
            end
          end
        end
      end
=end

      # This is no longer necessary
      # before :updating, :update_softwear_lib
      after :publishing, :restart

      desc 'Compile assets'
      task :compile_assets => [:set_rails_env] do
        invoke 'deploy:assets:precompile_local'
        invoke 'deploy:assets:backup_manifest'
      end

      namespace :assets do

        desc "Precompile assets locally and then rsync to web servers"
        task :precompile_local do
          # compile assets locally
          run_locally do
            execute "RAILS_ENV=#{fetch(:stage)} bundle exec rake assets:precompile"
          end

          # rsync to each server
          assets_dir = "public/#{fetch(:assets_prefix) || 'assets'}"
          local_dir  = "./#{assets_dir}/"
          on roles( fetch(:assets_roles, [:web]) ) do
            # this needs to be done outside run_locally in order for host to exist
            remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/#{assets_dir}"

            execute "mkdir -p #{release_path}/#{assets_dir}"
            run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }

            if fetch(:asset_sync)
              with rails_env: fetch(:rails_env) || fetch(:stage) do
                within(release_path) do
                  if respond_to?(:with_rvm)
                    with_rvm(fetch(:task_ruby_version)) { execute :rake, 'assets:sync' }
                  else
                    execute :rake, 'assets:sync'
                  end
                end
              end
            end
          end

          # clean up
          run_locally { execute "rm -rf #{local_dir}" }
        end
      end

    end
  end
end

.fix_sort_argument_error_on_rubiniusObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/softwear/lib.rb', line 79

def self.fix_sort_argument_error_on_rubinius
  # Rubinius calls Enumerator#sort! within Enumerator#sort_by,
  # # and Mail::PartsList calls sort_by within sort!... See the
  # problem?

  if RUBY_ENGINE == 'rbx'
    require 'mail'

    Mail::PartsList.class_eval do
      def map!(&block)
        Mail::PartsList.new(collect(&block))
      end

      def sort!(order = nil)
        return super() if order.nil?

        i = 0
        sorted = self.sort_by do |a|
          [get_order_value(a, order), i += 1]
        end
        self.clear
        sorted.each(&self.method(:<<))
      end
    end
  end
end

.fix_state_machine_around_validationObject



106
107
108
# File 'lib/softwear/lib.rb', line 106

def self.fix_state_machine_around_validation
  StateMachine::Integrations::ActiveModel.instance_eval { public :around_validation }
end