├── .gitignore ├── .travis.yml ├── Gemfile ├── README.md ├── Rakefile ├── UNLICENSE ├── block-is-array.gemspec ├── examples └── nginx.rb ├── lib ├── block-is-array.rb └── block-is-array │ ├── class.rb │ └── function.rb └── tool └── run_readme.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | tmp 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: ruby 4 | 5 | addons: 6 | apt: 7 | packages: 8 | - nginx 9 | - rubygems 10 | 11 | script: 12 | - rake test 13 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # block-is-array 2 | 3 | [![Build Status](https://travis-ci.org/raviqqe/block-is-array.svg?branch=master)](https://travis-ci.org/raviqqe/block-is-array) 4 | [![License](https://img.shields.io/badge/license-unlicense-lightgray.svg)](https://unlicense.org) 5 | 6 | Block is Array 7 | 8 | ## Installation 9 | 10 | ``` 11 | $ gem install block-is-array 12 | ``` 13 | 14 | ## Usage 15 | 16 | Code: 17 | 18 | ```ruby 19 | require 'block-is-array' 20 | 21 | array = block_is_array do 22 | user :www 23 | 24 | http do 25 | server do 26 | listen 80 27 | server_name 'foo.com' 28 | end 29 | 30 | server do 31 | listen 443, :ssl 32 | server_name 'bar.com' 33 | end 34 | end 35 | end 36 | 37 | p array 38 | ``` 39 | 40 | Output: 41 | 42 | ```ruby 43 | [[:user, :www], [:http, [[:server, [[:listen, 80], [:server_name, "foo.com"]]], [:server, [[:listen, 443, :ssl], [:server_name, "bar.com"]]]]]] 44 | ``` 45 | 46 | For more examples, see [examples](examples) directory. 47 | 48 | ## License 49 | 50 | [The Unlicense](https://unlicense.org) 51 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake/clean' 2 | 3 | 4 | 5 | task :build do 6 | sh 'gem build *.gemspec' 7 | end 8 | 9 | task :push => :build do 10 | sh 'gem push *.gem' 11 | end 12 | 13 | task :install => :build do 14 | sh 'gem install *.gem' 15 | end 16 | 17 | task :test => :install do 18 | sh 'tool/run_readme.sh README.md' 19 | 20 | Dir.glob('examples/*.rb').each do |file| 21 | ruby file 22 | end 23 | end 24 | 25 | task :default => :build 26 | 27 | 28 | CLEAN.include Dir.glob ['*.gem'] 29 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /block-is-array.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'block-is-array' 3 | s.version = '0.0.2' 4 | s.date = Date.today.to_s 5 | s.license = 'Unlicense' 6 | 7 | s.summary = 'Block is Array' 8 | s.description = 'block-to-array converter' 9 | 10 | s.authors = ['Yota Toyama'] 11 | s.email = 'raviqqe@gmail.com' 12 | s.homepage = 'https://github.com/raviqqe/block-is-array' 13 | 14 | s.files = Dir['lib/**/*'] 15 | end 16 | -------------------------------------------------------------------------------- /examples/nginx.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'block-is-array' 4 | 5 | 6 | 7 | conf = block_is_array do 8 | user :nobody, :nogroup 9 | worker_processes 1 10 | events do 11 | worker_connections 1024 12 | end 13 | 14 | http do 15 | include 'mime.types' 16 | default_type 'application/octet-stream' 17 | 18 | sendfile :on 19 | keepalive_timeout 65 20 | 21 | server do 22 | listen 80 23 | server_name :localhost 24 | 25 | location '/' do 26 | root '/usr/local/www/nginx' 27 | index 'index.html', 'index.htm' 28 | end 29 | end 30 | 31 | server do 32 | listen 443, :ssl 33 | server_name :localhost 34 | 35 | ssl_certificate 'cert.pem' 36 | ssl_certificate_key 'key.pem' 37 | ssl_session_cache 'shared:SSL:1m' 38 | ssl_session_timeout '5m' 39 | 40 | location '/' do 41 | root 'html' 42 | index 'index.html', 'index.htm' 43 | end 44 | end 45 | end 46 | end 47 | 48 | p conf 49 | -------------------------------------------------------------------------------- /lib/block-is-array.rb: -------------------------------------------------------------------------------- 1 | require_relative 'block-is-array/function' 2 | -------------------------------------------------------------------------------- /lib/block-is-array/class.rb: -------------------------------------------------------------------------------- 1 | class BlockIsArray 2 | def initialize &block 3 | @array = [] 4 | instance_eval(&block) 5 | end 6 | 7 | def method_missing name, *args, &block 8 | if block 9 | args.push BlockIsArray.new(&block).to_array 10 | end 11 | 12 | @array.push args.unshift(name) 13 | end 14 | 15 | def to_array 16 | @array 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/block-is-array/function.rb: -------------------------------------------------------------------------------- 1 | require_relative 'class' 2 | 3 | 4 | 5 | def block_is_array &block 6 | BlockIsArray.new(&block).to_array 7 | end 8 | -------------------------------------------------------------------------------- /tool/run_readme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cat $1 | sed -z 's/.*```.*\(require[^`]*\)```.*/\1/' | ruby 4 | --------------------------------------------------------------------------------