bindy 0.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: 0d66f073aa559946178b2bd63c84424dbaa717e8
4
+ data.tar.gz: 2a6b9b901e1d0f043ee9f79db2b5ec51e9dfdcdb
5
+ SHA512:
6
+ metadata.gz: 7acbd71c59c5b8909a7f960799a5756ea1f112e8e9285f22ae4412ad6ea113cf9bc5d1f6b5d1ec2fba6c260e3045dcdbfebeffd2ad5b4ed5e265a25ed9031e2b
7
+ data.tar.gz: 9171518e14d9d47565d35725cc85fa616596f8ae93cc2daef9f246b34be16297ad30332dad6e368dcee10e888a7a0166e0cbd2790e7031c75010eff56c6322a0
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: D7fLHgaDGJcXq9okjT3a9arCiphuoLBsJ
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ bindy
@@ -0,0 +1 @@
1
+ ruby 2.0.0
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - jruby
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bindy.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Gabriel Naiman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Bindy
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/bindy.png)](https://rubygems.org/gems/bindy)
4
+ [![Build Status](https://travis-ci.org/gabynaiman/bindy.png?branch=master)](https://travis-ci.org/gabynaiman/bindy)
5
+ [![Coverage Status](https://coveralls.io/repos/gabynaiman/bindy/badge.png?branch=master)](https://coveralls.io/r/gabynaiman/bindy?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/gabynaiman/bindy.png)](https://codeclimate.com/github/gabynaiman/bindy)
7
+ [![Dependency Status](https://gemnasium.com/gabynaiman/bindy.png)](https://gemnasium.com/gabynaiman/bindy)
8
+
9
+ Context binding for functions evaluation
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'bindy'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install bindy
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/bindy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << 'spec'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ t.verbose = false
8
+ end
9
+
10
+ task default: :spec
11
+
12
+ desc 'Pry console'
13
+ task :console do
14
+ require 'bindy'
15
+ require 'pry'
16
+ ARGV.clear
17
+ Pry.start
18
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bindy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bindy'
8
+ spec.version = Bindy::VERSION
9
+ spec.authors = ['Gabriel Naiman']
10
+ spec.email = ['gabynaiman@gmail.com']
11
+
12
+ spec.summary = 'Context binding for functions evaluation'
13
+ spec.description = 'Context binding for functions evaluation'
14
+ spec.homepage = 'https://github.com/gabynaiman/bindy'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'treetop', '~> 1.6.3'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'minitest', '~> 4.7'
27
+ spec.add_development_dependency 'turn', '~> 0.9'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'pry-nav'
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'treetop'
2
+
3
+ require 'bindy/version'
4
+ require 'bindy/context'
5
+ require 'bindy/language'
6
+ require 'bindy/language_interpreters'
@@ -0,0 +1,45 @@
1
+ module Bindy
2
+
3
+ class Context
4
+
5
+ attr_reader :variables
6
+
7
+ def initialize(variables)
8
+ @variables = variables
9
+ end
10
+
11
+ def bind(object)
12
+ case object
13
+ when Hash then bind_hash object
14
+ when Array then bind_array object
15
+ when String then bind_string object
16
+ else raise "Unbindable #{object}"
17
+ end
18
+ end
19
+
20
+ def var(name)
21
+ name.split('.').inject(variables) do |vars, key|
22
+ vars.fetch(key, vars.fetch(key.to_sym))
23
+ end
24
+ rescue KeyError
25
+ raise "Undefined variable #{name}"
26
+ end
27
+
28
+ private
29
+
30
+ def bind_hash(hash)
31
+ hash.each_with_object({}) do |(k,v),h|
32
+ h[k] = bind v
33
+ end
34
+ end
35
+
36
+ def bind_array(array)
37
+ array.map { |v| bind v }
38
+ end
39
+
40
+ def bind_string(string)
41
+ Language.parse(string).evaluate(self)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,58 @@
1
+ module Bindy
2
+ grammar Language
3
+
4
+ rule expression
5
+ function / value
6
+ end
7
+
8
+ rule function
9
+ identifier:identifier space* '(' space* arg_list:arg_list space* ')' <Function>
10
+ end
11
+
12
+ rule arg_list
13
+ expression space* ',' space* arg_list <ArgList> /
14
+ expression
15
+ end
16
+
17
+ rule identifier
18
+ [a-z\_]+
19
+ end
20
+
21
+ rule value
22
+ number / boolean / string
23
+ end
24
+
25
+ rule string
26
+ [\da-zA-ZáéíóúüñÁÉÍÓÚÜÑ¿?!¡\s\@\#\$\%\&\/\\\*\_\-\+\/\\\*\_\-\+\.\,\:\;\<\>\|\"\']+ <LiteralString>
27
+ end
28
+
29
+ rule number
30
+ float / integer
31
+ end
32
+
33
+ rule integer
34
+ [\+\-]? [\d]+ <LiteralInteger>
35
+ end
36
+
37
+ rule float
38
+ [\+\-]? [\d]+ '.' [\d]+ <LiteralFloat>
39
+ end
40
+
41
+ rule boolean
42
+ true / false
43
+ end
44
+
45
+ rule true
46
+ 'true' <LiteralTrue>
47
+ end
48
+
49
+ rule false
50
+ 'false' <LiteralFalse>
51
+ end
52
+
53
+ rule space
54
+ [\s\t\n]
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,71 @@
1
+ module Bindy
2
+ module Language
3
+
4
+ class << self
5
+
6
+ def parse(expression)
7
+ parsed_expression = parser.parse expression
8
+ raise parser.failure_reason unless parsed_expression
9
+ parsed_expression
10
+ end
11
+
12
+ private
13
+
14
+ def parser
15
+ @parser ||= LanguageParser.new
16
+ end
17
+
18
+ end
19
+
20
+ class Function < Treetop::Runtime::SyntaxNode
21
+ def evaluate(context)
22
+ context.public_send name, *arguments.map { |a| a.evaluate context }
23
+ end
24
+
25
+ def name
26
+ identifier.text_value
27
+ end
28
+
29
+ def arguments
30
+ arg_list.respond_to?(:to_a) ? arg_list.to_a : [arg_list]
31
+ end
32
+ end
33
+
34
+ class ArgList < Treetop::Runtime::SyntaxNode
35
+ def to_a
36
+ [expression] | (arg_list.respond_to?(:to_a) ? arg_list.to_a : [arg_list])
37
+ end
38
+ end
39
+
40
+ class LiteralString < Treetop::Runtime::SyntaxNode
41
+ def evaluate(context)
42
+ text_value
43
+ end
44
+ end
45
+
46
+ class LiteralInteger < Treetop::Runtime::SyntaxNode
47
+ def evaluate(context)
48
+ text_value.to_i
49
+ end
50
+ end
51
+
52
+ class LiteralFloat < Treetop::Runtime::SyntaxNode
53
+ def evaluate(context)
54
+ text_value.to_f
55
+ end
56
+ end
57
+
58
+ class LiteralTrue < Treetop::Runtime::SyntaxNode
59
+ def evaluate(context)
60
+ true
61
+ end
62
+ end
63
+
64
+ class LiteralFalse < Treetop::Runtime::SyntaxNode
65
+ def evaluate(context)
66
+ false
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module Bindy
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bindy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: treetop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.3
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.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: turn
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Context binding for functions evaluation
112
+ email:
113
+ - gabynaiman@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .coveralls.yml
119
+ - .gitignore
120
+ - .ruby-gemset
121
+ - .ruby-version
122
+ - .travis.yml
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bindy.gemspec
129
+ - lib/bindy.rb
130
+ - lib/bindy/context.rb
131
+ - lib/bindy/language.treetop
132
+ - lib/bindy/language_interpreters.rb
133
+ - lib/bindy/version.rb
134
+ homepage: https://github.com/gabynaiman/bindy
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.3
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Context binding for functions evaluation
158
+ test_files: []