evt-attribute 0.1.3.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: 84e4750f8ee634fd0a4ce789d9d73066138c3e7a
4
+ data.tar.gz: ce38778fd644bfc3e32041b333255b312725db32
5
+ SHA512:
6
+ metadata.gz: 8b85c0dc18f503d7ed9a2c0a0cc7f8310ae0becf8b459a8f471041e73a90b6596c555fd40edc188fd3c405982081b9b7200d5f35993d33300ac8acf43664a9c6
7
+ data.tar.gz: f02c277b54f14440ba4556ea4f30608cd1e008a722bc95bd9bc26e7c0cc5363b73f92b0f56f67795ae73bca23ead1a9fc39edd17ea6898652d5530fd75358abe
@@ -0,0 +1 @@
1
+ require 'attribute/define'
@@ -0,0 +1,54 @@
1
+ module Attribute
2
+ module Define
3
+ extend self
4
+
5
+ def call(target_class, attr_name, visibility=nil, check: nil, &initialize_value)
6
+ visibility ||= :reader
7
+
8
+ if [:reader, :accessor].include? visibility
9
+ define_reader(target_class, attr_name, visibility, check, &initialize_value)
10
+ end
11
+
12
+ if [:writer, :accessor].include? visibility
13
+ define_writer(target_class, attr_name, visibility, check, &initialize_value)
14
+ end
15
+
16
+ attr_name
17
+ end
18
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
19
+
20
+ def define_reader(target_class, attr_name, visibility, check, &initialize_value)
21
+ attr_name = :"#{attr_name}" unless attr_name.is_a? Symbol
22
+ var_name = "@#{attr_name}"
23
+ target_class.send :define_method, attr_name do
24
+ val = instance_variable_get(var_name)
25
+
26
+ if val.nil?
27
+ if initialize_value
28
+ val = initialize_value.()
29
+ instance_variable_set var_name, val
30
+ end
31
+ end
32
+
33
+ if check
34
+ check.(val)
35
+ end
36
+
37
+ val
38
+ end
39
+ end
40
+
41
+ def define_writer(target_class, attr_name, visibility, check, &initialize_value)
42
+ attr_name = :"#{attr_name}" unless attr_name.is_a? Symbol
43
+ writer_name = :"#{attr_name}="
44
+ var_name = "@#{attr_name}"
45
+ target_class.send :define_method, writer_name do |val|
46
+ if check
47
+ check.(val)
48
+ end
49
+
50
+ instance_variable_set var_name, val
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-attribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3.1
5
+ platform: ruby
6
+ authors:
7
+ - The Eventide Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ntl-test_bench
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: " "
28
+ email: opensource@eventide-project.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/attribute.rb
34
+ - lib/attribute/define.rb
35
+ homepage: https://github.com/eventide-project/attribute
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.3
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.5.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Define an attribute on a class using an imperative API
59
+ test_files: []