capoeira 0.0.1
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/lib/capoeira.rb +81 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4f3a042f3ec14e7fc4219c6967000025e086fe2d
|
|
4
|
+
data.tar.gz: 565ce40b7433946bb768df0eb3b20cbfbd687143
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 57602df09d6652f2362918ca481a91bc90f8460eec92c6a64375617c3279b9f4259b9af4330ece1c1111071f658be27c68c12d1b4aa489244930247083fc5342
|
|
7
|
+
data.tar.gz: 527f1c549b7f12b5ec2c9755dc87e2ea49706805bede2383f88ac77257d537b96bf33c9e27fdcb606687be938b80d193a96ab042be2ab5b1fb10d8ca3cdb5e7b
|
data/lib/capoeira.rb
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Capoeira
|
|
2
|
+
class << self
|
|
3
|
+
def get_obj(symbol)
|
|
4
|
+
send(symbol) if respond_to?(symbol) && send(symbol).is_a?(Scope)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def obj(*symbols_or_hash, &block)
|
|
8
|
+
if (symbols = symbols_or_hash)[0].is_a?(Symbol)
|
|
9
|
+
get_obj symbols.each{ |symbol| define_scope symbol, &block }[-1]
|
|
10
|
+
elsif (hash = symbols_or_hash[0]).is_a?(Hash)
|
|
11
|
+
hash.each{ |k, v| define_scope(k).send (v.is_a?(Symbol) ? :is : :has), v }
|
|
12
|
+
else
|
|
13
|
+
block_given? ? Scope.new.instance_exec(&block) : Scope.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
alias_method :scope, :obj
|
|
18
|
+
alias_method :verb, :obj
|
|
19
|
+
alias_method :noun, :obj
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def define_scope(symbol = nil, &block)
|
|
24
|
+
scope = Scope.new symbol
|
|
25
|
+
define_singleton_method symbol do |sym = nil, &blk|
|
|
26
|
+
blk ? scope.instance_exec(sym, &blk) : scope
|
|
27
|
+
end
|
|
28
|
+
send symbol, &block
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Scope
|
|
34
|
+
attr_reader :title, :module
|
|
35
|
+
|
|
36
|
+
def initialize title = nil
|
|
37
|
+
@title = title
|
|
38
|
+
extend @module = Module.new
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def has *symbols_or_hash, &block
|
|
42
|
+
if (symbols = symbols_or_hash)[0].is_a? Symbol
|
|
43
|
+
@module.send(:define_method, symbols[0], &block) if block_given?
|
|
44
|
+
@module.send(:attr_accessor, *symbols) if !block_given?
|
|
45
|
+
elsif (hash = symbols_or_hash[0]).is_a? Hash
|
|
46
|
+
hash.each{|k, v| has k do v end }
|
|
47
|
+
end
|
|
48
|
+
self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def has? symbol
|
|
52
|
+
@module.method_defined? symbol
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def is *symbols
|
|
56
|
+
extend @module.send(:include, *symbols.map{ |sym| Capoeira.get_obj(sym).module })
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def is? scope
|
|
60
|
+
is_a? scope.module
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
alias_method :can, :is
|
|
64
|
+
alias_method :knows, :is
|
|
65
|
+
alias_method :can?, :is?
|
|
66
|
+
alias_method :knows?, :is?
|
|
67
|
+
alias_method :does, :has
|
|
68
|
+
alias_method :does?, :has?
|
|
69
|
+
|
|
70
|
+
def method_missing symbol, &block
|
|
71
|
+
if scope = Capoeira.get_obj(symbol)
|
|
72
|
+
block_given? ? scope.instance_exec(&block) : scope
|
|
73
|
+
else
|
|
74
|
+
super
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def capoeira &block
|
|
80
|
+
Capoeira.module_eval &block
|
|
81
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: capoeira
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Joseph Swetnam
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A dynamic metalayer to the Ruby object system.
|
|
14
|
+
email: jbswetnam@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/capoeira.rb
|
|
20
|
+
homepage: https://github.com/crownyx/capoeira
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.0.5
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Capoiera
|
|
44
|
+
test_files: []
|