Class: Bike::Meta::Id
Overview
- Author
-
Akira FUNAI
- Copyright
-
Copyright © 2009-2010 Akira FUNAI
Constant Summary
Constants inherited from Field
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(meta = {}) ⇒ Id
constructor
not include Bike::Meta as this is SHORT_ID, not a full id.
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 = {}) ⇒ Id
not include Bike::Meta as this is SHORT_ID, not a full id.
10 11 12 13 |
# File 'lib/meta/id.rb', line 10 def initialize( = {}) [:size] = $&.to_i if [:tokens] && [:tokens].first =~ /^\d+$/ super end |
Instance Method Details
#errors ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/meta/id.rb', line 15 def errors if (my[:max].to_i > 0) && (val.size > my[:max]) [_('too long: %{max} characters maximum') % {:max => my[:max]}] elsif (my[:min].to_i == 1) && val.empty? [_('mandatory')] elsif (my[:min].to_i > 0) && (val.size < my[:min]) [_('too short: %{min} characters minimum') % {:min => my[:min]}] elsif val !~ /\A#{Bike::REX::ID_SHORT}\z/ [_('malformatted id')] elsif ( my[:parent] && my[:parent][:id] !~ /00000000_#{val}$/ && my[:parent][:parent].is_a?(Bike::Set::Dynamic) && my[:parent][:parent].item(val) ) [_('duplicate id: %{id}') % {:id => val}] else [] end end |