Skip to content

Commit

Permalink
Add Traits namespace with CollectionItem
Browse files Browse the repository at this point in the history
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
peteryates committed Dec 7, 2019
1 parent 86d492e commit b688946
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/govuk_design_system_formbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'govuk_design_system_formbuilder/builder'
require 'govuk_design_system_formbuilder/base'

require 'govuk_design_system_formbuilder/traits/collection_item'

require 'govuk_design_system_formbuilder/elements/hint'
require 'govuk_design_system_formbuilder/elements/label'
require 'govuk_design_system_formbuilder/elements/date'
Expand Down
18 changes: 18 additions & 0 deletions lib/govuk_design_system_formbuilder/traits/collection_item.rb
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

0 comments on commit b688946

Please sign in to comment.