Class: Runo::Set::Dynamic

Inherits:
Field
  • Object
show all
Includes:
Runo::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 Runo::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?

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
# File 'lib/set/dynamic.rb', line 12

def initialize(meta = {})
  @meta        = meta
  @storage     = Runo::Storage.instance self
  @workflow    = Runo::Workflow.instance self
  @meta        = @workflow.class.const_get(:DEFAULT_META).merge @meta
  @item_object = {}

  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

#workflowObject (readonly)

Returns the value of attribute workflow.



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

def workflow
  @workflow
end

Instance Method Details

#commit(type = :temp) ⇒ Object



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

def commit(type = :temp)
  @workflow.before_commit

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

#get(arg = {}) ⇒ Object



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

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



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

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

#meta_tidObject



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

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