to_php_array 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79f63c1f67f97468df1aa8d05ed0eeeb620091d5
4
+ data.tar.gz: dffb3df502dc0fafeadef928a037f2b04a465b5f
5
+ SHA512:
6
+ metadata.gz: 99e4114502f9fa837966345dc221b76688745a3b8d4a5d3fd2a52930819b336efea724d10c1fe555d08acae13b3cd153bf9386e0004e6b4f834a6acd35bb3f23
7
+ data.tar.gz: 75e1783e6bea5854b7e8f42cf75e16c6b367743772fc48b6179c422bcd114150164f5074efcfeb5fe9644d7d6d70ad1a77b22e57257ca157d8b2419ca1fd5d97
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.3
5
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in to_php_array.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # ToPhpArray
2
+
3
+ Dump PHP Array from Ruby's Hash or Array.
4
+
5
+ [![Build Status](https://travis-ci.org/tsmsogn/to_php_array.svg?branch=master)](https://travis-ci.org/tsmsogn/to_php_array)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'to_php_array'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install to_php_array
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'to_php_array'
27
+
28
+ array = [1, 2]
29
+ ToPhpArray.dump(array) #=> array(1, 2)
30
+
31
+ array = [
32
+ 'foo',
33
+ 3,
34
+ [4, 5]
35
+ ]
36
+ ToPhpArray.dump(array) #=> array('foo', 3, array(4, 5))
37
+
38
+ hash = {
39
+ :foo => 1,
40
+ 2 => 3,
41
+ 'bar' => {
42
+ 4 => 5
43
+ }
44
+ }
45
+ ToPhpArray.dump(hash) #=> array('foo' => 1, 2 => 3, 'bar' => array(4 => 5))
46
+
47
+ array = [1, 2]
48
+ ToPhpArray.dump(array, { :wrap => true }) #=>
49
+ # array(
50
+ # 1,
51
+ # 2
52
+ # )
53
+
54
+ array = [
55
+ 'foo',
56
+ 3,
57
+ [4, 5],
58
+ ]
59
+ ToPhpArray.dump(array, { :wrap => true }) #=>
60
+ # array(
61
+ # 'foo',
62
+ # 3,
63
+ # array(
64
+ # 4,
65
+ # 5
66
+ # )
67
+ # )
68
+
69
+ hash = {
70
+ :foo => 1,
71
+ 2 => 3,
72
+ 'bar' => {
73
+ 4 => 5,
74
+ 'baz' => {
75
+ 6 => 7
76
+ }
77
+ }
78
+ }
79
+ ToPhpArray.dump(hash, { :wrap => true }) #=>
80
+ # array(
81
+ # 'foo' => 1,
82
+ # 2 => 3,
83
+ # 'bar' => array(
84
+ # 4 => 5,
85
+ # 'baz' => array(
86
+ # 6 => 7
87
+ # )
88
+ # )
89
+ # )
90
+
91
+ array = [1, 2]
92
+ ToPhpArray.dump(array, { :wrap => true, :indent_size => 2 }) #=>
93
+ # array(
94
+ # 1,
95
+ # 2
96
+ # )
97
+
98
+ array = [1, 2]
99
+ array.extend(ToPhpArray)
100
+ array.to_php_array #=> array(1, 2)
101
+
102
+ hash = {
103
+ :foo => 1,
104
+ 2 => 3,
105
+ 'bar' => {
106
+ 4 => 5
107
+ }
108
+ }
109
+ hash.extend(ToPhpArray)
110
+ hash.to_php_array #=> array('foo' => 1, 2 => 3, 'bar' => array(4 => 5))
111
+ ```
112
+
113
+ ## Development
114
+
115
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
116
+
117
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
118
+
119
+ ## Contributing
120
+
121
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tsmsogn/to_php_array.
122
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "to_php_array"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module ToPhpArray
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,57 @@
1
+ require "to_php_array/version"
2
+
3
+ module ToPhpArray
4
+ def to_php_array(options = {})
5
+ ::ToPhpArray::dump(self, options)
6
+ end
7
+
8
+ def self.dump(value, options = {})
9
+ options = {
10
+ :wrap => false,
11
+ :indent_size => 4,
12
+ :depth => 0,
13
+ :new_line => false
14
+ }.merge(options)
15
+
16
+ indent = " " * options[:indent_size] * options[:depth]
17
+
18
+ case value
19
+ when Hash
20
+ key_options = options.merge({ :depth => options[:depth] + 1,
21
+ :new_line => true })
22
+ value_options = options.merge({ :depth => options[:depth] + 1,
23
+ :new_line => false })
24
+ lines = value.map do |key, value|
25
+ "#{dump(key, key_options)} => #{dump(value, value_options)}"
26
+ end
27
+ if options[:wrap]
28
+ res = "array(\n" + lines.join(",\n") + "\n" + indent + ")"
29
+ else
30
+ res = "array(" + lines.join(", ") + ")"
31
+ end
32
+ when Array
33
+ value_options = options.merge({ :depth => options[:depth] + 1,
34
+ :new_line => true })
35
+ lines = value.map do |value|
36
+ dump(value, value_options)
37
+ end
38
+ if options[:wrap]
39
+ res = "array(\n" + lines.join(",\n") + "\n" + indent + ")"
40
+ else
41
+ res = "array(" + lines.join(", ") + ")"
42
+ end
43
+ when Fixnum
44
+ res = "#{value.to_s}"
45
+ when Symbol
46
+ res = "'" + value.to_s.gsub(/\'/, "\\\\'") + "'"
47
+ when String
48
+ res = "'" + value.gsub(/\'/, "\\\\'") + "'"
49
+ end
50
+
51
+ if options[:wrap] && options[:new_line]
52
+ indent + res
53
+ else
54
+ res
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'to_php_array/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "to_php_array"
8
+ spec.version = ToPhpArray::VERSION
9
+ spec.authors = ["tsmsogn"]
10
+ spec.email = ["tsmsogn@gmail.com"]
11
+
12
+ spec.summary = %q{Dump PHP Array from Ruby's Hash or Array.}
13
+ spec.description = %q{Dump PHP Array from Ruby's Hash or Array.}
14
+ spec.homepage = "https://github.com/tsmsogn/to_php_array"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_php_array
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tsmsogn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Dump PHP Array from Ruby's Hash or Array.
56
+ email:
57
+ - tsmsogn@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/to_php_array.rb
71
+ - lib/to_php_array/version.rb
72
+ - to_php_array.gemspec
73
+ homepage: https://github.com/tsmsogn/to_php_array
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Dump PHP Array from Ruby's Hash or Array.
96
+ test_files: []