Skip to content

Commit

Permalink
Run rubocop autocorrect for consistent styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 22, 2019
1 parent b76fc88 commit 2fe7798
Show file tree
Hide file tree
Showing 115 changed files with 1,625 additions and 1,434 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
source "https://rubygems.org"
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rspec-its'
# Specify gem dependencies in hydra-head.gemspec
Expand Down Expand Up @@ -30,9 +32,9 @@ else

case ENV['RAILS_VERSION']
when /^4.2/
gem 'coffee-rails', '~> 4.1.0'
gem 'responders', '~> 2.0'
gem 'sass-rails', '>= 5.0'
gem 'coffee-rails', '~> 4.1.0'
when /^4.[01]/
gem 'sass-rails', '< 5.0'
end
Expand Down
95 changes: 48 additions & 47 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rake/testtask'
begin
require 'bundler/setup'
Expand All @@ -6,31 +8,31 @@ rescue LoadError
end
Bundler::GemHelper.install_tasks

APP_ROOT= File.dirname(__FILE__)
APP_ROOT = File.dirname(__FILE__)
require 'solr_wrapper'
require 'fcrepo_wrapper'
require 'active_fedora/rake_support'
require 'engine_cart/rake_task'

desc "Run Continuous Integration"
task :ci => ['engine_cart:generate'] do
ENV['environment'] = "test"
desc 'Run Continuous Integration'
task ci: ['engine_cart:generate'] do
ENV['environment'] = 'test'
with_test_server do
Rake::Task['spec'].invoke
end
end

task :default => [:ci]
task default: [:ci]

directory 'pkg'

FRAMEWORKS = ['hydra-access-controls', 'hydra-core']
FRAMEWORKS = ['hydra-access-controls', 'hydra-core'].freeze

root = File.expand_path('../', __FILE__)
root = File.expand_path(__dir__)
version = File.read("#{root}/HYDRA_VERSION").strip
tag = "v#{version}"

(FRAMEWORKS + ['hydra-head']).each do |framework|
(FRAMEWORKS + ['hydra-head']).each do |framework|
namespace framework do
gem = "pkg/#{framework}-#{version}.gem"
gemspec = "#{framework}.gemspec"
Expand All @@ -41,84 +43,85 @@ tag = "v#{version}"

task :update_version_rb do
glob = root.dup
glob << "/#{framework}/lib/*" unless framework == "hydra-head"
glob << "/version.rb"
glob << "/#{framework}/lib/*" unless framework == 'hydra-head'
glob << '/version.rb'

file = Dir[glob].first
if file
ruby = File.read(file)

major, minor, tiny, pre = version.split('.')
pre = pre ? pre.inspect : "nil"
pre = pre ? pre.inspect : 'nil'

ruby.gsub!(/^(\s*)VERSION = ".*?"$/, "\\1VERSION = \"#{version}\"")
raise "Could not insert VERSION in #{file}" unless $1
raise "Could not insert VERSION in #{file}" unless Regexp.last_match(1)

File.open(file, 'w') { |f| f.write ruby }
end
end
task gem => %w(update_version_rb pkg) do
cmd = ""
cmd << "cd #{framework} && " unless framework == "hydra-head"
task gem => %w[update_version_rb pkg] do
cmd = ''
cmd << "cd #{framework} && " unless framework == 'hydra-head'
cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
sh cmd
end

task :build => [:clean, gem]
task :install => :build do
task build: [:clean, gem]
task install: :build do
sh "gem install #{gem}"
end

task :prep_release => [:ensure_clean_state, :build]
task prep_release: %i[ensure_clean_state build]

task :push => :build do
task push: :build do
sh "gem push #{gem}"
end
end
end

namespace :all do
task :build => FRAMEWORKS.map { |f| "#{f}:build" } + ['hydra-head:build']
task :install => FRAMEWORKS.map { |f| "#{f}:install" } + ['hydra-head:install']
task :push => FRAMEWORKS.map { |f| "#{f}:push" } + ['hydra-head:push']
task build: FRAMEWORKS.map { |f| "#{f}:build" } + ['hydra-head:build']
task install: FRAMEWORKS.map { |f| "#{f}:install" } + ['hydra-head:install']
task push: FRAMEWORKS.map { |f| "#{f}:push" } + ['hydra-head:push']

