-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Traits namespace with CollectionItem
CollectionItem will hold functionality that's specific to items belonging to a collection. Initially, this covers the retrieval of the value depending on what's passed into the :text_method, :value_method or :hint_method params. These arguments now accept and properly deal with procs Refs #68
- Loading branch information
1 parent
86d492e
commit b688946
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lib/govuk_design_system_formbuilder/traits/collection_item.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module GOVUKDesignSystemFormBuilder | ||
module Elements | ||
module Traits | ||
module CollectionItem | ||
private | ||
|
||
def retrieve(item, text_method) | ||
case text_method | ||
when Symbol, String | ||
item.send(text_method) | ||
when Proc | ||
text_method.call(item) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |