Module: Bike::Set
Overview
- Author
-
Akira FUNAI
- Copyright
-
Copyright © 2009 Akira FUNAI
Defined Under Namespace
Instance Method Summary collapse
- #collect(&block) ⇒ Object
- #each(&block) ⇒ Object
- #errors ⇒ Object
- #inspect_items(indent = 0) ⇒ Object
- #item(*item_steps) ⇒ Object
- #meta_base_path ⇒ Object
- #meta_dir ⇒ Object
- #meta_path ⇒ Object
- #pending? ⇒ Boolean
- #val(*steps) ⇒ Object
Instance Method Details
#collect(&block) ⇒ Object
61 62 63 |
# File 'lib/set/_set.rb', line 61 def collect(&block) collect_item({}, &block) end |
#each(&block) ⇒ Object
65 66 67 |
# File 'lib/set/_set.rb', line 65 def each(&block) collect_item.each &block end |
#errors ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/set/_set.rb', line 48 def errors return {} if my[:id] =~ Bike::REX::ID_NEW && my[:parent].is_a?(Bike::Set::Dynamic) && my[:parent].workflow.is_a?(Bike::Workflow::Attachment) errors = {} @item_object.each_pair {|id, item| errors[id] = item.errors unless item.valid? || item.action == :delete } errors end |
#inspect_items(indent = 0) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/set/_set.rb', line 69 def inspect_items(indent = 0) my_action = action.inspect my_result = result.is_a?(::Hash) ? result.keys.sort.inspect.sub(/\A\[([\w\W]*)\]\z/, '{\1}') : result.inspect ' ' * indent + "<\"#{my[:id]}\" @action=#{my_action} @result=#{my_result}>\n" + @item_object.keys.sort.collect {|id| item = @item_object[id] if item.respond_to? :inspect_items item.inspect_items(indent + 1) else action = item.action.inspect result = item.result.inspect val = item.val.inspect ' ' * (indent + 1) + "<\"#{id}\" @action=#{action} @result=#{result} @val=#{val}>\n" end }.join end |
#item(*item_steps) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/set/_set.rb', line 32 def item(*item_steps) item_steps = item_steps.first if item_steps.first.is_a? ::Array return self if item_steps.empty? id, *item_steps = item_steps if id.is_a?(::String) && child = collect_item(:id => id).first item = item_steps.empty? ? child : child.item(*item_steps) block_given? ? yield(item) : item end end |
#meta_base_path ⇒ Object
20 21 22 |
# File 'lib/set/_set.rb', line 20 def Bike.base ? Bike.base[:path] : my[:path] end |
#meta_dir ⇒ Object
10 11 12 |
# File 'lib/set/_set.rb', line 10 def my[:folder][:dir] if my[:folder] end |
#meta_path ⇒ Object
14 15 16 17 18 |
# File 'lib/set/_set.rb', line 14 def ['main', nil].include?(my[:name]) ? my[:dir] : "#{my[:dir]}/#{my[:name].sub(/^main-?/, '').gsub('-', '/')}" end |
#pending? ⇒ Boolean
44 45 46 |
# File 'lib/set/_set.rb', line 44 def pending? !pending_items.empty? || action end |
#val(*steps) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/set/_set.rb', line 24 def val(*steps) if steps.empty? _val elsif i = item(steps) i.val end end |