Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .customink/catalog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: administrate-field-enum

owner: tailor-made # team definitions at https://app.opslevel.com/teams

purpose: # multiple choice
# - do_not_track # demo testing personal - will not be tracked in catalog
# - app
- library
# - configuration
# - other # example: frontend_dataset
deployment_type: # multiple choice
# - kubernetes
# - infrastructure_serverless
- package
# - cli
# - data
# - docker-image

# tier: tier_1 # Mission-critical service or repository. Failure could result in significant impact to revenue or reputation.
# tier: tier_2 # Customer-facing service or repository. Failure results in degraded experience for customers, although without significant impact to revenue or reputation.
# tier: tier_3 # Internal service or repository. Failure could result in productivity being compromised within the company.
# tier: tier_4 # Other service or repository. Failure doesn't result in immediate or significant impact.
tier: tier_na # this repo does not have a tier. typically libraries

properties:
public_facing: false
pci: false
pii: false
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @customink/tailor-made
24 changes: 24 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Bump/Close inactive PRs
on:
schedule:
- cron: "0 5 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-pr-stale: 30
days-before-pr-close: 90

stale-pr-label: "stale"
stale-pr-message: "This PR is open and inactive for 30 days. Merging PRs open after a long time is error-prone. Please proceed to merging or make a comment to keep it open. You can also prevent PRs from being tagged stale or closed with 'keep-open' tag. If there is no activity in 90 days, this PR will be closed"
close-pr-message: "This PR was closed because it has been inactive for 90 days since being marked as stale."

exempt-pr-labels: "keep-open,dependabot,dependencies"

repo-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Administrate Field Enum Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.9] - 2021/12/29
### Changed
- allow gem installation on Rails 4.2 and higher
8 changes: 4 additions & 4 deletions administrate-field-enum.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ $:.push File.expand_path('../lib', __FILE__)

Gem::Specification.new do |s|
s.name = 'administrate-field-enum'
s.version = '0.0.8'
s.authors = ['Balbina Santana', 'Adrian Rangel']
s.email = ['adrian@disruptiveangels.com']
s.version = '0.0.9'
s.authors = ['Daniel Wheeler', 'Tailor Made']
s.email = ['tailor.made@customink.com']
s.homepage = 'https://github.com/DisruptiveAngels/administrate-field-enum'
s.summary = 'Enum field plugin for Administrate'
s.description = s.summary
Expand All @@ -15,5 +15,5 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

s.add_dependency 'administrate'
s.add_dependency 'rails', '>= 4.2', '<= 6.0'
s.add_dependency 'rails', '>= 4.2'
end
4 changes: 1 addition & 3 deletions app/views/fields/enum/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ By default, the input is a select field for the enum attributes.
<%= f.select(
field.attribute,
options_for_select(
f.object.class.public_send(field.attribute.to_s.pluralize).map do |k, v|
[I18n.t("activerecord.attributes.#{f.object.class.name.underscore}.#{field.attribute.to_s.pluralize}.#{k}", default: k.humanize), k]
end,
field.filtered_options(f.object.class.public_send(field.attribute.to_s.pluralize)),
f.object.public_send(field.attribute.to_s)
),
{ include_blank: false },
Expand Down
10 changes: 10 additions & 0 deletions lib/administrate/field/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ def html_options
options[:html] || {}
end

def option_filter
options[:option_filter] || Proc.new { true }
end

def filtered_options(options)
options.select(&option_filter).map do |k, v|
[I18n.t("activerecord.attributes.#{resource.class.name.underscore}.#{attribute.to_s.pluralize}.#{k}", default: k.humanize), k]
end
end

class Engine < ::Rails::Engine
end
end
Expand Down
30 changes: 30 additions & 0 deletions spec/lib/administrate/field/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,34 @@
expect(field.html_options[:class]).to be_nil
end
end

describe '#option_filter' do
it 'returns a supplied option_filter Proc' do
page = :form
option_filter = Proc.new { |option| option != 'x' }
field = Administrate::Field::Enum.with_options(option_filter: option_filter)
.new(:status, 'status', page)

expect(field.option_filter).to eq(option_filter)
end

it 'returns a no-op filter Proc by default' do
page = :form
field = Administrate::Field::Enum.new(:status, 'status', page)

expect(field.evaluator.call).to be_truthy
end
end

describe '#filtered_options' do
it 'returns array of filtered arrays' do
page = :form
options = ['I', 'Am', 'Groot']
option_filter = Proc.new { |option| option != 'Am' }
field = Administrate::Field::Enum.with_options(option_filter: option_filter)
.new(:status, 'status', page)

expect(field.filtered_options(options)).to eq([['I', 'I'], ['Groot', 'Groot']])
end
end
end