babby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/babby.gemspec +23 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/babby.rb +47 -0
- data/lib/babby/version.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f01decd7ac10aa4cfeadfd021a58082b97f781b0
|
4
|
+
data.tar.gz: 2e0a6f850504d9183d7f09939ff269b84fbbc212
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 167ebd61c30bf7149ae445945809262946dfbe479ca08488e5b159f3d7b76fd28497a665637f2eb71c3bc0c956135a07e335b53ef8a63573fb22a324a4e3f163
|
7
|
+
data.tar.gz: 0b30c45c44b11a69451d31f44c464cfe08a45123345de3e82ed68dff55108665c7174a5ec885442d8f4bc06baa549fd0001161bd8aec50a2885ca42eb4207e39
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chaz Straney
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# How is Babby Formed?
|
2
|
+
|
3
|
+
A simple mixin to help crank out ruby DSLs a la ActiveRecord. Provides a method which adds a class instance variable, a class method to set that variable and an instance variable to retrieve the value for derived classes. For example:
|
4
|
+
|
5
|
+
```
|
6
|
+
class MyBase
|
7
|
+
include Babby::MetaDSL
|
8
|
+
|
9
|
+
dsl_method :thingy
|
10
|
+
|
11
|
+
dsl_method :doodad, type: :array
|
12
|
+
end
|
13
|
+
|
14
|
+
class MyDerived < MyBase
|
15
|
+
|
16
|
+
thingy "widget"
|
17
|
+
|
18
|
+
doodad "lol"
|
19
|
+
doodad "rofl"
|
20
|
+
end
|
21
|
+
|
22
|
+
i = MyDerived.new
|
23
|
+
i.thingy # => "widget"
|
24
|
+
i.doodad # => ["lol", "rofl"]
|
25
|
+
```
|
26
|
+
|
27
|
+
### But inheritance is yucky
|
28
|
+
Yes, but not for is-a relationships.
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
### TODOs
|
33
|
+
* add specs
|
34
|
+
* add inflection/pluralization for arrays, with manual getter specification as a backup.
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
data/babby.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'babby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "babby"
|
8
|
+
spec.version = Babby::VERSION
|
9
|
+
spec.authors = ["Chaz Straney"]
|
10
|
+
spec.email = ["chaz@plaidpotion.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Meta-DSL for writing simple inheritance-based DSLs.}
|
13
|
+
spec.description = %q{Meta-DSL for writing simple inheritance-based DSLs.}
|
14
|
+
spec.homepage = "http://www.github.com/chazu/babby/"
|
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.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "babby"
|
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
data/lib/babby.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "babby/version"
|
2
|
+
|
3
|
+
module Babby
|
4
|
+
module MetaDSL
|
5
|
+
def metaclass
|
6
|
+
class << self
|
7
|
+
self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
|
17
|
+
def dsl_method name, type: nil
|
18
|
+
state_type = type ? STATE_TYPE_MAP[type] : nil
|
19
|
+
|
20
|
+
if type == :array
|
21
|
+
define_singleton_method name do |value| # define 'setter' for derived class - i.e. DSL 'setup' method a la attr_accessor
|
22
|
+
if not self.instance_variable_get "@#{name}"
|
23
|
+
self.instance_variable_set "@#{name}", type ? state_type.new : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
self.instance_variable_get("@#{name}").push(value) # Set the underlying class instance variable to the desired value
|
27
|
+
end
|
28
|
+
else
|
29
|
+
define_singleton_method name do |value| # define 'setter' for derived class - i.e. DSL 'setup' method a la attr_accessor
|
30
|
+
if not self.instance_variable_get "@#{name}"
|
31
|
+
self.instance_variable_set "@#{name}", type ? state_type.new : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
self.instance_variable_set "@#{name}", value # Set the underlying class instance variable to the desired value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
define_singleton_method "get_#{name}".to_sym do
|
38
|
+
self.instance_variable_get "@#{name}"
|
39
|
+
end
|
40
|
+
|
41
|
+
define_method name do
|
42
|
+
self.class.send "get_#{name}".to_sym
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: babby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chaz Straney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-20 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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
|
+
description: Meta-DSL for writing simple inheritance-based DSLs.
|
42
|
+
email:
|
43
|
+
- chaz@plaidpotion.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- babby.gemspec
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/babby.rb
|
59
|
+
- lib/babby/version.rb
|
60
|
+
homepage: http://www.github.com/chazu/babby/
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Meta-DSL for writing simple inheritance-based DSLs.
|
84
|
+
test_files: []
|