Class: Object

Inherits:
BasicObject
Defined in:
lib/yaml/transform.rb,
lib/r_path.rb,
lib/auto_object.rb,
lib/blank_slate.rb,
lib/sym_tbl_gsub.rb,
lib/verbose_object.rb,
lib/commands/helpers.rb

Overview

FIXME: Implement all ruby types.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blank_slate_ignore(name) ⇒ Object



68
69
70
# File 'lib/blank_slate.rb', line 68

def self.blank_slate_ignore ( name )
  name =~ /^(__|blank_slate\?$)/
end

Instance Method Details

#auto_object?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/auto_object.rb', line 53

def auto_object?
  false
end

#blank_slate?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/blank_slate.rb', line 72

def blank_slate?
  false
end

#do_symtbl_gsub(symtbl) ⇒ Object



14
15
16
17
# File 'lib/sym_tbl_gsub.rb', line 14

def do_symtbl_gsub ( symtbl )
  result = symtbl_gsub(symtbl)
  return (result.nil?)? self : result
end

#regex_path_match(re, trees, args, &block) ⇒ Object

:nodoc:



100
101
102
# File 'lib/r_path.rb', line 100

def regex_path_match ( re, trees, args, &block ) # :nodoc:
  to_s.regex_path_match(re, trees, args, &block)
end

#rpath(re, &block) ⇒ Object

RPath is a sort of the well known XPath. XPath is XML and RPath is obviously built for Ruby.

When you have a Ruby tree – by tree I mean a complex data structure with no cycles – you can search something into it:

tree = {

:A => {
  :AA  => { :AAA => 'foo' },
  'AB' => [ :AB1, 2, 'a b 3' ],
},
:B => {
  'foo' => { :home => 'here',       :email => '[email protected]' },
  'bar' => { :home => "bar's home", :email => '[email protected]' },
  'baz' => { :home => 'nowhere',    :email => '[email protected]' }
}

}

tree.rpath(‘/A/AA/AAA/’) { |x| p x } # => ‘foo’

But we are dealing with regexp so if you want just this path you need: tree.rpath(‘/^A$/^AA$/^AAA$/’) { |x| p x } # => ‘foo’

But if you are lazy you can type that: tree.rpath(‘/A/AA//’) { |x| p x } # => ‘foo’ or tree.rpath(‘///AAA/’) { |x| p x } # => ‘foo’

tree.rpath(‘/B//home/nowhere’) { |x| p x } # => ‘nowhere’

But you would prefer get the complete baz record, so to do that you can mark your dezired levels with ‘*’.

tree.rpath(‘/B//*home/nowhere’) { |x| p x } # => ‘[email protected]

tree.rpath(‘/B//*home/ere’) { |x| p x }

> ‘[email protected]

> ‘[email protected]

tree.rpath(‘/B//*home/(.*)’) { |tree, home| p [home, tree] }

> [ ‘here’, ‘[email protected]’ ]

> [ “bar’s home”, ‘[email protected]’ ]

> [ ‘nowhere’, ‘[email protected]’ ]

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/r_path.rb', line 55

def rpath ( re, &block )
  raise ArgumentError, 'no block given' unless block_given?
  re = RegexPath.new(re) unless re.is_a? RegexPath
  regex_path_match(re, nil, [], &block)
  nil
end

#rpath_find(mode, re) ⇒ Object

mode = [:first, :all] rpath_find :all is like rpath_select rpath_find :first is the first element of rpath_select



91
92
93
94
95
96
97
98
# File 'lib/r_path.rb', line 91

def rpath_find ( mode, re )
  results = rpath_select(re)
  case mode
  when :all   then results
  when :first then results.first
  else raise "Bad mode `#{mode}' for rpath_find"
  end
end

#rpath_select(re) ⇒ Object

Act like rpath it does not take a block but



65
66
67
68
69
70
71
72
# File 'lib/r_path.rb', line 65

def rpath_select ( re )
  results = []
  re = RegexPath.new(re) unless re.is_a? RegexPath
  regex_path_match(re, nil, []) do |x|
    results << x
  end
  results
end

#rpath_select_match_data(re) ⇒ Object

Like rpath_select with match datas



77
78
79
80
81
82
83
84
# File 'lib/r_path.rb', line 77

def rpath_select_match_data ( re )
  results = []
  re = RegexPath.new(re) unless re.is_a? RegexPath
  regex_path_match(re, nil, []) do |*a|
    results << a
  end
  results
end

#symtbl_gsub(symtbl) ⇒ Object



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

def symtbl_gsub ( symtbl )
  nil
end

#symtbl_to_sObject



19
20
21
# File 'lib/sym_tbl_gsub.rb', line 19

def symtbl_to_s
  to_s
end

#to_io_for_commandsObject



14
15
16
# File 'lib/commands/helpers.rb', line 14

def to_io_for_commands
  to_io
end

#verbose_object?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/verbose_object.rb', line 108

def verbose_object?
  false
end

#verbosify(opts = nil) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/verbose_object.rb', line 112

def verbosify ( opts=nil )
  begin
    verbosify!(opts)
  rescue TypeError => ex
    VerboseObject.new(self, opts)
  end
end

#verbosify!(opts = nil) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/verbose_object.rb', line 120

def verbosify! ( opts=nil )
  unless blank_slate?
    class << self
      def self.blank_slate_ignore ( name )
        VerboseObject.blank_slate_ignore(name)
      end
    end
    extend BlankSlate unless blank_slate?
  end
  __blank_slate_extend Verbosify unless verbose_object?
  self.verbose_object_options = opts
  self
rescue TypeError => ex
  raise TypeError, "can't make a verbose object from #{self} (#{ex})"
end

#yaml_doc_traverse(activated) ⇒ Object

:nodoc:

Raises:

  • (ArgumentError)


27
28
29
# File 'lib/yaml/transform.rb', line 27

def yaml_doc_traverse ( activated )
  raise ArgumentError, "can't traverse class #{self.class}"
end