task :ensure_clean_state do
unless `git status -s | grep -v HYDRA_VERSION | grep -v HISTORY.textile`.strip.empty?
abort "[ABORTING] `git status` reports a dirty tree. Make sure all changes are committed"
abort '[ABORTING] `git status` reports a dirty tree. Make sure all changes are committed'
end

unless ENV['SKIP_TAG'] || `git tag | grep "#{tag}$"`.strip.empty?
abort "[ABORTING] `git tag` shows that #{tag} already exists. Has this version already\n"\
" been released? Git tagging can be skipped by setting SKIP_TAG=1"
' been released? Git tagging can be skipped by setting SKIP_TAG=1'
end
end

task :commit do
File.open('pkg/commit_message.txt', 'w') do |f|
f.puts "# Preparing for #{version} release\n"
f.puts
f.puts "# UNCOMMENT THE LINE ABOVE TO APPROVE THIS COMMIT"
f.puts '# UNCOMMENT THE LINE ABOVE TO APPROVE THIS COMMIT'
end

sh "git add . && git commit --verbose --template=pkg/commit_message.txt"
rm_f "pkg/commit_message.txt"
sh 'git add . && git commit --verbose --template=pkg/commit_message.txt'
rm_f 'pkg/commit_message.txt'
end

task :tag do
sh "git tag #{tag}"
sh "git push --tags"
sh 'git push --tags'
end

task :release => %w(ensure_clean_state build commit tag push)
task release: %w[ensure_clean_state build commit tag push]
end

desc "run all specs"
desc 'run all specs'
task :spec do
raise "test failures" unless all_modules("FCREPO_TEST_PORT=#{ENV['FCREPO_TEST_PORT']} SOLR_TEST_PORT=#{ENV['SOLR_TEST_PORT']} bundle exec rake spec")
raise 'test failures' unless all_modules("FCREPO_TEST_PORT=#{ENV['FCREPO_TEST_PORT']} SOLR_TEST_PORT=#{ENV['SOLR_TEST_PORT']} bundle exec rake spec")
end

desc "Remove any existing test deploys"
desc 'Remove any existing test deploys'
task :clean do
raise "test failures" unless all_modules('rake clean')
raise 'test failures' unless all_modules('rake clean')
end

def all_modules(cmd)
Expand All @@ -133,25 +136,23 @@ end
begin
require 'yard'
require 'yard/rake/yardoc_task'
project_root = File.expand_path(".")
project_root = File.expand_path('.')
doc_destination = File.join(project_root, 'doc')
if !File.exists?(doc_destination)
FileUtils.mkdir_p(doc_destination)
end
FileUtils.mkdir_p(doc_destination) unless File.exist?(doc_destination)

YARD::Rake::YardocTask.new(:doc) do |yt|
yt.files = ['*/lib/**/*.rb', project_root+"*", '*/app/**/*.rb']

yt.options << "-m" << "textile"
yt.options << "--protected"
yt.options << "--no-private"
yt.options << "-r" << "README.textile"
yt.options << "-o" << "doc"
yt.options << "--files" << "*.textile"
yt.files = ['*/lib/**/*.rb', project_root + '*', '*/app/**/*.rb']

yt.options << '-m' << 'textile'
yt.options << '--protected'
yt.options << '--no-private'
yt.options << '-r' << 'README.textile'
yt.options << '-o' << 'doc'
yt.options << '--files' << '*.textile'
end
rescue LoadError
desc "Generate YARD Documentation"
desc 'Generate YARD Documentation'
task :doc do
abort "Please install the YARD gem to generate rdoc."
abort 'Please install the YARD gem to generate rdoc.'
end
end
20 changes: 11 additions & 9 deletions hydra-access-controls/Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

APP_ROOT= File.expand_path(File.join(File.dirname(__FILE__),".."))
import "tasks/hydra-access-controls.rake"
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
import 'tasks/hydra-access-controls.rake'

desc 'Default: run specs.'
task :default => :spec
task default: :spec

desc "Run specs"
desc 'Run specs'
RSpec::Core::RakeTask.new do |t|
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.8/
if ENV['COVERAGE'] && RUBY_VERSION =~ /^1.8/
t.rcov = true
t.rcov_opts = %w{--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data}
t.rcov_opts = %w[--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data]
end
end

desc "clean"
desc 'clean'
task :clean do
#nop, required by hydra-head ci
# nop, required by hydra-head ci
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hydra::AccessControls
class EmbargoIndexer
def initialize(object)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hydra::AccessControls
class LeaseIndexer
def initialize(object)
Expand All @@ -9,4 +11,3 @@ def generate_solr_document
end
end
end

