<commit_before># encoding: UTF-8

# Author::    <NAME>
# Copyright:: Copyright (c) 2009 <NAME>

class Sofa::Set::Dynamic < Sofa::Field

	include Sofa::Set

	attr_reader :storage,:workflow

	def initialize(meta = {})
		@meta        = meta
		@storage     = Sofa::Storage.instance self
		@workflow    = Sofa::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[:confirm] = :optional if meta[:tokens].to_a.include?('may_confirm')
		my[:confirm] = :mandatory if meta[:tokens].to_a.include?('should_confirm')
	end

	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

	def meta_dir
		my[:folder][:dir] if my[:folder]
	end

	def meta_path
		(my[:name] == 'main') ? my[:dir] : "#{my[:dir]}/#{my[:name].sub(/^main-?/,'').gsub('-','/')}"
	end

	def meta_base_path
		Sofa.base ? Sofa.base[:path] : my[:path]
	end

	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

	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? Sofa::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

	private

	def _val
		@storage.val
	end

	def _get(arg)
		(@workflow._get(arg) || super) unless @workflow._hide? arg
	end

	def _get_by_tmpl(arg,tmpl = '')
		if arg[:action] == :read || self != Sofa.base
			super
		else
			base_path = Sofa.transaction[my[:tid]].is_a?(Sofa::Field) ? nil : my[:base_path]
			action = "/#{my[:tid]}#{base_path}/update.html"
			<<_html
<form id="#{my[:name]}" method="post" enctype="multipart/form-data" action="#{action}">
#{super}</form>
_html
		end
	end

	def _get_by_self_reference(arg)
		super unless @workflow._hide?(arg)
	end

	def _g_login(arg)
		path = Sofa::Path.path_of arg[:conds]
		action = arg[:dest_action]
		<<_html
<form id="#{my[:name]}" method="post" action="#{my[:base_path]}/#{path}login.html">
	<input type="hidden" name="dest_action" value="#{action}" />
	<label for="id">id</label><input type="text" id="id" name="id" size="10" value="" />
	<label for="pw">pw</label><input type="password" id="pw" name="pw" size="10" value="" />
	<input type="submit" value="login" />
</form>
_html
	end

	def _g_done(arg)
		'done.'
	end<commit_msg>Set::Dynamic#_get_by_tmpl put base paths before tid steps.<commit_after># encoding: UTF-8

# Author::    <NAME>
# Copyright:: Copyright (c) 2009 <NAME>

class Sofa::Set::Dynamic < Sofa::Field

	include Sofa::Set

	attr_reader :storage,:workflow

	def initialize(meta = {})
		@meta        = meta
		@storage     = Sofa::Storage.instance self
		@workflow    = Sofa::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[:confirm] = :optional if meta[:tokens].to_a.include?('may_confirm')
		my[:confirm] = :mandatory if meta[:tokens].to_a.include?('should_confirm')
	end

	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

	def meta_dir
		my[:folder][:dir] if my[:folder]
	end

	def meta_path
		(my[:name] == 'main') ? my[:dir] : "#{my[:dir]}/#{my[:name].sub(/^main-?/,'').gsub('-','/')}"
	end

	def meta_base_path
		Sofa.base ? Sofa.base[:path] : my[:path]
	end

	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

	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? Sofa::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

	private

	def _val
		@storage.val
	end

	def _get(arg)
		(@workflow._get(arg) || super) unless @workflow._hide? arg
	end

	def _get_by_tmpl(arg,tmpl = '')
		if arg[:action] == :read || self != Sofa.base
			super
		else
			base_path = Sofa.transaction[my[:tid]].is_a?(Sofa::Field) ? nil : my[:base_path]
			action = "#{base_path}/#{my[:tid]}/update.html"
			<<_html
<form id="#{my[:name]}" method="post" enctype="multipart/form-data" action="#{action}">
#{super}</form>
_html
		end
	end

	def _get_by_self_reference(arg)
		super unless @workflow._hide?(arg)
	end

	def _g_login(arg)
		path = Sofa::Path.path_of arg[:conds]
		action = arg[:dest_action]
		<<_html
<form id="#{my[:name]}" method="post" action="#{my[:base_path]}/#{path}login.html">
	<input type="hidden" name="dest_action" value="#{action}" />
	<label for="id">id</label><input type="text" id="id" name="id" size="10" value="" />
	<label for="pw">pw</label><input type="password" id="pw" name="pw" size="10" value="" />
	<input type="submit" value="login" />
</form>
_html
	end

	def _g_done(arg)
		'done.'
	end
{'fraction_non_alphanumeric': 0.20046123824729467, 'fraction_numerical': 0.0031931878658861094, 'mean_word_length': 4.042933810375671, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3471154', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2218, 'n_words': 437}