o 2.0.1 → 2.0.2

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.
Files changed (6) hide show
  1. data/README.md +10 -7
  2. data/lib/o.rb +2 -2
  3. data/lib/o/parser.rb +0 -1
  4. data/lib/o/version.rb +1 -1
  5. metadata +2 -3
  6. data/lib/o1.rb +0 -189
data/README.md CHANGED
@@ -7,6 +7,8 @@ O, a configuration libraray for Ruby
7
7
  **Documentation**: [http://rubydoc.info/gems/o/frames](http://rubydoc.info/gems/o/frames) <br/>
8
8
  **Issue Tracker**: [https://github.com/GutenYe/o/issues](https://github.com/GutenYe/o/issues) <br/>
9
9
 
10
+ then name `o` comes from option/setting, short and handy, eh-ah~
11
+
10
12
  Features
11
13
  --------
12
14
 
@@ -22,11 +24,11 @@ do configuration at three levels: system, user, cmdline
22
24
 
23
25
  lib/guten/rc.rb # system level
24
26
  ~/.gutenrc # user level
25
- $ guten --list # cmdline level
27
+ $ guten --list or ENV[GEMFILE]=x guten # cmdline level
26
28
 
27
29
  module Guten
28
30
  Rc = O.require("guten/rc") + O.require("~/.gutenrc")
29
- Rc.list = true
31
+ Rc.list = true or Rc.gemfile = ENV[GEMFILE] # from cmdline.
30
32
  end
31
33
 
32
34
 
@@ -62,7 +64,7 @@ alternative syntax
62
64
  c.time = proc{|offset| Time.now}
63
65
  end
64
66
 
65
- a sugar syntax
67
+ a sugar syntax. _works in a file only_
66
68
 
67
69
  # file: guten/rc.rb
68
70
  development:
@@ -78,8 +80,9 @@ a sugar syntax
78
80
  username "guten"
79
81
  end
80
82
 
81
- **WARNNING**: must use \t to indent for this sugar syntax.
83
+ this is not pure ruby syntax, but it works.
82
84
 
85
+ **WARNNING**: must use \t to indent for this sugar syntax.
83
86
 
84
87
  ### initialize ###
85
88
 
@@ -136,9 +139,9 @@ either way is fine
136
139
  friend do
137
140
  age 3
138
141
  p age #=> 3
139
- p __.age #=> 2 relative
140
- p ___.age #=> 1
141
- p _.age #=> 1 root
142
+ p __.age #=> 2 __ is relative up to 1 times
143
+ p ___.age #=> 1 ___ and so on is relative up to 2 and so on times
144
+ p _.age #=> 1 _ is root
142
145
  end
143
146
  end
144
147
  end
data/lib/o.rb CHANGED
@@ -9,7 +9,7 @@ class O
9
9
  Error = Class.new Exception
10
10
  LoadError = Class.new Error
11
11
 
12
- BUILTIN_METHODS = [ :p, :pd, :raise, :sleep, :rand, :srand, :exit, :require, :at_exit, :autoload, :open]
12
+ BUILTIN_METHODS = [ :p, :raise, :sleep, :rand, :srand, :exit, :require, :at_exit, :autoload, :open]
13
13
 
14
14
  class << self
15
15
  public *BUILTIN_METHODS
@@ -189,7 +189,7 @@ class O
189
189
  # .a.b.c
190
190
  #
191
191
  def method_missing name, *args, &blk
192
- #O.pd 'missing', name, args, blk
192
+ #O.p d 'missing', name, args, blk
193
193
 
194
194
  # path: root
195
195
  if name == :_
@@ -51,7 +51,6 @@ class O
51
51
 
52
52
  content.scan(/(.*?)(\n+|\Z)/).each do |line, newline|
53
53
 
54
- #pd line.match(/^(\t*)(.*)/)
55
54
  _, indents, statement = line.match(/^(\t*)(.*)/).to_a
56
55
 
57
56
  # indent
@@ -2,7 +2,7 @@ class O
2
2
  module VERSION
3
3
  MAJOR = 2
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  IS = [MAJOR, MINOR, PATCH].join(".")
8
8
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: o
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.1
5
+ version: 2.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Guten
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-22 00:00:00 Z
13
+ date: 2011-07-26 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: |
@@ -36,7 +36,6 @@ files:
36
36
  - lib/o/parser.rb
37
37
  - lib/o/semantics.rb
38
38
  - lib/o/version.rb
39
- - lib/o1.rb
40
39
  - o.gemspec
41
40
  - o.watchr
42
41
  - spec/data/home/gutenrc
data/lib/o1.rb DELETED
@@ -1,189 +0,0 @@
1
- #
2
- # internal: store data in a Hash, the key of the Hash is always converted to symbol.
3
- #
4
- #
5
- #
6
- class O < Hash
7
- autoload :VERSION, "o/version"
8
-
9
- # PATH for O.load
10
- PATH = []
11
- Error = Exception.new
12
- LoadError = Exception.new(Error)
13
-
14
- class O_Eval
15
- def _data
16
- _data = {}
17
- self.instance_variables.each do |k|
18
- key = k[1..-1].to_sym
19
- value = self.instance_variable_get(k)
20
- _data[key] = value
21
- end
22
- _data
23
- end
24
- end
25
-
26
- class << self
27
- # convert <#Hash> to <#O>
28
- #
29
- # @param [hash] hash
30
- # @return O
31
- def from_hash hash
32
- o = O.new
33
- o._replace hash
34
- end
35
-
36
- # load a configuration file,
37
- # support PATH, and '~/.gutenrc'
38
- #
39
- # first try name.rb, then use name
40
- #
41
- # @example
42
- # option = O.load("~/.gutenrc")
43
- #
44
- # option = O.load("/absolute/path/a.rb")
45
- #
46
- # O::Path << "/home"
47
- # option = O.load("guten") #=> try guten.rb; then try guten
48
- # option = O.load("guten.rb")
49
- #
50
- # @param [String] name
51
- # @return [O]
52
- def load name
53
- path = nil
54
- if name =~ /^~/
55
- file = File.expand_path(name)
56
- path = file if File.exists?(file)
57
- elsif File.absolute_path(name) == name
58
- path = name if File.exists?(name)
59
- else
60
- catch :break do
61
- PATH.each do |p|
62
- ['.rb', ''].each {|ext|
63
- file = File.join(p, name+ext)
64
- if File.exists? file
65
- path = file
66
- throw :break
67
- end
68
- }
69
- end
70
- end
71
- end
72
-
73
- raise LoadError, "can't find file -- #{name}" unless path
74
-
75
- eval_file path
76
- end
77
-
78
- # relative load a configuration file
79
- # @see load
80
- #
81
- # @param [String] name
82
- # @return [O] option
83
- def relative_load name
84
- pd caller if $TEST
85
- a,file, line, method = caller[0].match(/^(.*):(\d+):.*`(.*)'$/).to_a
86
- raise LoadError, "#{type} is called in #{file}" if file=~/\(.*\)/ # eval, etc.
87
-
88
- file = File.readlink(file) if File.symlink?(file)
89
-
90
- path = nil
91
- [".rb", ""].each do |ext|
92
- f = File.absolute_path(File.join(File.dirname(file), name+ext))
93
- if File.exists?(f)
94
- path = f
95
- break
96
- end
97
- end
98
-
99
- raise LoadError, "can't find file -- #{name}" unless path
100
-
101
- eval_file path
102
- end
103
-
104
- private
105
- def eval_file path
106
- content = File.open(path){|f| f.read}
107
- o_eval = O_Eval.new
108
- o_eval.instance_eval(content)
109
- O.from_hash(o_eval._data)
110
- end
111
-
112
- end
113
-
114
- attr_reader :_data
115
-
116
- def initialize default=nil, &blk
117
- @_data = Hash.new(default)
118
- if blk
119
- o_eval = O_Eval.new
120
- o_eval.instance_eval &blk
121
- @_data.merge!(o_eval._data)
122
- end
123
- end
124
-
125
- def []= key, value
126
- @_data[key.to_sym] = value
127
- end
128
-
129
- def [] key
130
- @_data[key.to_sym]
131
- end
132
-
133
- def + other
134
- O.new(@_data, other._data)
135
- end
136
-
137
- def _replace data
138
- case data
139
- when Hash
140
- @_data = data
141
- when O
142
- @_data = data._data
143
- end
144
- self
145
- end
146
-
147
- #
148
- # _method goes to @_data.send(_method, ..)
149
- # method? #=> !! @_data[:method]
150
- # method #=> @_data[:method]
151
- # method=value #=> @_data[:method]=value
152
- #
153
- def method_missing method, *args, &blk
154
- if method =~ /(.*)=$/
155
- @_data[$1.to_sym] = args[0]
156
- elsif method =~ /(.*)\?$/
157
- !! @_data[$1.to_sym]
158
- elsif method =~ /^_(.*)/
159
- method = $1.to_sym
160
- args.map!{|arg| O===arg ? arg._data : arg}
161
- rst = @_data.send(method, *args, &blk)
162
-
163
- if [:merge!].include method
164
- self
165
- elsif [:merge].include method
166
- O.new(rst)
167
- end
168
- else
169
- @_data[method]
170
- end
171
- end
172
-
173
- def inspect
174
- rst = "<#O "
175
- @_data.each do |k,v|
176
- rst << "#{k}:#{v.inspect} "
177
- end
178
- rst << " >"
179
- end
180
-
181
- alias to_s inspect
182
-
183
- end
184
-
185
- module Kernel
186
- def O default=nil, &blk
187
- O.new(default, &blk)
188
- end
189
- end