Class: Bike::Set::Dynamic

Inherits:
Field
  • Object
show all
Includes:
Bike::Set
Defined in:
lib/set/dynamic.rb,
lib/_widget/done.rb,
lib/_widget/navi.rb,
lib/_widget/login.rb,
lib/_widget/submit.rb,
lib/_widget/message.rb,
lib/_widget/view_ym.rb,
lib/_widget/action_create.rb

Overview

Author

Akira FUNAI

Copyright

Copyright © 2009-2010 Akira FUNAI

Constant Summary

Constants inherited from Field

Field::DEFAULT_META

Instance Attribute Summary collapse

Attributes inherited from Field

#action, #result

Instance Method Summary collapse

Methods included from Bike::Set

#collect, #each, #errors, #inspect_items, #item, #meta_base_path, #meta_dir, #meta_path, #pending?, #val

Methods inherited from Field

#[], #[]=, #create, #default_action, #delete, #empty?, #errors, #find_ancestor, 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 = {}) ⇒ Dynamic

Returns a new instance of Dynamic.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/set/dynamic.rb', line 12

def initialize(meta = {})
  @meta        = meta
  @storage     = Bike::Storage.instance self
  @meta        = workflow.default_meta.merge @meta
  @item_object = {}

  self.extend workflow.sd_module

  my[:item] ||= {
    'default' => {:item => {}}
  }
  my[:item].each {|type, item_meta|
    item_meta[:item] = workflow.default_sub_items.merge item_meta[:item]
  }

  my[:p_size] = meta[:max] if meta[:max]
  my[:preview] = :optional if Array(meta[:tokens]).include?('may_preview')
  my[:preview] = :mandatory if Array(meta[:tokens]).include?('should_preview')
  my[:order] = 'id'  if Array(meta[:tokens]).include? 'asc'
  my[:order] = '-id' if Array(meta[:tokens]).include? 'desc'
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



10
11
12
# File 'lib/set/dynamic.rb', line 10

def storage
  @storage
end

Instance Method Details

#commit(type = :temp) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/set/dynamic.rb', line 53

def commit(type = :temp)
  items = pending_items
  items.each {|id, item|
    item.commit(:temp) || next
    case type
      when :temp
        store(id, item) if @storage.is_a? Bike::Storage::Temp
      when :persistent
        store(id, item)
        item.commit :persistent
    end
  }
  if valid?
    @result = (@action == :update) ? items : @action
    @action = nil if type == :persistent
    self
  end
end

#get(arg = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/set/dynamic.rb', line 46

def get(arg = {})
  if !arg[:conds].is_a?(::Hash) || arg[:conds].empty?
    arg[:conds] = my[:conds].is_a?(::Hash) ? my[:conds].dup : {}
  end
  super
end

#meta_hrefObject



34
35
36
# File 'lib/set/dynamic.rb', line 34

def meta_href
  "#{Bike.uri}#{my[:path]}/"
end

#meta_tidObject



38
39
40
41
42
43
44
# File 'lib/set/dynamic.rb', line 38

def meta_tid
  unless @meta[:tid]
    t = Time.now
    @meta[:tid] = t.strftime('%m%d%H%M%S.') + t.usec.to_s
  end
  @meta[:tid]
end