boxomojo 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2622586e305e61e3f2406a11007d00c5d84ff119
4
+ data.tar.gz: 09efe846b0daf95108af25a7074a4f179c02fda5
5
+ SHA512:
6
+ metadata.gz: f9b38c8792987d4896cd788c01c268bd92dc0b84d0a5c4d103f242919e6db618a794ac4651b840bb34e545a95cb6ee89caa32c7d47b1288b72f73030cc414c56
7
+ data.tar.gz: d2ae66db78e3a0b9886f9aa4aaa4a9558dce237b1fb2f196fb5f7867561d765464afe3f2510d3a37934549e15aa6b11a0c38e9d1def3207ccb1a46c95480ab4e
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ node_modules/
19
+ bin/bower
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+
2
+ Copyright (c) 2015 da99
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+
2
+ Boxomojo
3
+ ----------
4
+
5
+ I use this to help make internal DSLs.
6
+
7
+ It took me 10+ years to get to this point.
8
+ I'm too tired to write anymore.
9
+
10
+
11
+ ```ruby
12
+ box_class = Boxomojo.new(:val, :collect=>[:names,:places])
13
+
14
+ box_class.new {
15
+ val 5
16
+ names :happy
17
+ names :sad
18
+ places :glasgow
19
+ places :oxford
20
+ }
21
+
22
+ require "awesome_print"
23
+ ap box.kv, :indent=>-2
24
+ ap box.stack, :indent=>-2
25
+ ap box.meta, :indent=>-2
26
+ ```
27
+
28
+
29
+ Ending Credits:
30
+ --------------
31
+
32
+ This was originally done for nodejs: [v0.1.0](https://github.com/da99/boxomojo/tree/v0.1.0)
33
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env bash
2
+ # -*- bash -*-
3
+ #
4
+ #
5
+ if [[ -z "$1" ]]; then
6
+ action="watch"
7
+ else
8
+ action="$1"
9
+ shift
10
+ fi
11
+
12
+ set -u -e -o pipefail
13
+
14
+
15
+ case "$action" in
16
+
17
+ "help")
18
+ echo " ====================================================="
19
+ echo ""
20
+ echo " $ boxomojo watch"
21
+ echo ""
22
+ echo " $ boxomojo test"
23
+ echo " $ boxomojo test name"
24
+ echo ""
25
+ echo " ====================================================="
26
+ echo ""
27
+ exit 0
28
+ ;; # === start
29
+
30
+ "watch")
31
+ echo "=== Watching: "
32
+ bin/boxomojo test "$@" || true
33
+
34
+ inotifywait -q --exclude .git/ -e close_write,close -m -r . | while read CHANGE
35
+ do
36
+ dir=$(echo "$CHANGE" | cut -d' ' -f 1)
37
+ op=$(echo "$CHANGE" | cut -d' ' -f 2)
38
+ file=$(echo "$CHANGE" | cut -d' ' -f 3)
39
+ path="${dir}$file"
40
+
41
+ if [[ ( ! "$op" =~ "NOWRITE" ) && ( "$op" =~ "CLOSE" || "$op" =~ "WRITE" ) && ! -z "$file" ]]
42
+ then
43
+ echo ""
44
+ if [[ "$file" == *.js* ]]; then
45
+ echo ""
46
+ echo "=== Runninig jshint on $path: $CHANGE"
47
+ (jshint "$path" && echo "No errors.") || true
48
+ fi
49
+
50
+ if [[ "$path" == *bin/boxomojo* ]]; then
51
+ echo ""
52
+ echo "=== Restarting:"
53
+ exec $path "watch" "$@"
54
+ fi
55
+
56
+ if [[ "$path" == *.rb* ]]; then
57
+ echo "=== Running tests: $@"
58
+ bin/boxomojo test "$@" || true
59
+ fi
60
+ fi # === if file op
61
+
62
+ done
63
+
64
+ ;; # === watch
65
+
66
+ "test")
67
+ files=""
68
+ if [[ ! -z "$@" ]]; then
69
+ files="$(echo -n specs/*-$1.rb)"
70
+ if [[ -f "$files" ]]; then
71
+ shift
72
+ else
73
+ files=""
74
+ fi
75
+ fi
76
+
77
+ if [[ -z "$files" ]]; then
78
+ files="$(echo -n specs/*.rb | tr ' ' '\n' | sort)"
79
+ fi
80
+
81
+ if [[ -z "$files" ]]; then
82
+ colorize yellow "No tests found." 1>&2
83
+ exit 0
84
+ else
85
+ bundle exec bacon specs/lib/helpers.rb $files "$@"
86
+ fi
87
+ ;; # === test
88
+
89
+ *)
90
+ echo "=== Unknown action: $action" 1>&2
91
+ exit 1
92
+ ;;
93
+
94
+ esac
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "boxomojo"
7
+ spec.version = `cat VERSION`
8
+ spec.authors = ["da99"]
9
+ spec.email = ["i-hate-spam-1234567@mailinator.com"]
10
+ spec.summary = %q{My own way of creating internal DSLs.}
11
+ spec.description = %q{
12
+ An internal DSL for creating/managing Hashes and Arrays.
13
+ You will not use it since it only suits me tastes.
14
+ }
15
+ spec.homepage = "https://github.com/da99/boxomojo"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |file|
19
+ file.index('bin/') == 0 && file != "bin/#{File.basename Dir.pwd}"
20
+ }
21
+ spec.executables = spec.files.grep("bin/#{spec.name}") { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.required_ruby_version = '>= 2.2.0'
26
+
27
+ spec.add_development_dependency "pry" , "> 0.9"
28
+ spec.add_development_dependency "bundler" , "> 1.5"
29
+ spec.add_development_dependency "bacon" , "> 1.0"
30
+ spec.add_development_dependency "Bacon_Colored" , "> 0.1"
31
+ spec.add_development_dependency "awesome_print" , "> 0.1"
32
+ end
@@ -0,0 +1,116 @@
1
+
2
+ class Boxomojo
3
+
4
+ module Mod
5
+
6
+ attr_reader :stack, :meta, :kv
7
+
8
+ def initialize name=nil, *args
9
+ @stack = []
10
+ @kv = {}
11
+ @meta = {:name=>name, :args=>args}
12
+ run(&Proc.new) if block_given?
13
+ end
14
+
15
+ def name
16
+ @meta[:name]
17
+ end
18
+
19
+ def args
20
+ @meta[:args]
21
+ end
22
+
23
+ def push *args
24
+ stack.concat args
25
+ end
26
+
27
+ def new_box name, *args
28
+ box = self.class.new(name, *args)
29
+ if block_given?
30
+ box.run(&(Proc.new))
31
+ end
32
+ @stack.<<( box )
33
+ end
34
+
35
+ def update key, arr
36
+ if arr.size == 1 || arr.empty?
37
+ @kv[key] = arr.first
38
+ else
39
+ @kv[key] = arr
40
+ end
41
+ arr
42
+ end
43
+
44
+ def collect key, arr
45
+ if !@kv.has_key?(key)
46
+ @kv[key] = []
47
+ end
48
+
49
+ @kv[key].concat arr
50
+ arr
51
+ end
52
+
53
+ def run &blok
54
+ instance_eval &blok
55
+ self
56
+ end
57
+
58
+ end # === module Mod
59
+
60
+ class << self
61
+ def new *names
62
+ kv = if names.last.is_a?(Hash)
63
+ h = names.pop
64
+ h[:names] = names
65
+ h
66
+ else
67
+ {:names=>names}
68
+ end
69
+
70
+ c = Class.new {
71
+ include Boxomojo::Mod
72
+ kv.each { |k, sym_or_arr|
73
+ arr = [sym_or_arr].flatten
74
+
75
+ case k
76
+ when :names
77
+ arr.each { |name|
78
+ eval <<-EOF, nil, __FILE__, __LINE__+1
79
+ def #{name} *args
80
+ if block_given?
81
+ new_box :#{name}, *args, &(Proc.new)
82
+ else
83
+ update :#{name}, args
84
+ end # === if
85
+ end
86
+ EOF
87
+ }
88
+
89
+ when :block
90
+ arr.each { |name|
91
+ eval <<-EOF, nil, __FILE__, __LINE__ + 1
92
+ def #{name} *args, &blok
93
+ new_box :#{name}, *args, blok
94
+ end
95
+ EOF
96
+ }
97
+
98
+ when :collect
99
+ arr.each { |name|
100
+ eval <<-EOF, nil, __FILE__, __LINE__+1
101
+ def #{name} *args
102
+ collect :#{name}, args
103
+ end
104
+ EOF
105
+ }
106
+
107
+ else
108
+ fail ArgumentError, "Unknow type: #{k.inspect}"
109
+
110
+ end # === case k
111
+ }
112
+ }
113
+ end
114
+ end # === class self ===
115
+
116
+ end # === class Boxomojo ===
@@ -0,0 +1,47 @@
1
+
2
+ describe "boxomojo" do
3
+
4
+ it "runs code from README.md" do
5
+ file = File.expand_path(File.dirname(__FILE__) + '/../README.md')
6
+ contents = File.read( file )
7
+ code = (contents[/```ruby([^`]+)```/] && $1).
8
+ split("\n").
9
+ reject { |l| l['ap '] }.
10
+ join("\n")
11
+
12
+ should.not.raise {
13
+ eval(code, nil, file, contents.split("\n").index('```ruby') + 1)
14
+ }
15
+ end # === it
16
+
17
+ it "runs" do
18
+ results = Boxomojo.new(:p).new {
19
+ p {
20
+ push "This is text."
21
+ p {
22
+ push "This is another paragraph."
23
+ }
24
+ }
25
+ }
26
+
27
+ stack(results).should == [
28
+ [
29
+ "This is text.",
30
+ ["This is another paragraph."]
31
+ ]
32
+ ]
33
+ end # === it
34
+
35
+ it "saves methods calls w/o blocks as meta kv" do
36
+ results = Boxomojo.new(:css, :style).new {
37
+ css 'happy'
38
+ style 'red'
39
+ }
40
+
41
+ kv(results).should == {
42
+ :css => 'happy',
43
+ :style => 'red'
44
+ }
45
+ end # === it
46
+
47
+ end # === describe "boxomojo"
@@ -0,0 +1,14 @@
1
+
2
+
3
+ describe ":block" do
4
+
5
+ it "does not evaluate the block" do
6
+ results = Boxomojo.new(:val, :block=>:change_to).new {
7
+ val 5
8
+ change_to { :a }
9
+ }
10
+
11
+ results.stack.last.args.last.class.should == Proc
12
+ end # === it
13
+
14
+ end # === describe ":block"
@@ -0,0 +1,16 @@
1
+
2
+ describe ":collect" do
3
+
4
+ it "collects value rather than updates value" do
5
+ results = Boxomojo.new(:val, :collect=>[:names,:places]).new {
6
+ val 5
7
+ names :happy
8
+ names :sad
9
+ places :glasgow
10
+ places :oxford
11
+ }
12
+
13
+ results.kv.should == {:val=>5, :names=>[:happy,:sad], :places=>[:glasgow, :oxford]}
14
+ end # === it
15
+
16
+ end # === describe ":collect"
@@ -0,0 +1,25 @@
1
+
2
+ require 'Bacon_Colored'
3
+ require 'boxomojo'
4
+ require 'pry'
5
+ require 'awesome_print'
6
+
7
+ def awesome *args
8
+ args.each { |v|
9
+ ap v, :indent=>-2
10
+ }
11
+ end
12
+
13
+ def stack box
14
+ box.stack.map { |b|
15
+ if b.is_a?(Boxomojo::Mod)
16
+ stack(b)
17
+ else
18
+ b
19
+ end
20
+ }
21
+ end
22
+
23
+ def kv box
24
+ box.kv
25
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boxomojo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - da99
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bacon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: Bacon_Colored
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ description: "\n An internal DSL for creating/managing Hashes and Arrays.\n You
84
+ will not use it since it only suits me tastes.\n "
85
+ email:
86
+ - i-hate-spam-1234567@mailinator.com
87
+ executables:
88
+ - boxomojo
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - VERSION
97
+ - bin/boxomojo
98
+ - boxomojo.gemspec
99
+ - lib/boxomojo.rb
100
+ - specs/0000-boxomojo.rb
101
+ - specs/0010-block.rb
102
+ - specs/0010-collect.rb
103
+ - specs/lib/helpers.rb
104
+ homepage: https://github.com/da99/boxomojo
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.2.0
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: My own way of creating internal DSLs.
128
+ test_files: []