Class: Bike::Checkbox

Inherits:
Field
  • Object
show all
Defined in:
lib/scalar/checkbox.rb

Overview

Author

Akira FUNAI

Copyright

Copyright © 2009 Akira FUNAI

Constant Summary

Constants inherited from Field

Field::DEFAULT_META

Instance Attribute Summary

Attributes inherited from Field

#action, #result

Instance Method Summary collapse

Methods inherited from Field

#[], #[]=, #commit, #create, #default_action, #delete, #empty?, #find_ancestor, #get, h, #inspect, instance, #item, #load, #load_default, #meta_admins, #meta_client, #meta_folder, #meta_full_name, #meta_group, #meta_name, #meta_owner, #meta_owners, #meta_roles, #meta_sd, #meta_short_name, #pending?, #permit?, #post, #update, #val, #valid?, #workflow

Methods included from I18n

_, bindtextdomain, domain, domain=, find_msg, lang, lang=, merge_msg!, msg, n_, parse_msg, po_dir, po_dir=

Constructor Details

#initialize(meta = {}) ⇒ Checkbox

Returns a new instance of Checkbox.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/scalar/checkbox.rb', line 8

def initialize(meta = {})
  if meta[:tokens]
    meta[:options] ||= meta[:tokens] - ['mandatory']
    meta[:options] = ['_on'] if meta[:options].empty?
    meta[:mandatory] = meta[:tokens].include?('mandatory') && Array(meta[:options]).size > 1
  end
  if meta[:options].size == 1 && meta[:default] =~ /^(on|true|yes)$/i
    meta[:default] = meta[:options].first
  end
  super
end

Instance Method Details

#errorsObject



20
21
22
23
24
25
26
# File 'lib/scalar/checkbox.rb', line 20

def errors
  if val.empty?
    my[:mandatory] ? [_('mandatory')] : []
  else
    (val - my[:options]).empty? ? [] : [_('no such option')]
  end
end