omg_objectify 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/objectify.rb +64 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 832ecc75078d3a6cc71b9a61a0191f9985efd0e54c72883e15a3f75073070757
4
+ data.tar.gz: 47ddd72a0dbfccd7c163c4a6df9f088e4c305e138bf91a5e07a35093570d9537
5
+ SHA512:
6
+ metadata.gz: a56ce8da20a3482fce46f6e013e52f69a2920f7bfb8eacdb61d89da890dc29bc30e86a0a47d2d9d6c1e056779a6a2bcbc93ea88af8034dedc003dab5ec57c2db
7
+ data.tar.gz: e02ab65ad07425a68bc5184f59290b222abb1927a37eea1428d718c900d1d9e2552ebc10ccaccab6d94723e8c24d796e33709114a903e2f46dc84bff0ea0ac82
@@ -0,0 +1,64 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Objectify
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ class << self
9
+ def register_object name
10
+ nameString = String(name)
11
+ self.class_eval <<-EOS
12
+ class << self
13
+ def #{nameString.pluralize}
14
+ @@#{nameString.pluralize} ||= []
15
+ end
16
+ end
17
+ EOS
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ def object(name, attrs:[])
23
+ klass = Class.new Object
24
+ className = String(name).camelize
25
+ nameString = String(name)
26
+
27
+ attrs.each do |attr|
28
+ if attr.is_a? Hash
29
+ klass.class_eval <<-EOS
30
+ def #{attr.keys.first.to_s}
31
+ instance_eval #{attr.values.first}
32
+ end
33
+ EOS
34
+ else
35
+ klass.class_eval <<-EOS
36
+ attr_reader :#{attr}
37
+ attr_accessor :#{attr}
38
+ EOS
39
+ end
40
+ end
41
+
42
+ self.class_eval <<-EOS
43
+ class << self
44
+ def #{nameString}(#{attrs.map{ |a| "#{String(a)}: nil" }.join(', ')})
45
+ item = #{className}.new(#{attrs.map{ |a| "#{String(a)}: #{String(a)}" }.join(', ')})
46
+ Objectify.#{nameString.pluralize}.push(item)
47
+ item
48
+ end
49
+ end
50
+ EOS
51
+
52
+ self.const_set className, klass
53
+ Objectify::register_object name
54
+ end
55
+ end
56
+
57
+ class Object
58
+ def initialize(**attrs)
59
+ attrs.each do |key, value|
60
+ instance_variable_set("@#{key}", value)
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omg_objectify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Greenfield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/objectify.rb
20
+ homepage: https://rubygems.org/gems/omg_objectify
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.7.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Allows the creation of dynamic object definitions and instances
44
+ test_files: []