sereth_json_spec 1.0beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ # Sereth Libraries
2
+ require_relative 'sereth_utils/all'
3
+
4
+ # JSON Spec
5
+ require_relative 'sereth_json_spec/utils'
6
+ require_relative 'sereth_json_spec/generator'
7
+ require_relative 'sereth_json_spec/cache'
8
+ require_relative 'sereth_json_spec/exports'
9
+ require_relative 'sereth_json_spec/imports'
10
+ require_relative 'sereth_json_spec/data'
11
+ require_relative 'sereth_json_spec/api'
12
+
13
+ # TODO - Run any necessary stages
14
+ # Binding.run_stage(:sereth_util_loaded)
@@ -0,0 +1,40 @@
1
+ =begin
2
+ # Usage:
3
+
4
+ class Thing
5
+ def method_name(*args)
6
+ args
7
+ end
8
+ alias_shift_arg(:method_changed, :method_name, 1, 2, 3)
9
+ end
10
+
11
+
12
+ thing = Thing.new
13
+ thing.method_name("a").inspect #=> ["a"]
14
+ thing.method_changed("a").inspect #=> [1, 2, 3, "a"]
15
+ =end
16
+
17
+ module Sereth
18
+ module AliasArgs
19
+ # Register an alias before the method is defined. Not for performance critical use
20
+ def alias_preload(target, source)
21
+ self.send(:define_method, target) do |*orig_args, &block|
22
+ self.send(source, *orig_args, &block)
23
+ end
24
+ end
25
+
26
+ # Register a method that appends some arguments before calling the aliased method
27
+ def alias_push_args(target, source, *args)
28
+ self.send(:define_method, target) do |*orig_args, &block|
29
+ self.send(source, *(orig_args + args), &block)
30
+ end
31
+ end
32
+
33
+ # Register a method that prepends some arguments before calling the aliased method
34
+ def alias_shift_args(target, source, *args)
35
+ self.send(:define_method, target) do |*orig_args, &block|
36
+ self.send(source, *(args + orig_args), &block)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ # Ensure the sereth namespace exists
2
+ module Sereth; end
3
+
4
+ raise LoadError, 'Ruquires Ruby 2' if !RUBY_VERSION.match(/^2/)
5
+ require 'rubygems'
6
+ require 'pry'
7
+ require 'andand'
8
+ require 'binding_of_caller'
9
+
10
+ # Use staging for all following code.
11
+ require_relative './stage'
12
+ require_relative './alias_args'
13
+ require_relative './callbacks'
14
+
15
+ Binding.run_stage(:sereth_util_loaded)
@@ -0,0 +1,31 @@
1
+ =begin
2
+ # Callback System
3
+ Implements around callbacks for any requested function.
4
+
5
+ ## Usage:
6
+ class Example
7
+ include Sereth::Callback
8
+
9
+ around_method :method_name do |*args, &block|
10
+ print 'ar1'
11
+ super(*args, &block)
12
+ print 'ar2'
13
+ end
14
+
15
+ def method_name(*args, &block)
16
+ print 'method'
17
+ end
18
+ end
19
+
20
+ Example.new.method_name => ar1 method ar2
21
+ =end
22
+ module Sereth
23
+ # Enables around callbacks for a given object. Ruby 1.9 only.
24
+ module Callbacks
25
+ def around_method(func_name, &callback)
26
+ handler = Module.new
27
+ handler.send :define_method, func_name, &callback
28
+ self.send(:prepend, handler)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,141 @@
1
+ =begin
2
+ # Configuration Module
3
+ The configuration module allows tools to register configuraiton parameters, and then query
4
+ them as necessay. It also acts as a config file generator, loader, and validator, as well as
5
+ an argument parser.
6
+
7
+ ## Parameter Sources
8
+ Parameters are sourced from (in order of importance):
9
+
10
+ 1. In-code Configuration
11
+ 2. Command Line Configuration
12
+ 3. File Configuration
13
+ 4. Default Configuration
14
+
15
+ ## Storage
16
+ All configuration options are stored at a fully formed path "/path/is/here" with a proper
17
+ symbol :name.
18
+
19
+ ## Command line configuration
20
+ Command line aguments must specify the argument name, and may also specify any of the
21
+ preceding path. The system will to its best to find an argument that matches that name,
22
+ but will fail if a single match can not be determined
23
+
24
+ Given:
25
+ config.add_arg('/path/1', :name)
26
+ config.add_arg('/path/2', :name)
27
+
28
+ ruby script.rb -name=on #=> [/path/1/name => on, /path/2/name => nil]
29
+ ruby script.rb -1_name=on #=> [/path/1/name => on, /path/2/name => nil]
30
+ ruby script.rb -2_name=on #=> [/path/1/name => nil, /path/2/name => on]
31
+ ruby script.rb -path_2_name=on #=> [/path/1/name => nil, /path/2/name => on]
32
+
33
+ TODO: Fully formed Flow path
34
+
35
+ ## Usage
36
+ The configuration module is best combined with binding stages in order to ensure that
37
+ the execution has proper access to the local context, and all values defined therein.
38
+
39
+ Valid Types: Boolean (Default) | Integer | String
40
+
41
+ class Data
42
+ binding.stage :after_parse do
43
+ extend Sereth::Config
44
+
45
+ args_config :category, "path"... do
46
+ command :name do
47
+
48
+ end
49
+
50
+ bool :name_b, "desc"[, default_value]
51
+ int :name_i, "desc"[, default_value]
52
+ string :name_s, "desc"[, default_value]
53
+ exec :name_e, "desc" &block
54
+
55
+ config :deeper_category do
56
+ bool :name_x
57
+
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ Sereth::Stage.run_stage :after_parse
64
+
65
+ Sereth::Config.value(:category, :path, :name_b) #=> Bool Value/Default/nil
66
+ cont = Sereth::Config.container(:category, :path, :deeper_category)
67
+ con
68
+
69
+ ## Argument Styles
70
+ Static arguments: Basic type of argument, optionally assigned a default value. These
71
+ arguments are automatically parsed when they are defined, and may be re-parsed later
72
+ for updates.
73
+ Dynamic arguments: These arguments are generated automatically once they are accessed,
74
+ or when the configdb is notified to parse the data.
75
+
76
+ =end
77
+ module Sereth
78
+ class ConfigDB
79
+ # Register the config paramters
80
+ binding.stage :sereth_util_loaded do
81
+ extend Config
82
+ end
83
+
84
+ @full_names = {}
85
+ @data = {}
86
+
87
+ class << self
88
+ def parse_file
89
+
90
+ end
91
+
92
+ def parse_args
93
+
94
+ end
95
+
96
+ def gen_path(path)
97
+
98
+ end
99
+
100
+ def get_path(path)
101
+ path = path.split('/').map(&:to_sym)
102
+ @data.get(*path)
103
+
104
+ end
105
+
106
+ def parse
107
+
108
+ end
109
+ end
110
+
111
+ def initialize
112
+
113
+ end
114
+
115
+ def add(name, type)
116
+
117
+ end
118
+
119
+ def set(name, value)
120
+
121
+ end
122
+ end
123
+
124
+ module Config
125
+ # This module is only for extension
126
+ def self.included(target)
127
+ raise "The #{self} Module should only be extended, not included."
128
+ end
129
+
130
+ # Add the callback method added to the method_added stack
131
+ def self.extended(target)
132
+ # Stack the method_added callback
133
+ raise "Cannot exted system_config" if target.method_defined?(:system_config)
134
+ end
135
+
136
+ def args_config(*path, &block)
137
+ path = path.map(&:to_sym)
138
+ ConfigDB
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,140 @@
1
+ # Tree logging
2
+ # Multiple perspectives/buffers for threads and others
3
+
4
+ # Modify depth for any
5
+ module Sereth
6
+ module DevLogBinding
7
+ def var_in_parent(var_name)
8
+ begin
9
+ i = 0
10
+ while i += 1
11
+ ret = binding.of_caller(i).eval("#{var_name} if defined? #{var_name}")
12
+ return ret if !ret.nil?
13
+ end
14
+ rescue
15
+ return nil
16
+ end
17
+ end
18
+
19
+ def dev_sectionize(func, tag)
20
+ # Get the closest parent binding with a
21
+ end
22
+ end
23
+
24
+ module DevLogKernel
25
+ include Callbacks
26
+
27
+ def dev_sectionize(func, tag)
28
+ # Get the closest parent binding with a
29
+ self.define_method :func do |*args, &block|
30
+ Sereth::DevLog.section(tag)
31
+ begin
32
+ super(*args, &block)
33
+ ensure
34
+ Sereth::DevLog.pop
35
+ end
36
+ end
37
+ end
38
+
39
+ #
40
+ def putd(*args)
41
+ return if !Sereth::DevLog.active?
42
+
43
+ Sereth::DevLog.write(depth, *args)
44
+ end
45
+
46
+ def putds(*args)
47
+ if Sereth::DevLog.active?
48
+ putd(*args)
49
+ else
50
+ puts(*args)
51
+ end
52
+ end
53
+ end
54
+
55
+ class DevLogBuffers
56
+ # Random name with a low probability of intersection
57
+ @default_buffer = nil
58
+ @buffers = {}
59
+
60
+ class << self
61
+ def default_buffer
62
+ @default_buffer ||= LoggerBuffers.new
63
+ @default_buffer
64
+ end
65
+
66
+ def get_buffer(id = nil)
67
+ return default_buffer if id.nil?
68
+ @buffers[id] ||= LoggerBuffers.new
69
+ @buffers[id]
70
+ end
71
+ end
72
+
73
+ attr_accessor :mirror
74
+ def initialzie(spacer = " ")
75
+ @io = StringIO.new
76
+ @depth = 0
77
+ @spacer = spacer
78
+ @mirror = nil
79
+ end
80
+
81
+ def write(string)
82
+ # Generate the spacer to use for this write
83
+ cur_spacer = ""
84
+ @depth.times{cur_spacer << @spacer}
85
+ # Log the message to the boud IO, and optionally mirror the output elsewhere
86
+ string.split("\n").each do |str|
87
+ to_write = "#{cur_spacer}#{str}"
88
+ @io.write(to_write)
89
+ @mirror.write(to_write) if @mirror
90
+ end
91
+ end
92
+
93
+ # Forward everything else to string IO
94
+ def respond_to_missing?(name, include_private = false)
95
+ @io.respond_to?(name, include_private)
96
+ end
97
+
98
+ # Forward everything else to string IO
99
+ def method_missing(name, *args, &block)
100
+ @io.send(name, *args, &block)
101
+ end
102
+ end
103
+
104
+ class DevLog
105
+ @buffer_table = {}
106
+ @active = false
107
+ class << self
108
+ def active?
109
+ @active
110
+ end
111
+
112
+ def activate
113
+ @active = true
114
+ end
115
+
116
+ def root
117
+
118
+ end
119
+ end
120
+
121
+ def initialize(section, depth = 0, buffer = nil)
122
+ @buffer = buffer
123
+ @section = section
124
+ @depth = depth
125
+ end
126
+
127
+ def spawn(section)
128
+ self.class.new(section, @depth += 1, @buffer)
129
+ end
130
+
131
+ end
132
+ end
133
+
134
+ class Binding
135
+ include Sereth::DevLogBinding
136
+ end
137
+
138
+ module Kernel
139
+ include Sereth::DevLogKernel
140
+ end
@@ -0,0 +1,70 @@
1
+ =begin
2
+ TODO - When adding a regex to lexxer, insert it into the global state
3
+ machine. This state machine can match multiple objects based on context.
4
+
5
+ Result is based on selection priority
6
+ =end
7
+
8
+ module Sereth
9
+
10
+ class Parser
11
+ class << self
12
+ def inherited
13
+ # Log Stuff
14
+ end
15
+
16
+
17
+ end
18
+
19
+ def initialize(raw)
20
+ @raw = raw
21
+ @raw_pos = 0
22
+ end
23
+
24
+ def add_query
25
+ next_matcher = nil
26
+ to_match = /\G#{next_matcher}/
27
+ end
28
+
29
+ def query
30
+ res = @raw.match(next_query, @raw_pos)
31
+ raise 'Parse Error' if !res
32
+ match = res[0]
33
+ @raw_pos += match.size
34
+ match
35
+ end
36
+ end
37
+
38
+ class JSONParser < Parser
39
+ _config do
40
+ ignore_whitespace true
41
+ end
42
+
43
+
44
+ # Global Value
45
+ value! _any(number, string, array, object, literals)
46
+
47
+ # Basic value types
48
+ literals! %w{false null true}
49
+
50
+ number! do
51
+ opt '-'
52
+ raw(:integers, %r{^(0|[1-9]\d+)})
53
+ opt raw(:frac, '.', /\d+/)
54
+ opt raw(:exp, /e|E/, /\d+/)
55
+ handle
56
+ end
57
+
58
+ string! '"', string_value, '"' do
59
+ string_value! _until(%r{(.*[^\\](\\\\)*|(\\\\)*)?(?=")})
60
+ end
61
+
62
+ # Recursive Definitions
63
+ values! _opt(value, _opt(',', values))
64
+ members! _opt(string, ':', value, _opt(',', members))
65
+
66
+ # Containers
67
+ array! '[', values, ']'
68
+ object! '{', members, '}'
69
+ end
70
+ end
@@ -0,0 +1,80 @@
1
+ =begin
2
+ # Staging Module
3
+ Allows for the configuration of execution stages, and provides code to be executed in
4
+ that stage. Node, code is executed in the current context.
5
+
6
+ This is particularly useful for tasks that need to be performed at specific spots in
7
+ the loading process. May also be useful for cleanup code.
8
+
9
+ ## Usage
10
+ binding.stage :name do
11
+ ... code ...
12
+ end
13
+
14
+ # Example
15
+ $result = []
16
+ class Ex
17
+ val = 1
18
+ $result.push(val)
19
+ binding.stage(:after) {$result.push(val)}
20
+ val = 2
21
+ end
22
+
23
+ Sereth::Stage.run_stage :after
24
+
25
+ $result == [1, 2]
26
+ =end
27
+ require 'sourcify'
28
+
29
+ module Sereth
30
+ module StageBindingExtender
31
+ def run_stage(name)
32
+ Sereth::Stage.run_stage(:sereth_util_loaded)
33
+ end
34
+ end
35
+
36
+ module StageBinding
37
+ # Convert the requested block to source code
38
+ def stage(name, &block)
39
+ Sereth::Stage.add_stage(name, self, block.to_source(:strip_enclosure => true))
40
+ end
41
+
42
+ # Extend target with the proper singleton methods
43
+ def self.included(target)
44
+ target.send(:extend, StageBindingExtender)
45
+ end
46
+ end
47
+
48
+ class Stage
49
+ @db = {}
50
+ class << self
51
+ def add_stage(name, target_binding, code)
52
+ @db[name] ||= Stage.new(name)
53
+ @db[name].add(target_binding, code)
54
+ end
55
+
56
+ def run_stage(name)
57
+ return if !@db.has_key?(name)
58
+ @db.delete(name).run
59
+ end
60
+ end
61
+
62
+ def initialize(name)
63
+ @name = name
64
+ @targets = []
65
+ end
66
+
67
+ def add(target_binding, code)
68
+ @targets.push([target_binding, code])
69
+ end
70
+
71
+ def run
72
+ @targets.each {|target_binding, code| target_binding.eval(code)}
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ class Binding
79
+ include Sereth::StageBinding
80
+ end
@@ -0,0 +1,27 @@
1
+ module Sereth
2
+ module SymbolCallbackIncludes
3
+ # Generate a proc object to be evaluated in a context
4
+ def caller
5
+ return proc {|*input| self.send(*(input + args))}
6
+ end
7
+
8
+ # Generate a proc object to be evaluated in a context with arg appended
9
+ def caller_push(*args)
10
+ return proc {|*input| self.send(*(input + args))}
11
+ end
12
+
13
+ # Generate a proc object to be evaluated in a context with arg prepended
14
+ def caller_shift(*args)
15
+ return proc do |*input|
16
+ return proc {|*input| self.send(*(args + input))}
17
+ end
18
+ end
19
+ end
20
+
21
+ class SymbolCallback
22
+ end
23
+ end
24
+
25
+ class Symbol
26
+ include Sereth::SymbolCallbackIncludes
27
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sereth_json_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0beta1
5
+ platform: ruby
6
+ authors:
7
+ - Tikhon Botchkarev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: andand
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: binding_of_caller
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sourcify
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A gem to generate JSON schema and output from object instances
84
+ email: TikiTDO@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/seek_test.rb
90
+ - lib/sereth_json_spec.rb
91
+ - lib/sereth_json_spec/api.rb
92
+ - lib/sereth_json_spec/cache.rb
93
+ - lib/sereth_json_spec/data.rb
94
+ - lib/sereth_json_spec/exports.rb
95
+ - lib/sereth_json_spec/generator.rb
96
+ - lib/sereth_json_spec/imports.rb
97
+ - lib/sereth_json_spec/lib_config.rb
98
+ - lib/sereth_json_spec/utils.rb
99
+ - lib/sereth_utils/alias_args.rb
100
+ - lib/sereth_utils/all.rb
101
+ - lib/sereth_utils/callbacks.rb
102
+ - lib/sereth_utils/config.rb
103
+ - lib/sereth_utils/dev_log.rb
104
+ - lib/sereth_utils/parser.rb
105
+ - lib/sereth_utils/stage.rb
106
+ - lib/sereth_utils/symbol_callback.rb
107
+ homepage: https://github.com/TikiTDO/sereth_json_spec
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: 2.0.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>'
123
+ - !ruby/object:Gem::Version
124
+ version: 1.3.1
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.0.0
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Sereth JSON Specification gem
131
+ test_files: []