facets 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ProjectInfo +32 -25
- data/data/facets/index.yml +30 -6
- data/data/facets/units/binary/base.yaml +12 -0
- data/data/facets/units/binary/extra.yaml +8 -0
- data/data/facets/units/cex.yaml +7 -0
- data/data/facets/units/currency/base.yaml +268 -0
- data/data/facets/units/default.yaml +22 -0
- data/data/facets/units/dump_yaml.rb +309 -0
- data/data/facets/units/si/base.yaml +36 -0
- data/data/facets/units/si/derived.yaml +133 -0
- data/data/facets/units/si/extra.yaml +107 -0
- data/data/facets/units/standard.yaml +5 -0
- data/data/facets/units/uk.yaml +16 -0
- data/data/facets/units/uk/base.yaml +107 -0
- data/data/facets/units/us.yaml +16 -0
- data/data/facets/units/us/base.yaml +112 -0
- data/data/facets/units/xmethods/cached.yaml +83 -0
- data/data/facets/units/xmethods/mapping.yaml +85 -0
- data/lib/facet/array/join_sentence.rb +1 -0
- data/lib/facet/class/cattr.rb +1 -0
- data/lib/facet/class/cattr_accessor.rb +1 -0
- data/lib/facet/class/cattr_reader.rb +1 -0
- data/lib/facet/class/cattr_writer.rb +1 -0
- data/lib/facet/elementor.rb +1 -0
- data/lib/facet/enumerable/accumulate.rb +1 -0
- data/lib/facet/enumerable/collect_if.rb +1 -0
- data/lib/facet/enumerable/map_if.rb +1 -0
- data/lib/facet/file/self/append.rb +1 -0
- data/lib/facet/file/self/read_binary.rb +1 -0
- data/lib/facet/file/self/write.rb +1 -0
- data/lib/facet/json.rb +1 -0
- data/lib/facet/kernel/__self__.rb +1 -0
- data/lib/facet/kernel/methodname.rb +1 -0
- data/lib/facet/module/attr_query.rb +1 -0
- data/lib/facet/module/attr_validator.rb +1 -0
- data/lib/facet/module/inherit.rb +1 -0
- data/lib/facet/module/let.rb +1 -0
- data/lib/facet/module/mattr.rb +1 -0
- data/lib/facet/module/mattr_accessor.rb +1 -0
- data/lib/facet/module/mattr_reader.rb +1 -0
- data/lib/facet/module/mattr_writer.rb +1 -0
- data/lib/facet/module/singleton_to_module.rb +1 -0
- data/lib/facet/nilclass/op_cmp.rb +1 -0
- data/lib/facet/nilclass/succ.rb +1 -0
- data/lib/facet/recorder.rb +1 -0
- data/lib/facet/xoxo.rb +1 -0
- data/lib/facets/core/array.rb +1 -0
- data/lib/facets/core/array/join_sentence.rb +12 -0
- data/lib/facets/core/class.rb +4 -0
- data/lib/facets/core/{module → class}/cattr.rb +7 -9
- data/lib/facets/core/class/cattr_accessor.rb +2 -0
- data/lib/facets/core/class/cattr_reader.rb +3 -0
- data/lib/facets/core/class/cattr_writer.rb +2 -0
- data/lib/facets/core/dir/self/ls_r.rb +4 -9
- data/lib/facets/core/enumerable.rb +3 -0
- data/lib/facets/core/enumerable/accumulate.rb +25 -0
- data/lib/facets/core/enumerable/collect_if.rb +15 -0
- data/lib/facets/core/enumerable/ew.rb +1 -5
- data/lib/facets/core/enumerable/map_if.rb +3 -0
- data/lib/facets/core/file.rb +3 -0
- data/lib/facets/core/file/self/append.rb +8 -0
- data/lib/facets/core/file/self/create.rb +14 -8
- data/lib/facets/core/file/self/open_as_string.rb +31 -13
- data/lib/facets/core/file/self/read_binary.rb +8 -0
- data/lib/facets/core/file/self/read_list.rb +11 -7
- data/lib/facets/core/file/self/write.rb +8 -0
- data/lib/facets/core/fileutils/wc.rb +4 -9
- data/lib/facets/core/fileutils/which.rb +4 -9
- data/lib/facets/core/kernel.rb +2 -1
- data/lib/facets/core/kernel/__self__.rb +32 -0
- data/lib/facets/core/kernel/as.rb +1 -1
- data/lib/facets/core/kernel/assign_from.rb +3 -3
- data/lib/facets/core/kernel/assign_with.rb +2 -0
- data/lib/facets/core/kernel/me.rb +3 -2
- data/lib/facets/core/kernel/method_name.rb +2 -49
- data/lib/facets/core/kernel/methodname.rb +49 -0
- data/lib/facets/core/module.rb +9 -4
- data/lib/facets/core/module/attr_query.rb +56 -0
- data/lib/facets/core/module/attr_validator.rb +18 -0
- data/lib/facets/core/module/inherit.rb +70 -0
- data/lib/facets/core/module/integrate.rb +1 -1
- data/lib/facets/core/module/let.rb +55 -0
- data/lib/facets/core/module/mattr.rb +180 -0
- data/lib/facets/core/module/{cattr_accessor.rb → mattr_accessor.rb} +0 -0
- data/lib/facets/core/module/{cattr_reader.rb → mattr_reader.rb} +0 -0
- data/lib/facets/core/module/{cattr_writer.rb → mattr_writer.rb} +0 -0
- data/lib/facets/core/module/on_included.rb +3 -1
- data/lib/facets/core/module/singleton_to_module.rb +23 -0
- data/lib/facets/core/nilclass.rb +2 -0
- data/lib/facets/core/string/methodize.rb +4 -3
- data/lib/facets/core/string/modulize.rb +3 -3
- data/lib/facets/more/ansicode.rb +1 -1
- data/lib/facets/more/aspects.rb +1 -1
- data/lib/facets/more/basicobject.rb +67 -22
- data/lib/facets/more/classinherit.rb +2 -2
- data/lib/facets/more/cloneable.rb +1 -1
- data/lib/facets/more/consoleapp.rb +31 -20
- data/lib/facets/more/dictionary.rb +1 -1
- data/lib/facets/more/filelist.rb +2 -10
- data/lib/facets/more/functor.rb +6 -6
- data/lib/facets/more/json.rb +891 -0
- data/lib/facets/more/methodprobe.rb +1 -1
- data/lib/facets/more/multiton.rb +16 -8
- data/lib/facets/more/nilcomparable.rb +31 -49
- data/lib/facets/more/openobject.rb +50 -10
- data/lib/facets/more/recorder.rb +125 -0
- data/lib/facets/more/rtals.rb +199 -4
- data/lib/facets/more/typecast.rb +12 -12
- data/lib/facets/more/units.rb +20 -14
- data/lib/facets/more/xoxo.rb +519 -0
- data/setup.rb +283 -271
- data/test/lib/facets/core/array/test_at_rand.rb +1 -1
- data/test/lib/facets/core/array/test_delete_unless.rb +1 -1
- data/test/lib/facets/core/array/test_delete_values.rb +1 -1
- data/test/lib/facets/core/array/test_delete_values_at.rb +1 -1
- data/test/lib/facets/core/array/test_first.rb +1 -1
- data/test/lib/facets/core/array/test_head.rb +1 -1
- data/test/lib/facets/core/array/test_last_index.rb +1 -1
- data/test/lib/facets/core/array/test_merge.rb +1 -1
- data/test/lib/facets/core/array/test_mid.rb +1 -1
- data/test/lib/facets/core/array/test_middle.rb +1 -1
- data/test/lib/facets/core/array/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/array/test_op_store.rb +1 -1
- data/test/lib/facets/core/array/test_pick.rb +1 -1
- data/test/lib/facets/core/array/test_pos.rb +1 -1
- data/test/lib/facets/core/array/test_pull.rb +1 -1
- data/test/lib/facets/core/array/test_rand_index.rb +1 -1
- data/test/lib/facets/core/array/test_rand_subset.rb +1 -1
- data/test/lib/facets/core/array/test_range.rb +1 -1
- data/test/lib/facets/core/array/test_rotate.rb +1 -1
- data/test/lib/facets/core/array/test_select.rb +1 -1
- data/test/lib/facets/core/array/test_shuffle.rb +1 -1
- data/test/lib/facets/core/array/test_slap.rb +1 -1
- data/test/lib/facets/core/array/test_thru.rb +1 -1
- data/test/lib/facets/core/array/test_to_b.rb +1 -1
- data/test/lib/facets/core/array/test_to_h.rb +1 -1
- data/test/lib/facets/core/array/test_to_hash.rb +1 -1
- data/test/lib/facets/core/binding/self/test_of_caller.rb +1 -1
- data/test/lib/facets/core/binding/test___LINE__.rb +1 -1
- data/test/lib/facets/core/binding/test_call_stack.rb +1 -1
- data/test/lib/facets/core/binding/test_called.rb +1 -1
- data/test/lib/facets/core/binding/test_caller.rb +1 -1
- data/test/lib/facets/core/binding/test_defined.rb +1 -1
- data/test/lib/facets/core/binding/test_eval.rb +1 -1
- data/test/lib/facets/core/binding/test_local_variables.rb +1 -1
- data/test/lib/facets/core/binding/test_method_name.rb +1 -1
- data/test/lib/facets/core/binding/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/binding/test_op_store.rb +1 -1
- data/test/lib/facets/core/binding/test_self.rb +1 -1
- data/test/lib/facets/core/{module/test_cattr_accessor.rb → class/test_cattr.rb} +11 -3
- data/test/lib/facets/core/class/test_descendents.rb +1 -1
- data/test/lib/facets/core/class/test_method_name.rb +1 -1
- data/test/lib/facets/core/class/test_remove_descendents.rb +1 -1
- data/test/lib/facets/core/class/test_unix_path.rb +1 -1
- data/test/lib/facets/core/comparable/test_at_least.rb +1 -1
- data/test/lib/facets/core/comparable/test_clip.rb +1 -1
- data/test/lib/facets/core/comparable/test_cmp.rb +1 -1
- data/test/lib/facets/core/continuation/self/test_create.rb +1 -1
- data/test/lib/facets/core/date/test_days_in_month.rb +1 -1
- data/test/lib/facets/core/date/test_days_of_month.rb +1 -1
- data/test/lib/facets/core/date/test_stamp.rb +1 -1
- data/test/lib/facets/core/date/test_to_date.rb +1 -1
- data/test/lib/facets/core/date/test_to_s.rb +1 -1
- data/test/lib/facets/core/date/test_to_time.rb +1 -1
- data/test/lib/facets/core/dir/self/test_ancestor.rb +1 -1
- data/test/lib/facets/core/dir/self/test_ascend.rb +1 -1
- data/test/lib/facets/core/enumerable/self/test_combinations.rb +1 -1
- data/test/lib/facets/core/enumerable/self/test_cross.rb +1 -1
- data/test/lib/facets/core/enumerable/test_collect_with_index.rb +1 -1
- data/test/lib/facets/core/enumerable/test_commonality.rb +1 -1
- data/test/lib/facets/core/enumerable/test_compact_collect.rb +1 -1
- data/test/lib/facets/core/enumerable/test_cross.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_combination.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_pair.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_slice.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_unique_pair.rb +1 -1
- data/test/lib/facets/core/enumerable/test_entropy.rb +1 -1
- data/test/lib/facets/core/enumerable/test_every.rb +1 -1
- data/test/lib/facets/core/enumerable/test_ew.rb +1 -1
- data/test/lib/facets/core/enumerable/test_filter_collect.rb +1 -1
- data/test/lib/facets/core/enumerable/test_find_collisions.rb +1 -1
- data/test/lib/facets/core/enumerable/test_frequency.rb +1 -1
- data/test/lib/facets/core/enumerable/test_graph.rb +1 -1
- data/test/lib/facets/core/enumerable/test_ideal_entropy.rb +1 -1
- data/test/lib/facets/core/enumerable/test_none.rb +1 -1
- data/test/lib/facets/core/enumerable/test_occur.rb +1 -1
- data/test/lib/facets/core/enumerable/test_one.rb +1 -1
- data/test/lib/facets/core/enumerable/test_op_pow.rb +1 -1
- data/test/lib/facets/core/enumerable/test_partition_by.rb +1 -1
- data/test/lib/facets/core/enumerable/test_permute.rb +1 -1
- data/test/lib/facets/core/enumerable/test_probability.rb +1 -1
- data/test/lib/facets/core/enumerable/test_to_h.rb +1 -1
- data/test/lib/facets/core/enumerable/test_uniq_by.rb +1 -1
- data/test/lib/facets/core/file/self/test_create.rb +14 -9
- data/test/lib/facets/core/file/self/test_open_as_string.rb +21 -11
- data/test/lib/facets/core/file/self/test_read_list.rb +11 -8
- data/test/lib/facets/core/file/self/test_sanitize.rb +1 -1
- data/test/lib/facets/core/file/self/test_split_all.rb +1 -1
- data/test/lib/facets/core/float/test_round_at.rb +1 -1
- data/test/lib/facets/core/float/test_round_to.rb +1 -1
- data/test/lib/facets/core/hash/self/test_zipnew.rb +1 -1
- data/test/lib/facets/core/hash/test_alias.rb +1 -1
- data/test/lib/facets/core/hash/test_assert_has_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_assert_has_only_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_at.rb +1 -1
- data/test/lib/facets/core/hash/test_collate.rb +1 -1
- data/test/lib/facets/core/hash/test_each.rb +1 -1
- data/test/lib/facets/core/hash/test_each_with_index.rb +1 -1
- data/test/lib/facets/core/hash/test_each_with_key.rb +1 -1
- data/test/lib/facets/core/hash/test_graph.rb +1 -1
- data/test/lib/facets/core/hash/test_has_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_has_only_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_inverse.rb +1 -1
- data/test/lib/facets/core/hash/test_keys_to_s.rb +1 -1
- data/test/lib/facets/core/hash/test_keys_to_sym.rb +1 -1
- data/test/lib/facets/core/hash/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/hash/test_op_lshift.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_key.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_pair.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_value.rb +1 -1
- data/test/lib/facets/core/hash/test_replace_each.rb +1 -1
- data/test/lib/facets/core/hash/test_shuffle.rb +1 -1
- data/test/lib/facets/core/hash/test_slice.rb +1 -1
- data/test/lib/facets/core/hash/test_swap.rb +1 -1
- data/test/lib/facets/core/hash/test_swapkey.rb +1 -1
- data/test/lib/facets/core/hash/test_to_h.rb +1 -1
- data/test/lib/facets/core/hash/test_to_ostruct.rb +1 -1
- data/test/lib/facets/core/hash/test_to_ostruct_recurse.rb +1 -1
- data/test/lib/facets/core/hash/test_traverse.rb +1 -1
- data/test/lib/facets/core/hash/test_update_each.rb +1 -1
- data/test/lib/facets/core/hash/test_update_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_update_values.rb +1 -1
- data/test/lib/facets/core/hash/test_weave.rb +1 -1
- data/test/lib/facets/core/integer/test_factorial.rb +1 -1
- data/test/lib/facets/core/integer/test_multiple.rb +1 -1
- data/test/lib/facets/core/integer/test_ordinal.rb +1 -1
- data/test/lib/facets/core/integer/test_times_collect.rb +1 -1
- data/test/lib/facets/core/kernel/test___class__.rb +1 -1
- data/test/lib/facets/core/kernel/test_as.rb +1 -1
- data/test/lib/facets/core/kernel/test_assign_from.rb +1 -1
- data/test/lib/facets/core/kernel/test_assign_with.rb +1 -1
- data/test/lib/facets/core/kernel/test_bool.rb +1 -1
- data/test/lib/facets/core/kernel/test_bug.rb +1 -1
- data/test/lib/facets/core/kernel/test_call_stack.rb +1 -1
- data/test/lib/facets/core/kernel/test_called.rb +1 -1
- data/test/lib/facets/core/kernel/test_constant.rb +1 -1
- data/test/lib/facets/core/kernel/test_copy.rb +1 -1
- data/test/lib/facets/core/kernel/test_deep_copy.rb +1 -1
- data/test/lib/facets/core/kernel/test_demo.rb +1 -1
- data/test/lib/facets/core/kernel/test_fn.rb +1 -1
- data/test/lib/facets/core/kernel/test_generate_method_name.rb +1 -1
- data/test/lib/facets/core/kernel/test_get_by_id.rb +1 -1
- data/test/lib/facets/core/kernel/test_here.rb +1 -1
- data/test/lib/facets/core/kernel/test_in.rb +1 -1
- data/test/lib/facets/core/kernel/test_maybe.rb +1 -1
- data/test/lib/facets/core/kernel/test_metaclass.rb +1 -1
- data/test/lib/facets/core/kernel/test_method.rb +1 -1
- data/test/lib/facets/core/kernel/{test_method_name.rb → test_methodname.rb} +3 -3
- data/test/lib/facets/core/kernel/test_methods.rb +1 -1
- data/test/lib/facets/core/kernel/test_new.rb +1 -1
- data/test/lib/facets/core/kernel/test_object_class.rb +1 -1
- data/test/lib/facets/core/kernel/test_object_hexid.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_all.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_esc.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_facet.rb +1 -1
- data/test/lib/facets/core/kernel/test_resc.rb +1 -1
- data/test/lib/facets/core/kernel/test_returning.rb +1 -1
- data/test/lib/facets/core/kernel/test_send_as.rb +1 -1
- data/test/lib/facets/core/kernel/test_set_from.rb +1 -1
- data/test/lib/facets/core/kernel/test_set_with.rb +1 -1
- data/test/lib/facets/core/kernel/test_silently.rb +1 -1
- data/test/lib/facets/core/kernel/test_singleton.rb +1 -1
- data/test/lib/facets/core/kernel/test_superior.rb +1 -1
- data/test/lib/facets/core/kernel/test_supermethod.rb +1 -1
- data/test/lib/facets/core/kernel/test_this.rb +1 -1
- data/test/lib/facets/core/kernel/test_to_b.rb +1 -1
- data/test/lib/facets/core/kernel/test_to_bool.rb +1 -1
- data/test/lib/facets/core/kernel/test_uri.rb +1 -1
- data/test/lib/facets/core/kernel/test_val.rb +1 -1
- data/test/lib/facets/core/kernel/test_with_accessor.rb +1 -1
- data/test/lib/facets/core/matchdata/test_match.rb +1 -1
- data/test/lib/facets/core/matchdata/test_matchtree.rb +1 -1
- data/test/lib/facets/core/module/test_abstract.rb +1 -1
- data/test/lib/facets/core/module/test_alias_module_function.rb +1 -1
- data/test/lib/facets/core/module/test_ancestor.rb +1 -1
- data/test/lib/facets/core/module/test_basename.rb +1 -1
- data/test/lib/facets/core/module/test_by_name.rb +1 -1
- data/test/lib/facets/core/module/test_clone_using.rb +1 -1
- data/test/lib/facets/core/module/test_dirname.rb +1 -1
- data/test/lib/facets/core/module/test_equate_on.rb +1 -1
- data/test/lib/facets/core/module/test_generate_instance_method_name.rb +1 -1
- data/test/lib/facets/core/module/test_include_as.rb +1 -1
- data/test/lib/facets/core/module/test_inherit.rb +58 -0
- data/test/lib/facets/core/module/test_initializer.rb +1 -1
- data/test/lib/facets/core/module/test_instance_methods.rb +1 -1
- data/test/lib/facets/core/module/test_integrate.rb +1 -1
- data/test/lib/facets/core/module/test_let.rb +31 -0
- data/test/lib/facets/core/module/test_mattr.rb +71 -0
- data/test/lib/facets/core/module/test_memoize.rb +1 -1
- data/test/lib/facets/core/module/test_modspace.rb +1 -1
- data/test/lib/facets/core/module/test_namespace.rb +1 -1
- data/test/lib/facets/core/module/test_nesting.rb +1 -1
- data/test/lib/facets/core/module/test_on_included.rb +36 -0
- data/test/lib/facets/core/module/test_redef.rb +1 -1
- data/test/lib/facets/core/module/test_redefine_method.rb +1 -1
- data/test/lib/facets/core/module/test_redirect.rb +1 -1
- data/test/lib/facets/core/module/test_redirect_method.rb +1 -1
- data/test/lib/facets/core/module/test_remove.rb +1 -1
- data/test/lib/facets/core/module/test_rename.rb +1 -1
- data/test/lib/facets/core/module/test_rename_method.rb +1 -1
- data/test/lib/facets/core/module/test_revisal.rb +1 -1
- data/test/lib/facets/core/module/test_shadow_method.rb +1 -1
- data/test/lib/facets/core/module/test_sort_on.rb +1 -1
- data/test/lib/facets/core/module/test_undef.rb +1 -1
- data/test/lib/facets/core/module/test_wrap.rb +1 -1
- data/test/lib/facets/core/module/test_wrap_method.rb +1 -1
- data/test/lib/facets/core/nilclass/{test_to_f.rb → test_blank.rb} +5 -5
- data/test/lib/facets/core/nilclass/test_empty.rb +1 -1
- data/test/lib/facets/core/nilclass/test_include.rb +1 -1
- data/test/lib/facets/core/nilclass/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/nilclass/test_size.rb +1 -1
- data/test/lib/facets/core/nilclass/test_to_h.rb +1 -1
- data/test/lib/facets/core/{float → numeric}/test_approx.rb +4 -3
- data/test/lib/facets/core/numeric/test_ceil_multiple.rb +1 -1
- data/test/lib/facets/core/numeric/test_succ.rb +1 -1
- data/test/lib/facets/core/numeric/test_to_b.rb +1 -1
- data/test/lib/facets/core/ostruct/test___merge__.rb +1 -1
- data/test/lib/facets/core/ostruct/test___update__.rb +1 -1
- data/test/lib/facets/core/ostruct/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/ostruct/test_op_store.rb +1 -1
- data/test/lib/facets/core/proc/test_compose.rb +1 -1
- data/test/lib/facets/core/proc/test_to_method.rb +1 -1
- data/test/lib/facets/core/range/test_to_r.rb +1 -1
- data/test/lib/facets/core/range/test_to_range.rb +1 -1
- data/test/lib/facets/core/range/test_umbrella.rb +1 -1
- data/test/lib/facets/core/range/test_within.rb +1 -1
- data/test/lib/facets/core/regexp/test_arity.rb +1 -1
- data/test/lib/facets/core/regexp/test_to_re.rb +1 -1
- data/test/lib/facets/core/regexp/test_to_regexp.rb +1 -1
- data/test/lib/facets/core/string/self/test_interpolate.rb +1 -1
- data/test/lib/facets/core/string/self/test_patterns.rb +1 -1
- data/test/lib/facets/core/string/self/test_rand_letter.rb +1 -1
- data/test/lib/facets/core/string/test_align_center.rb +1 -1
- data/test/lib/facets/core/string/test_at_rand.rb +1 -1
- data/test/lib/facets/core/string/test_basename.rb +1 -1
- data/test/lib/facets/core/string/test_blank.rb +1 -1
- data/test/lib/facets/core/string/test_bracket.rb +1 -1
- data/test/lib/facets/core/string/test_camelcase.rb +1 -1
- data/test/lib/facets/core/string/test_camelize.rb +1 -1
- data/test/lib/facets/core/string/test_capitalized.rb +1 -1
- data/test/lib/facets/core/string/test_chars.rb +1 -1
- data/test/lib/facets/core/string/test_cmp.rb +1 -1
- data/test/lib/facets/core/string/test_demodulize.rb +1 -1
- data/test/lib/facets/core/string/test_downcase.rb +1 -1
- data/test/lib/facets/core/string/test_dresner.rb +1 -1
- data/test/lib/facets/core/string/test_each_char.rb +1 -1
- data/test/lib/facets/core/string/test_each_word.rb +1 -1
- data/test/lib/facets/core/string/test_first.rb +1 -1
- data/test/lib/facets/core/string/test_fold.rb +1 -1
- data/test/lib/facets/core/string/test_frequency.rb +1 -1
- data/test/lib/facets/core/string/test_humanize.rb +1 -1
- data/test/lib/facets/core/string/test_indent.rb +1 -1
- data/test/lib/facets/core/string/test_index_all.rb +1 -1
- data/test/lib/facets/core/string/test_last.rb +1 -1
- data/test/lib/facets/core/string/test_line_wrap.rb +1 -1
- data/test/lib/facets/core/string/test_lines.rb +1 -1
- data/test/lib/facets/core/string/test_lowercase.rb +1 -1
- data/test/lib/facets/core/string/test_margin.rb +1 -1
- data/test/lib/facets/core/string/test_methodize.rb +1 -1
- data/test/lib/facets/core/string/test_modulize.rb +1 -1
- data/test/lib/facets/core/string/test_mscan.rb +1 -1
- data/test/lib/facets/core/string/test_natcmp.rb +1 -1
- data/test/lib/facets/core/string/test_nchar.rb +1 -1
- data/test/lib/facets/core/string/test_pathize.rb +1 -1
- data/test/lib/facets/core/string/test_pop.rb +1 -1
- data/test/lib/facets/core/string/test_probability.rb +1 -1
- data/test/lib/facets/core/string/test_push.rb +1 -1
- data/test/lib/facets/core/string/test_quote.rb +1 -1
- data/test/lib/facets/core/string/test_rand_byte.rb +1 -1
- data/test/lib/facets/core/string/test_rand_index.rb +1 -1
- data/test/lib/facets/core/string/test_range.rb +1 -1
- data/test/lib/facets/core/string/test_range_all.rb +1 -1
- data/test/lib/facets/core/string/test_range_of_line.rb +1 -1
- data/test/lib/facets/core/string/test_regesc.rb +1 -1
- data/test/lib/facets/core/string/test_shatter.rb +1 -1
- data/test/lib/facets/core/string/test_shift.rb +1 -1
- data/test/lib/facets/core/string/test_shuffle.rb +1 -1
- data/test/lib/facets/core/string/test_similarity.rb +1 -1
- data/test/lib/facets/core/string/test_singular.rb +1 -1
- data/test/lib/facets/core/string/test_slap.rb +1 -1
- data/test/lib/facets/core/string/test_soundex.rb +1 -1
- data/test/lib/facets/core/string/test_succ.rb +1 -1
- data/test/lib/facets/core/string/test_to_a.rb +1 -1
- data/test/lib/facets/core/string/test_to_arr.rb +1 -1
- data/test/lib/facets/core/string/test_to_b.rb +1 -1
- data/test/lib/facets/core/string/test_to_const.rb +1 -1
- data/test/lib/facets/core/string/test_to_date.rb +1 -1
- data/test/lib/facets/core/string/test_to_proc.rb +1 -1
- data/test/lib/facets/core/string/test_to_re.rb +1 -1
- data/test/lib/facets/core/string/test_to_time.rb +1 -1
- data/test/lib/facets/core/string/test_unix_crypt.rb +1 -1
- data/test/lib/facets/core/string/test_unpack.rb +1 -1
- data/test/lib/facets/core/string/test_unshift.rb +1 -1
- data/test/lib/facets/core/string/test_upcase.rb +1 -1
- data/test/lib/facets/core/string/test_whitespace.rb +1 -1
- data/test/lib/facets/core/string/test_word_filter.rb +1 -1
- data/test/lib/facets/core/string/test_word_wrap.rb +1 -1
- data/test/lib/facets/core/string/test_words.rb +1 -1
- data/test/lib/facets/core/symbol/test_camelcase.rb +1 -1
- data/test/lib/facets/core/symbol/test_camelize.rb +1 -1
- data/test/lib/facets/core/symbol/test_capitalize.rb +1 -1
- data/test/lib/facets/core/symbol/test_capitalized.rb +1 -1
- data/test/lib/facets/core/symbol/test_downcase.rb +1 -1
- data/test/lib/facets/core/symbol/test_not.rb +1 -1
- data/test/lib/facets/core/symbol/test_pad.rb +1 -1
- data/test/lib/facets/core/symbol/test_succ.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_const.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_proc.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_str.rb +1 -1
- data/test/lib/facets/core/symbol/test_underscore.rb +1 -1
- data/test/lib/facets/core/symbol/test_upcase.rb +1 -1
- data/test/lib/facets/core/time/test_change.rb +1 -1
- data/test/lib/facets/core/time/test_elapse.rb +1 -1
- data/test/lib/facets/core/time/test_stamp.rb +1 -1
- data/test/lib/facets/core/time/test_to_date.rb +1 -1
- data/test/lib/facets/core/time/test_to_s.rb +1 -1
- data/test/lib/facets/core/time/test_to_time.rb +1 -1
- data/test/lib/facets/more/test_annotation.rb +1 -1
- data/test/lib/facets/more/test_ansicode.rb +1 -1
- data/test/lib/facets/more/test_association.rb +1 -1
- data/test/lib/facets/more/test_basicobject.rb +58 -0
- data/test/lib/facets/more/test_bbcode.rb +1 -1
- data/test/lib/facets/more/test_bitmask.rb +1 -1
- data/test/lib/facets/more/test_bytes.rb +1 -1
- data/test/lib/facets/more/test_classinherit.rb +1 -1
- data/test/lib/facets/more/test_classmethods.rb +1 -1
- data/test/lib/facets/more/test_coroutine.rb +1 -1
- data/test/lib/facets/more/test_crypt.rb +1 -1
- data/test/lib/facets/more/test_dictionary.rb +1 -1
- data/test/lib/facets/more/test_elementor.rb +48 -0
- data/test/lib/facets/more/test_enumerablepass.rb +1 -1
- data/test/lib/facets/more/test_floatstring.rb +1 -1
- data/test/lib/facets/more/test_functor.rb +1 -1
- data/test/lib/facets/more/test_inheritor.rb +1 -1
- data/test/lib/facets/more/test_interval.rb +1 -1
- data/test/lib/facets/more/test_json.rb +232 -0
- data/test/lib/facets/more/test_lisp.rb +1 -1
- data/test/lib/facets/more/test_lisp_format.rb +1 -1
- data/test/lib/facets/more/test_lrucache.rb +1 -1
- data/test/lib/facets/more/test_mathconstants.rb +1 -1
- data/test/lib/facets/more/test_methodprobe.rb +1 -1
- data/test/lib/facets/more/test_multipliers.rb +1 -1
- data/test/lib/facets/more/test_multiton.rb +1 -1
- data/test/lib/facets/more/test_nackclass.rb +1 -1
- data/test/lib/facets/more/test_nilcomparable.rb +6 -2
- data/test/lib/facets/more/test_openobject.rb +1 -1
- data/test/lib/facets/more/test_overload.rb +1 -1
- data/test/lib/facets/more/test_paramix.rb +1 -1
- data/test/lib/facets/more/test_preinitialize.rb +1 -1
- data/test/lib/facets/more/test_promoteself.rb +1 -1
- data/test/lib/facets/more/test_recorder.rb +44 -0
- data/test/lib/facets/more/test_snapshot.rb +1 -1
- data/test/lib/facets/more/test_statichash.rb +1 -1
- data/test/lib/facets/more/test_syncarray.rb +1 -1
- data/test/lib/facets/more/test_synchash.rb +1 -1
- data/test/lib/facets/more/test_tagiterator.rb +1 -1
- data/test/lib/facets/more/test_timer.rb +1 -1
- data/test/lib/facets/more/test_times.rb +1 -1
- data/test/lib/facets/more/test_tuple.rb +1 -1
- data/test/lib/facets/more/test_typecast.rb +2 -2
- data/test/lib/facets/more/test_uninheritable.rb +1 -1
- data/test/lib/facets/more/test_units.rb +16 -10
- data/test/lib/facets/more/test_xoxo.rb +288 -0
- data/test/lib/facets/more/test_yamlstruct.rb +1 -1
- metadata +92 -25
- data/lib/facet/kernel/instance.rb +0 -1
- data/lib/facet/module/cattr.rb +0 -1
- data/lib/facet/module/cattr_accessor.rb +0 -1
- data/lib/facet/module/cattr_reader.rb +0 -1
- data/lib/facet/module/cattr_writer.rb +0 -1
- data/lib/facets/core/kernel/instance.rb +0 -29
- data/test/FIXTURE/create_file +0 -1
- data/test/FIXTURE/open_as_string_file +0 -1
- data/test/FIXTURE/read_list_file +0 -6
- data/test/lib/facets/core/dir/self/test_ls_r.rb +0 -52
- data/test/lib/facets/core/fileutils/test_wc.rb +0 -68
- data/test/lib/facets/core/fileutils/test_which.rb +0 -61
- data/test/testdir.rb +0 -8
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
# but might prove a better means in the future.
|
|
42
42
|
#
|
|
43
43
|
# This script is provided for experimetnal purposes. Please inform the author
|
|
44
|
-
# if you find ways to improve it or put to an interesting use.
|
|
44
|
+
# if you find ways to improve it or put it to an interesting use.
|
|
45
45
|
#
|
|
46
46
|
# == Synopsis
|
|
47
47
|
#
|
data/lib/facets/more/multiton.rb
CHANGED
|
@@ -44,18 +44,22 @@
|
|
|
44
44
|
# end
|
|
45
45
|
#
|
|
46
46
|
# a = SomeMultitonClass.new(4)
|
|
47
|
-
# b = SomeMultitonClass.new(4)
|
|
47
|
+
# b = SomeMultitonClass.new(4) # a and b are same object
|
|
48
48
|
# c = SomeMultitonClass.new(2) # c is a different object
|
|
49
49
|
#
|
|
50
50
|
# == Previous Behavior
|
|
51
51
|
#
|
|
52
|
-
# In previous versions of Multion the #new method was made
|
|
52
|
+
# In previous versions of Multion the #new method was made
|
|
53
53
|
# private and #instance was used in its stay --just like Singleton.
|
|
54
|
-
# But this has proved less desirable for Multiton
|
|
55
|
-
# have multiple instances not just one.
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
54
|
+
# But this has proved less desirable for Multiton since Multitions can
|
|
55
|
+
# have multiple instances, not just one.
|
|
56
|
+
#
|
|
57
|
+
# So instead Multiton now defines #create as a private alias of
|
|
58
|
+
# the original #new method (jus tin case it is needed) and then
|
|
59
|
+
# defines #new to handle the multion, and #instance is provided
|
|
60
|
+
# as an alias for it.
|
|
61
|
+
#
|
|
62
|
+
# So if you must have the old behavior, all you need do is re-alias
|
|
59
63
|
# #new to #create and privatize it.
|
|
60
64
|
#
|
|
61
65
|
# class SomeMultitonClass
|
|
@@ -65,6 +69,8 @@
|
|
|
65
69
|
# ...
|
|
66
70
|
# end
|
|
67
71
|
#
|
|
72
|
+
# Then only #instance will be available for creating the Multiton.
|
|
73
|
+
#
|
|
68
74
|
# == How It Works
|
|
69
75
|
#
|
|
70
76
|
# A pool of objects is searched for a previously cached object,
|
|
@@ -136,6 +142,7 @@ module Multiton
|
|
|
136
142
|
|
|
137
143
|
end
|
|
138
144
|
|
|
145
|
+
#--
|
|
139
146
|
# Deprecated use, now use #private_multiton method after including Multiton
|
|
140
147
|
#
|
|
141
148
|
# module MultitonInstance
|
|
@@ -159,8 +166,9 @@ end
|
|
|
159
166
|
# return obj
|
|
160
167
|
# end
|
|
161
168
|
# end
|
|
162
|
-
#
|
|
169
|
+
#
|
|
163
170
|
# end
|
|
171
|
+
#++
|
|
164
172
|
|
|
165
173
|
|
|
166
174
|
# _____ _
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
# end
|
|
50
50
|
#
|
|
51
51
|
# To do so for a pre-existing class with a pre-existing #<=> method, you'll
|
|
52
|
-
# need to
|
|
52
|
+
# need to overide the method. As an example let's make Numeric comparable to nil.
|
|
53
53
|
#
|
|
54
54
|
# class Numeric
|
|
55
55
|
#
|
|
@@ -101,53 +101,31 @@ class NilClass
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# end
|
|
130
|
-
|
|
131
|
-
# DEPRECATED
|
|
132
|
-
#
|
|
133
|
-
# # Calling this method for a given class allows instances
|
|
134
|
-
# # of a class to be compared to nil using <=>.
|
|
135
|
-
# # Adapted from code by Paul Brannan (Ruby License)
|
|
136
|
-
# def nil_comparable(klass=self)
|
|
137
|
-
# klass.class_eval %{
|
|
138
|
-
# if method_defined?( :<=> )
|
|
139
|
-
# alias_method :compare_without_nil, :<=>
|
|
140
|
-
# else
|
|
141
|
-
# def compare_without_nil( other )
|
|
142
|
-
# raise TypeError, "Cannot compare \#{self.inspect} to \#{other.inspect}"
|
|
143
|
-
# end
|
|
144
|
-
# end
|
|
145
|
-
# def <=>( other )
|
|
146
|
-
# return 1 if other.nil?
|
|
147
|
-
# compare_without_nil( other )
|
|
148
|
-
# end
|
|
149
|
-
# }
|
|
150
|
-
# end
|
|
104
|
+
|
|
105
|
+
=begin DEPRECATED
|
|
106
|
+
|
|
107
|
+
module NilComparable
|
|
108
|
+
|
|
109
|
+
def self.included( mod )
|
|
110
|
+
mod.class_eval %{
|
|
111
|
+
if method_defined?( :<=> )
|
|
112
|
+
alias_method :compare_without_nil, :<=>
|
|
113
|
+
else
|
|
114
|
+
def compare_without_nil( other )
|
|
115
|
+
raise TypeError, "Cannot compare \#{self.inspect} to \#{other.inspect}"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def <=>( other )
|
|
120
|
+
return 1 if other.nil?
|
|
121
|
+
compare_without_nil( other )
|
|
122
|
+
end
|
|
123
|
+
}
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
=end
|
|
151
129
|
|
|
152
130
|
|
|
153
131
|
|
|
@@ -163,7 +141,11 @@ end
|
|
|
163
141
|
require 'test/unit'
|
|
164
142
|
|
|
165
143
|
class Mock < String
|
|
166
|
-
|
|
144
|
+
alias_method :compare_without_nil, :<=>
|
|
145
|
+
def <=>( other )
|
|
146
|
+
return 1 if other.nil?
|
|
147
|
+
compare_without_nil( other )
|
|
148
|
+
end
|
|
167
149
|
end
|
|
168
150
|
|
|
169
151
|
class TC_NilClass_Comparable < Test::Unit::TestCase
|
|
@@ -36,10 +36,12 @@
|
|
|
36
36
|
# advantage in benchmark tests.
|
|
37
37
|
#
|
|
38
38
|
#--
|
|
39
|
-
#
|
|
39
|
+
#
|
|
40
|
+
# Third, when an entry is not found 'null' is returned rather then 'nil'.
|
|
40
41
|
# This allows for run-on entries withuot error. Eg.
|
|
41
42
|
#
|
|
42
43
|
# OpenObject.new.a.b.c #=> null
|
|
44
|
+
#
|
|
43
45
|
#++
|
|
44
46
|
#
|
|
45
47
|
# == Author(s)
|
|
@@ -48,6 +50,7 @@
|
|
|
48
50
|
# * Thomas Sawyer
|
|
49
51
|
#
|
|
50
52
|
|
|
53
|
+
require 'facets/core/hash/keys_to_sym'
|
|
51
54
|
require 'facets/more/basicobject'
|
|
52
55
|
#require 'facets/more/nullclass'
|
|
53
56
|
|
|
@@ -56,15 +59,15 @@ class OpenObject < BasicObject
|
|
|
56
59
|
def initialize( init=nil )
|
|
57
60
|
case init
|
|
58
61
|
when Array
|
|
59
|
-
@table = Hash[*init]
|
|
62
|
+
@table = Hash[*init].keys_to_sym
|
|
60
63
|
when Hash
|
|
61
|
-
@table = init.
|
|
64
|
+
@table = init.keys_to_sym
|
|
62
65
|
when NilClass
|
|
63
66
|
@table = {}
|
|
64
67
|
when OpenObject
|
|
65
68
|
@table = init.__table__.dup
|
|
66
69
|
else
|
|
67
|
-
@table = init.to_h.
|
|
70
|
+
@table = init.to_h.keys_to_sym
|
|
68
71
|
end
|
|
69
72
|
end
|
|
70
73
|
|
|
@@ -108,11 +111,14 @@ class OpenObject < BasicObject
|
|
|
108
111
|
@table[name] = args[0]
|
|
109
112
|
self
|
|
110
113
|
else
|
|
111
|
-
|
|
114
|
+
if @table.key?(name)
|
|
112
115
|
@table[name]
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
elsif @parent
|
|
117
|
+
@parent.__send__(name)
|
|
118
|
+
else
|
|
119
|
+
nil
|
|
120
|
+
# Kernel.null #@table[name] = instance.class.new
|
|
121
|
+
end
|
|
116
122
|
end
|
|
117
123
|
end
|
|
118
124
|
|
|
@@ -134,18 +140,23 @@ class OpenObject < BasicObject
|
|
|
134
140
|
@table.each( &yld )
|
|
135
141
|
end
|
|
136
142
|
|
|
143
|
+
# shadow methods
|
|
144
|
+
|
|
137
145
|
def __table__ ; @table ; end
|
|
138
146
|
|
|
147
|
+
def __parent__ ; @parent ; end
|
|
148
|
+
def __parent__=(x) ; @parent = x ; end
|
|
149
|
+
|
|
139
150
|
#def __get__(k) ; @table.key?(k.to_sym) ? @table[k.to_sym] : null ; end
|
|
140
151
|
def __get__(k) ; @table[k.to_sym] ; end
|
|
141
152
|
def __set__(k) ; @table[k.to_sym]=v ; end
|
|
142
153
|
|
|
143
|
-
def __key__?(
|
|
154
|
+
def __key__?(k) ; @table.key?(k.to_sym) ; end
|
|
144
155
|
def __keys__ ; @table.keys ; end
|
|
145
156
|
|
|
146
157
|
def __update__( other )
|
|
147
158
|
other = Hash[*other] if other.is_a?(Array)
|
|
148
|
-
other.each{ |k, v| @table[k] = v }
|
|
159
|
+
other.each{ |k, v| @table[k.to_sym] = v }
|
|
149
160
|
end
|
|
150
161
|
|
|
151
162
|
def __merge__( other )
|
|
@@ -158,6 +169,35 @@ end
|
|
|
158
169
|
|
|
159
170
|
|
|
160
171
|
|
|
172
|
+
class CascadingOpenObject < OpenObject
|
|
173
|
+
|
|
174
|
+
def method_missing( sym, *args )
|
|
175
|
+
type = sym.to_s[-1,1]
|
|
176
|
+
name = sym.to_s.gsub(/[=!?]$/, '').to_sym
|
|
177
|
+
if type == '='
|
|
178
|
+
@table[name] = args[0]
|
|
179
|
+
elsif type == '!' and args.size > 0
|
|
180
|
+
@table[name] = args[0]
|
|
181
|
+
self
|
|
182
|
+
else
|
|
183
|
+
if @table.key?(name)
|
|
184
|
+
if Hash === @table[name]
|
|
185
|
+
self.__class__.new( @table[name] )
|
|
186
|
+
else
|
|
187
|
+
@table[name]
|
|
188
|
+
end
|
|
189
|
+
elsif @parent
|
|
190
|
+
@parent.__send__(name)
|
|
191
|
+
else
|
|
192
|
+
nil
|
|
193
|
+
# Kernel.null #@table[name] = instance.class.new
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
|
|
161
201
|
# _____ _
|
|
162
202
|
# |_ _|__ ___| |_
|
|
163
203
|
# | |/ _ \/ __| __|
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Multiton
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2005 Thomas Sawyer
|
|
5
|
+
#
|
|
6
|
+
# Ruby License
|
|
7
|
+
#
|
|
8
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
|
9
|
+
# software under the same terms as Ruby.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13
|
+
# FOR A PARTICULAR PURPOSE.
|
|
14
|
+
#
|
|
15
|
+
#
|
|
16
|
+
# ==========================================================================
|
|
17
|
+
# Revision History ::
|
|
18
|
+
# --------------------------------------------------------------------------
|
|
19
|
+
# 2006-04-04 trans * Created
|
|
20
|
+
# ==========================================================================
|
|
21
|
+
#++
|
|
22
|
+
|
|
23
|
+
require 'facets/more/basicobject'
|
|
24
|
+
|
|
25
|
+
#:title: Recorder
|
|
26
|
+
#
|
|
27
|
+
# Recorder is similar essentially a method probe. It records everthing
|
|
28
|
+
# that happens to it, building an internal parse tree. You can then
|
|
29
|
+
# pass a substitute object and apply the recoding to it. Or you can
|
|
30
|
+
# utilize the parse tree.
|
|
31
|
+
#
|
|
32
|
+
# The only limitation of Recorder is with special operators, like if, &&, ||, etc.
|
|
33
|
+
# Since they are not true methods they can't be recorded. (Too bad for Ruby.)
|
|
34
|
+
#
|
|
35
|
+
# == Synopsis
|
|
36
|
+
#
|
|
37
|
+
# class Z
|
|
38
|
+
# def name ; 'George' ; end
|
|
39
|
+
# def age ; 12 ; end
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# z = Z.new
|
|
43
|
+
#
|
|
44
|
+
# r = Recorder.new
|
|
45
|
+
# q = proc { |x| (x.name == 'George') & (x.age > 10) }
|
|
46
|
+
# x = q[r]
|
|
47
|
+
# x.__call__(z)
|
|
48
|
+
#
|
|
49
|
+
# produces
|
|
50
|
+
#
|
|
51
|
+
# true
|
|
52
|
+
#
|
|
53
|
+
# == Author(s)
|
|
54
|
+
#
|
|
55
|
+
# * Thomas Sawyer
|
|
56
|
+
#
|
|
57
|
+
|
|
58
|
+
class Recorder < BasicObject
|
|
59
|
+
|
|
60
|
+
def initialize( msg=nil )
|
|
61
|
+
@msg = msg
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def inspect
|
|
65
|
+
"<Recorder #{@msg.inspect}>"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def __call__( orig )
|
|
69
|
+
return orig unless @msg
|
|
70
|
+
|
|
71
|
+
sym = @msg[0]
|
|
72
|
+
args = @msg[1..-1].collect do |a|
|
|
73
|
+
Recorder === a ? a.__call__(orig) : a
|
|
74
|
+
end
|
|
75
|
+
obj = args.shift
|
|
76
|
+
|
|
77
|
+
obj.__send__( sym, *args )
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def method_missing( sym, *args, &blk )
|
|
81
|
+
self.__class__.new( [ sym, self, *args ] )
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# _____ _
|
|
89
|
+
# |_ _|__ ___| |_
|
|
90
|
+
# | |/ _ \/ __| __|
|
|
91
|
+
# | | __/\__ \ |_
|
|
92
|
+
# |_|\___||___/\__|
|
|
93
|
+
#
|
|
94
|
+
|
|
95
|
+
=begin test
|
|
96
|
+
|
|
97
|
+
require 'test/unit'
|
|
98
|
+
|
|
99
|
+
#class Object
|
|
100
|
+
# def &(o)
|
|
101
|
+
# self && o
|
|
102
|
+
# end
|
|
103
|
+
#end
|
|
104
|
+
|
|
105
|
+
class TCRecorder < Test::Unit::TestCase
|
|
106
|
+
|
|
107
|
+
class Z
|
|
108
|
+
def name ; 'George' ; end
|
|
109
|
+
def age ; 12 ; end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def setup
|
|
113
|
+
@z = Z.new
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_001
|
|
117
|
+
r = Recorder.new
|
|
118
|
+
q = proc { |x| (x.name == 'George') & (x.age > 10) }
|
|
119
|
+
x = q[r]
|
|
120
|
+
assert( x.__call__(@z) )
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
=end
|
data/lib/facets/more/rtals.rb
CHANGED
|
@@ -1,14 +1,209 @@
|
|
|
1
|
-
|
|
1
|
+
#--
|
|
2
|
+
# RubyTals
|
|
3
|
+
# Copyright (c) 2006 Thomas Sawyer
|
|
4
|
+
#
|
|
5
|
+
# Ruby License
|
|
6
|
+
#
|
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
|
8
|
+
# software under the same terms as Ruby.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
|
13
|
+
#++
|
|
2
14
|
|
|
3
|
-
require 'rexml'
|
|
15
|
+
require 'rexml/document'
|
|
16
|
+
|
|
17
|
+
# RubyTals
|
|
18
|
+
#
|
|
19
|
+
# RubyTals is a Ruby variation on Zope Page Templates and it's TAL specification.
|
|
20
|
+
# It differs from TAL in that it is specifically geared for use by Ruby.
|
|
21
|
+
#
|
|
22
|
+
# == Usage
|
|
23
|
+
#
|
|
24
|
+
# s = %q{
|
|
25
|
+
# <html>
|
|
26
|
+
# <body>
|
|
27
|
+
# <h1 rtal:content="x">[X]</h1>
|
|
28
|
+
# <div rtal:each="animal" rtal:do="a">
|
|
29
|
+
# <b rtal:content="a">[ANIMAL]</b>
|
|
30
|
+
# </div>
|
|
31
|
+
# <div rtal:if="animal.size > 1">
|
|
32
|
+
# There are <b rtal:body="animal.size">[ANIMAL SIZE]</b> animals.
|
|
33
|
+
# </div>
|
|
34
|
+
# </body>
|
|
35
|
+
# </html>
|
|
36
|
+
# }
|
|
37
|
+
#
|
|
38
|
+
# x = 'Our Little Zoo'
|
|
39
|
+
# animal = ['Zebra', 'Monkey', 'Tiger' ]
|
|
40
|
+
# out = ''
|
|
41
|
+
#
|
|
42
|
+
# prg = RubyTals.compile( s )
|
|
43
|
+
# puts eval(prg)
|
|
44
|
+
#
|
|
45
|
+
#
|
|
46
|
+
# == Note
|
|
47
|
+
#
|
|
48
|
+
# WARNING! This library is only minimally functional at this point.
|
|
49
|
+
# If you would like to use it please consider improving upon it!
|
|
50
|
+
#
|
|
51
|
+
# Presently rTAL clauses can run arbitraty Ruby code. Although
|
|
52
|
+
# upping the safety level before executing a compiled template
|
|
53
|
+
# should be sufficiently protective in most cases, perhaps it would
|
|
54
|
+
# be better to limit valid expressions to single object references,
|
|
55
|
+
# ie. 'this.that', and then use a substitution of '.' for '/'.
|
|
56
|
+
# Not only would this be highly protective, it would also be more
|
|
57
|
+
# compatible with the original TAL spec; albiet this isn't exacty
|
|
58
|
+
# how TALs interprets the '/' divider.
|
|
59
|
+
#
|
|
60
|
+
# On the other hand perhaps it is too much restraint. For instance
|
|
61
|
+
# it would require the if-clause in the above exmaple to be
|
|
62
|
+
# something like:
|
|
63
|
+
#
|
|
64
|
+
# <div rtal:if="animal/plenty">
|
|
65
|
+
#
|
|
66
|
+
# and have a definition in the evaluateing code:
|
|
67
|
+
#
|
|
68
|
+
# def animal.plenty
|
|
69
|
+
# size > 1
|
|
70
|
+
# end
|
|
71
|
+
#
|
|
72
|
+
# It's a classic Saftey vs. Usability trade-off.
|
|
73
|
+
# And something to consider for the future.
|
|
74
|
+
#
|
|
75
|
+
# == Author(s)
|
|
76
|
+
#
|
|
77
|
+
# * Thomas Sawyer
|
|
78
|
+
#
|
|
4
79
|
|
|
5
80
|
module RubyTals
|
|
6
81
|
|
|
7
|
-
def
|
|
82
|
+
def self.compile( xmlstr )
|
|
83
|
+
rxml = REXML::Document.new( xmlstr.strip )
|
|
84
|
+
parse( rxml )
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
#def self.evaluate( xomp, out='' )
|
|
88
|
+
# eval xomp
|
|
89
|
+
#end
|
|
90
|
+
|
|
91
|
+
def self.parse( xml )
|
|
92
|
+
building = ''
|
|
93
|
+
body = []
|
|
94
|
+
|
|
95
|
+
xml.each do |elem|
|
|
96
|
+
#p elem.class
|
|
97
|
+
|
|
98
|
+
tag, mode = [], nil
|
|
99
|
+
case elem
|
|
100
|
+
when REXML::Element
|
|
101
|
+
|
|
102
|
+
attributes, ruby_attributes = {}, {}
|
|
103
|
+
elem.attributes.each { |k, v|
|
|
104
|
+
if k =~ /^ruby:/i
|
|
105
|
+
ruby_attributes[k.sub(/^rtal:/i,'')] = v
|
|
106
|
+
else
|
|
107
|
+
attributes[k] = v
|
|
108
|
+
end
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if ruby_attributes.empty?
|
|
112
|
+
tag = add_tag( elem.name, parse( elem ), attributes )
|
|
113
|
+
|
|
114
|
+
else
|
|
115
|
+
if bd = ruby_attributes["content"]
|
|
116
|
+
tag << "out << #{bd}.to_s"
|
|
117
|
+
elsif bd = ruby_attributes["replace"]
|
|
118
|
+
tag << "out << #{bd}.to_s"
|
|
119
|
+
mode = :replace
|
|
120
|
+
else
|
|
121
|
+
tag << parse( elem )
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
if cond = ( ruby_attributes["if"] || ruby_attributes["condition"] )
|
|
125
|
+
#mode = :replace
|
|
126
|
+
tag = ([ "if #{cond}" ].concat( tag ) << "end")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
if enum = ( ruby_attributes["each"] || ruby_attributes["repeat"] )
|
|
130
|
+
loopf = "#{enum}.each do"
|
|
131
|
+
if d = ruby_attributes["do"]
|
|
132
|
+
loopf << " |#{d}|"
|
|
133
|
+
end
|
|
134
|
+
tag = ([ loopf ].concat( tag ) << "end")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
unless mode == :replace #unless attributes.empty? #
|
|
138
|
+
tag = add_tag( elem.name, tag, attributes )
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
else
|
|
144
|
+
tag << "out << #{elem.to_s.inspect}"
|
|
8
145
|
|
|
9
|
-
|
|
146
|
+
end
|
|
10
147
|
|
|
148
|
+
body.concat tag
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
building << body.flatten.join("\n")
|
|
152
|
+
return building
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def self.add_tag( name, body, attributes={} )
|
|
156
|
+
b = []
|
|
157
|
+
if attributes.empty?
|
|
158
|
+
b << "out << '<#{name}>'"
|
|
159
|
+
b << body
|
|
160
|
+
b << "out << '</#{name}>'"
|
|
161
|
+
else
|
|
162
|
+
s = ''
|
|
163
|
+
s << "out << '<#{name} "
|
|
164
|
+
s << attributes.collect { |k,v| %{#{k}="#{v}"} }.join(' ')
|
|
165
|
+
s << ">'"
|
|
166
|
+
b << s
|
|
167
|
+
b << body
|
|
168
|
+
b << "out << '</#{name}>'"
|
|
169
|
+
end
|
|
170
|
+
b
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def self.loop_structure
|
|
11
174
|
|
|
12
175
|
end
|
|
13
176
|
|
|
14
177
|
end
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
=begin
|
|
183
|
+
|
|
184
|
+
s = %q{
|
|
185
|
+
<html>
|
|
186
|
+
<body>
|
|
187
|
+
<test>This is a test.</test>
|
|
188
|
+
<h1 rtal:content="x">[X]</h1>
|
|
189
|
+
<div rtal:each="animal" rtal:do="a">
|
|
190
|
+
<b rtal:content="a">[ANIMAL]</b>
|
|
191
|
+
</div>
|
|
192
|
+
<div rtal:if="animal.size >= 1">
|
|
193
|
+
<b rtal:body="animal.size">[ANIMAL SIZE]</b>
|
|
194
|
+
</div>
|
|
195
|
+
</body>
|
|
196
|
+
</html>
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
x = '10' # problem with numbers
|
|
200
|
+
animal = ['Zebra', 'Monkey', 'Tiger' ]
|
|
201
|
+
out = ''
|
|
202
|
+
|
|
203
|
+
prg = RubyTals.compile( s )
|
|
204
|
+
puts
|
|
205
|
+
puts prg
|
|
206
|
+
puts
|
|
207
|
+
puts eval(prg)
|
|
208
|
+
|
|
209
|
+
=end
|