2 changes: 2 additions & 0 deletions hydra-access-controls/app/models/ability.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Allows you to use CanCan to control access to Models
class Ability
include Hydra::Ability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hydra
module AccessControls
extend ActiveSupport::Autoload
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# frozen_string_literal: true

module Hydra
module AccessControls
class AccessRight
# What these groups are called in the Hydra rights assertions:
PERMISSION_TEXT_VALUE_PUBLIC = 'public'.freeze
PERMISSION_TEXT_VALUE_AUTHENTICATED = 'registered'.freeze
PERMISSION_TEXT_VALUE_PUBLIC = 'public'
PERMISSION_TEXT_VALUE_AUTHENTICATED = 'registered'

# The values that get drawn to the page
VISIBILITY_TEXT_VALUE_PUBLIC = 'open'.freeze
VISIBILITY_TEXT_VALUE_EMBARGO = 'embargo'.freeze
VISIBILITY_TEXT_VALUE_LEASE = 'lease'.freeze
VISIBILITY_TEXT_VALUE_AUTHENTICATED = 'authenticated'.freeze
VISIBILITY_TEXT_VALUE_PRIVATE = 'restricted'.freeze
VISIBILITY_TEXT_VALUE_PUBLIC = 'open'
VISIBILITY_TEXT_VALUE_EMBARGO = 'embargo'
VISIBILITY_TEXT_VALUE_LEASE = 'lease'
VISIBILITY_TEXT_VALUE_AUTHENTICATED = 'authenticated'
VISIBILITY_TEXT_VALUE_PRIVATE = 'restricted'

# @param permissionable [#visibility, #permissions]
# @example
Expand All @@ -24,9 +26,9 @@ def initialize(permissionable)
delegate :persisted?, :permissions, :visibility, to: :permissionable
protected :persisted?, :permissions, :visibility


def open_access?
return true if has_visibility_text_for?(VISIBILITY_TEXT_VALUE_PUBLIC)

# We don't want to know if its under embargo, simply does it have a date.
# In this way, we can properly inform the label input
persisted_open_access_permission? && !permissionable.embargo_release_date.present?
Expand All @@ -35,54 +37,58 @@ def open_access?
def open_access_with_embargo_release_date?
return false unless permissionable_is_embargoable?
return true if has_visibility_text_for?(VISIBILITY_TEXT_VALUE_EMBARGO)

# We don't want to know if its under embargo, simply does it have a date.
# In this way, we can properly inform the label input
persisted_open_access_permission? && permissionable.embargo_release_date.present?
end

def authenticated_only?
return false if open_access?

has_permission_text_for?(PERMISSION_TEXT_VALUE_AUTHENTICATED) ||
has_visibility_text_for?(VISIBILITY_TEXT_VALUE_AUTHENTICATED)
end

alias :authenticated_only_access? :authenticated_only?
alias authenticated_only_access? authenticated_only?

def private?
return false if open_access?
return false if authenticated_only?
return false if open_access_with_embargo_release_date?

true
end

alias :private_access? :private?
alias private_access? private?

private

def persisted_open_access_permission?
if persisted?
has_permission_text_for?(PERMISSION_TEXT_VALUE_PUBLIC)
else
visibility.to_s == ''
end
def persisted_open_access_permission?
if persisted?
has_permission_text_for?(PERMISSION_TEXT_VALUE_PUBLIC)
else
visibility.to_s == ''
end
end

def on_or_after_any_embargo_release_date?
return true unless permissionable.embargo_release_date
permissionable.embargo_release_date.to_date < Date.today
end
def on_or_after_any_embargo_release_date?
return true unless permissionable.embargo_release_date

def permissionable_is_embargoable?
permissionable.respond_to?(:embargo_release_date)
end
permissionable.embargo_release_date.to_date < Date.today
end

def has_visibility_text_for?(text)
visibility == text
end
def permissionable_is_embargoable?
permissionable.respond_to?(:embargo_release_date)
end

def has_permission_text_for?(text)
!!permissions.detect { |perm| perm.agent_name == text }
end
def has_visibility_text_for?(text)
visibility == text
end

def has_permission_text_for?(text)
!!permissions.detect { |perm| perm.agent_name == text }
end
end
end
end
Loading

0 comments on commit 2fe7798

Please sign in to comment.