Module: DataMapper::Is::Select
- Defined in:
- lib/dm-is-select/is/select.rb,
lib/dm-is-select/is/version.rb
Overview
dm-is-select
A DataMapper plugin that makes getting the <select>
options from a Model easier.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
'0.0.3'
Instance Method Summary collapse
-
#is_select(select_field = :name, options = {}) ⇒ Object
Defines the field to use for the select menu.
Instance Method Details
#is_select(select_field = :name, options = {}) ⇒ Object
Defines the field to use for the select menu
Params
-
:field_name => the name of the field values shown in select
-
:options
-
:is_tree => whether if the current Model is an is :tree model. (Defaults to false)
-
Examples
is :select, :name
=> creates a <select> options array on the :name attribute of the model
is :select, :name, :is_tree => true
=> creates a <select> options array with the results ordered in hierarchical order
parent > child > grandchild for each parent
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dm-is-select/is/select.rb', line 34 def is_select(select_field = :name, = {}) raise ArgumentError, "The :select_field, must be an existing attribute in the Model. Got [ #{select_field.inspect} ]" unless properties.any?{ |p| p.name == select_field.to_sym } @select_options = { # add specical features if we are working with Tree Model :is_tree => false }.merge() @select_field = select_field # Add class & Instance methods extend DataMapper::Is::Select::ClassMethods # include DataMapper::Is::Select::InstanceMethods end |