such 0.4.0 → 1.0.210117

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 69f8edd38b0a7e373c70c896c47a08c629af311a
4
- data.tar.gz: 72b897561c138e4efc85facdc39300f5b27a3386
2
+ SHA256:
3
+ metadata.gz: 8455f46116268e25b466323fb8d75b76d6084c815b8007a5d7d8cd934a15758d
4
+ data.tar.gz: 577f05b1c0bc9d4d3a1a93ee58103f7656243dbd064ed7d887cec899a3de47e6
5
5
  SHA512:
6
- metadata.gz: e9f866da5f5971f67cee50008942332fcdb2e3377b81ba4e7ee30d0b5dc1ed3ef223e7706a8f4f0627bdfe3b65dd57a188c69ea167ee3b11f4ebe803263caf08
7
- data.tar.gz: 0452ec9e456484ec83b53103c766288e71c1d9d12ca38b63d4d745af3ae578a797263462dfacf61f5505757299e8e0937b99ed2af0ad5574aefa16374d5ccf2b
6
+ metadata.gz: c008f4588f1ea74638d76279d0f7ccc9ffd1a9f321e2cbd32d14bf0ad5e7da70903995b03d9820cf4a95af302269b5d99c9bf952fa7a346aebc77724d9091ddf
7
+ data.tar.gz: 8cce6a2ce219fe0f9a435f9d4236cb24ba28d60e62b585eb53cd2aa49bb9aacdf5ae43d29a864c761d472ded4cd02a3dca989c3a24b19dd8b5bc40658e303417
@@ -1,53 +1,77 @@
1
- = Such
1
+ # Such
2
2
 
3
- == DESCRIPTION:
3
+ * [VERSION 1.0.210117](https://github.com/carlosjhr64/such/releases)
4
+ * [github](https://www.github.com/carlosjhr64/such)
5
+ * [rubygems](https://rubygems.org/gems/such)
6
+
7
+ ## DESCRIPTION:
4
8
 
5
9
  Wraps widgets with an alternate constructor
6
10
  which factors out the configuration and assembly procedures into metadata.
7
11
  Can be used to wrap any class with the alternate constructor,
8
- although currently only Gtk3 widgets is supported.
12
+ although targeted only Gtk3 widgets.
13
+
14
+ ## INSTALL:
15
+
16
+ ```shell
17
+ $ sudo gem install such
18
+ ```
9
19
 
10
- == SYNOPSIS:
20
+ ## SYNOPSIS:
11
21
 
12
- require 'gtk3'
13
- require 'such'
14
- include Such; Things.gtk_widget
22
+ ```ruby
23
+ require 'gtk3'
24
+ require 'such'
25
+ include Such; Things.in Gtk::Widget
15
26
 
16
- Thing.configure window: {
17
- set_title: 'Synopsis Example',
18
- set_window_position: :center },
19
- BUTTON: [label: 'Button!'],
20
- button: {set_size_request: [100,50], into:[:add]}
27
+ Thing.configure window: {
28
+ set_title: 'Synopsis Example',
29
+ set_window_position: :center},
30
+ BUTTON: [label: 'Button!'],
31
+ button: {
32
+ set_size_request: [100,50],
33
+ into:[:add]}
21
34
 
22
- window = Window.new(:window, 'destroy'){Gtk.main_quit}
23
- Button.new(window, :button!){puts 'Button pressed!'}
24
- window.show_all
35
+ window = Window.new(:window, 'destroy'){Gtk.main_quit} #~> Such::Window
36
+ Button.new(window, :button!){puts 'Button pressed!'} #~> Such::Button
37
+ window.show_all
25
38
 
26
- Gtk.main
39
+ Gtk.main #=> nil
40
+ ```
27
41
 
28
- == MORE:
42
+ ## MORE:
29
43
 
30
44
  Arrays are passed to constructer's super,
31
45
  Hashes are method=>arguments pairs, and Strings are signals.
32
46
  Other objects are assumed to be containers:
33
47
 
34
- Such::Button.new(window, [label: 'Hello!'], {set_size_request:[100,50]}, 'clicked' ){puts 'OK'}
48
+ ```ruby
49
+ Such::Button.new(
50
+ window,
51
+ [label: 'Hello!'],
52
+ {set_size_request:[100,50]},
53
+ 'clicked'
54
+ ){ puts 'OK'}
35
55
 
36
- # Is equivalent to
56
+ # Is equivalent to:
37
57
 
38
- button = Gtk::Button.new(label:'Hello!')
39
- window.add button
40
- button.set_size_request 100, 50
41
- button.signal_connect('clicked'){puts 'OK'}
58
+ button = Gtk::Button.new(label:'Hello!')
59
+ window.add button
60
+ button.set_size_request 100, 50
61
+ button.signal_connect('clicked'){puts 'OK'}
62
+ ```
42
63
 
43
- To set the packing method to say, :pack_start, set the :into method as follows:
64
+ To set the packing method to say `:pack_start`, set the `:into` method as follows:
44
65
 
45
- {into: [:pack_start, expand:false, fill:false, padding:0]}
46
- # The effect in the contructor will be as if the following was run:
47
- # container.pack_start(self, expand:false, fill:false, padding:0)
66
+ ```ruby
67
+ {into: [:pack_start, expand:false, fill:false, padding:0]}
68
+ # The effect in the contructor will be as if the following was run:
69
+ # container.pack_start(self, expand:false, fill:false, padding:0)
70
+ ```
48
71
 
49
72
  One can configure Symbol keys to represent metadata about a widget:
50
73
 
74
+ ```ruby
51
75
  Thing.configure(
52
76
  KEY: [ arg1, arg2, arg3 ], # an array for super(arg1, arg2, arg3)
53
77
  key: { # a hash for like self.method(args)
@@ -57,11 +81,12 @@ One can configure Symbol keys to represent metadata about a widget:
57
81
  },
58
82
  key!: [[arg1, arg2], {meth1:args1, meth2:args2}, 'signal1', 'signal2'] # the splatter bang!
59
83
  )
84
+ ```
60
85
 
61
86
  The examples in this repository are reworks of the examples given in
62
87
  ZetCode.com[http://zetcode.com/gui/rubygtk/] (back in 2015).
63
88
 
64
- === Features:
89
+ ## Features:
65
90
 
66
91
  * :key! content *splat
67
92
  * Undefined :key! expanded to :KEY, :key
@@ -70,21 +95,17 @@ ZetCode.com[http://zetcode.com/gui/rubygtk/] (back in 2015).
70
95
  * Packing method defaults (ultimately) to :add
71
96
  * Way to change default packing behaviour
72
97
 
73
- == INSTALL:
74
-
75
- $ sudo gem install such
76
-
77
- == But wait! One more thing:
98
+ ## But wait! One more thing:
78
99
 
79
- See link:examples/such_parts_demo in the examples directory
80
- and link:test/tc_part for hints on how to use the much powerful
81
- Such::Part module link:lib/such/part.rb
100
+ See [such_parts_demo](examples/such_parts_demo) in the examples directory
101
+ and [tc_part](test/tc_part) for hints on how to use the powerful
102
+ [Such::Part module](lib/such/part.rb).
82
103
 
83
- == LICENSE:
104
+ ## LICENSE:
84
105
 
85
106
  (The MIT License)
86
107
 
87
- Copyright (c) 2017
108
+ Copyright (c) 2021 CarlosJHR64
88
109
 
89
110
  Permission is hereby granted, free of charge, to any person obtaining
90
111
  a copy of this software and associated documentation files (the
@@ -1,8 +1,8 @@
1
1
  module Such
2
- VERSION = '0.4.0'
2
+ VERSION = '1.0.210117'
3
3
  end
4
- require 'such/thing'
5
4
  require 'such/such'
5
+ require 'such/thing'
6
6
  require 'such/things'
7
7
  require 'such/part'
8
8
  require 'such/parts'
@@ -1,29 +1,33 @@
1
1
  module Such
2
2
  module Part
3
+ PLUG_PATTERN = /^(?<sym>[^\W_]+)_(?<cls>[^\W_]+)$/
4
+
3
5
  def initialize(*parameters, &block)
4
6
  super(*parameters)
5
7
  self.class.plugs.each do |plg|
6
- if /^(?<sym>[^\W_]+)_(?<cls>[^\W_]+)$/=~plg
7
- plg, sym, cls = method("#{plg}="), "#{sym}!".to_sym, Object.const_get("Such::#{cls}")
8
- plg.call cls.new(self, sym, &block)
8
+ if md = PLUG_PATTERN.match(plg)
9
+ plg, sym, cls = "#{plg}=".to_sym, "#{md[:sym]}!".to_sym, Object.const_get("Such::#{md[:cls]}")
10
+ # self.<plg> = Such::<cls>.new(self, :<sym>!, &block)
11
+ public_send plg, cls.new(self, sym, &block)
9
12
  end
10
13
  end
11
14
  end
12
15
 
13
16
  def message(*parameters)
14
- self.class.plugs.each{|plg| method(plg).call.message(*parameters)}
17
+ self.class.plugs.each{|plg| public_send(plg).message(*parameters) }
15
18
  end
16
19
 
17
- def method_missing(plug,*args) # assuming a plug
18
- super unless args.length==0 and plug=~/^[^\W_]+_[^\W_]+$/
19
- obj = nil
20
- self.class.plugs.each do |plg|
21
- plug = method(plg).call
22
- if plug.is_a? Such::Part
23
- break if obj = plug.method(plg).call
20
+ def method_missing(maybe,*args) # maybe a plug down the plugged things.
21
+ super unless args.length==0 and PLUG_PATTERN.match?(maybe)
22
+ self.class.plugs.each do |plug|
23
+ thing = public_send(plug)
24
+ if thing.is_a? Such::Part
25
+ if obj = thing.public_send(maybe)
26
+ return obj
27
+ end
24
28
  end
25
29
  end
26
- return obj
30
+ return nil
27
31
  end
28
32
  end
29
33
  end
@@ -1,7 +1,9 @@
1
1
  module Such
2
2
  module Parts
3
3
  def self.make(part, thing, *plugs)
4
- raise "Such::#{thing} not defined." unless Object.const_defined?("Such::#{thing}")
4
+ unless thing < Such::Thing and [part,*plugs].all?{_1.is_a? Symbol}
5
+ raise "Expected Such::Parts.make(Symbol part, Class thing < Such::Thing, *Symbol plugs)"
6
+ end
5
7
  plugs.each do |plug|
6
8
  if /^[^\W_]+_(?<klass>[^\W_]+)$/=~plug
7
9
  next unless $VERBOSE
@@ -12,13 +14,9 @@ module Such
12
14
  raise "Plugs must have the form key_class: #{plug}"
13
15
  end
14
16
  end
15
- Such.subclass part, thing, <<-EOT
16
- attr_accessor :#{plugs.join(', :')}
17
- def self.plugs
18
- [:#{plugs.join(', :')}]
19
- end
20
- include Such::Part
21
- EOT
17
+ subklass = Such.subclass(part, thing, include: Such::Part, attr_accessor: plugs)
18
+ subklass.singleton_class.class_eval{ define_method(:plugs){plugs} }
19
+ return subklass
22
20
  end
23
21
  end
24
22
  end
@@ -1,15 +1,8 @@
1
1
  module Such
2
- def self.subclass(clss, sprclss="Gtk::#{clss}", body='include Such::Thing')
3
- code = <<-CODE
4
- class #{clss} < #{sprclss}
5
- #{body}
6
- end
7
- CODE
8
- begin
9
- eval code
10
- rescue Exception
11
- $stderr.puts code if $VERBOSE
12
- raise $!
13
- end
2
+ def self.subclass(name, klass, **kw, &block)
3
+ subklass = const_set(name, Class.new(klass))
4
+ kw.each{|method, args| subklass.public_send(method, *args)}
5
+ subklass.class_eval(&block) if block
6
+ return subklass
14
7
  end
15
8
  end
@@ -1,10 +1,11 @@
1
1
  module Such
2
2
  module Thing
3
- INTOS = [:set_submenu, :pack_start, :append, :add] # TODO:TK!?
3
+ SIGNALS = ['clicked']
4
+ INTOS = [:set_submenu, :pack_start, :append, :add]
4
5
 
5
6
  PARAMETERS = {}
6
7
  def self.configure(conf)
7
- conf.each{|k,v| PARAMETERS[k]=v}
8
+ PARAMETERS.merge! conf
8
9
  end
9
10
 
10
11
  def self.trace_method(obj, mthd, args)
@@ -36,17 +37,17 @@ module Such
36
37
  case parameter
37
38
  when Symbol
38
39
  # Symbols are expected to translate to something else.
39
- Thing.do_symbol(parameter, parameters)
40
+ Thing.do_symbol parameter, parameters
40
41
  when Array
41
42
  # Arrays are added to the Thing's arguments list.
42
- arguments += parameter
43
+ arguments.concat parameter
43
44
  when Hash
44
45
  # Hashes are expected to be a symbol list of methods on Thing with respective arguments.
45
46
  # It's possible to override a previously defined method with new arguments.
46
- parameter.each{|k,v| methods[k]=v}
47
+ methods.merge! parameter
47
48
  when String
48
49
  # Typically a signal: Thing#signal_connect(signal){|*emits| block.call(*emits)}
49
- signals.push(parameter)
50
+ signals.push parameter
50
51
  else
51
52
  # Assume it's a container
52
53
  container = parameter
@@ -72,7 +73,7 @@ module Such
72
73
  mthd=Thing.which_method(container)
73
74
  end
74
75
  Thing.trace_method(container, mthd, [obj.class,*args]) if $VERBOSE
75
- container.method(mthd).call(obj, *args)
76
+ container.public_send(mthd, obj, *args)
76
77
  else
77
78
  warn "Warning: Container for #{self.class} not given."
78
79
  end
@@ -92,7 +93,7 @@ module Such
92
93
 
93
94
  def self.do_methods(obj, methods, container=nil)
94
95
  # If user does not specify how to add to container, assume default way.
95
- methods[:into]=Thing.which_method(container) if container and !methods.has_key?(:into)
96
+ methods[:into]=Thing.which_method(container) if container and not methods.has_key?(:into)
96
97
  methods.each do |mthd, args|
97
98
  (mthd==:into)? Thing.into(obj, container, *args) :
98
99
  Thing.do_method(obj, mthd, *args)
@@ -103,14 +104,14 @@ module Such
103
104
  return if signals.first==''
104
105
  none = (signals.length==0)
105
106
  if block
106
- signals.push('clicked') if block and none # TODO: TK!?
107
+ signals.push(*SIGNALS) if none
107
108
  signals.each do |signal|
108
109
  break if signal==''
109
110
  begin
110
- obj.signal_connect(signal){|*emits| block.call(*emits, signal)} # TODO: TK!?
111
+ obj.signal_connect(signal){|*emits| block.call(*emits, signal)}
111
112
  Thing.trace_signal(obj, signal) if $VERBOSE
112
113
  rescue GLib::NoSignalError
113
- warn "Warning: no \"#{signal}\" signal for #{obj.class}"
114
+ warn "Warning: no #{signal} signal for #{obj.class}"
114
115
  end
115
116
  end
116
117
  elsif not none
@@ -1,21 +1,21 @@
1
1
  module Such
2
2
  module Things
3
- def self.list(klss)
4
- ObjectSpace.each_object(Class).select{|k| k < klss}
3
+ def self.list(superklass)
4
+ ObjectSpace.each_object(Class).select{|klass| klass < superklass}
5
5
  end
6
6
 
7
- def self.in(klass)
8
- Things.list(klass).each do |clss|
7
+ def self.subclass(klass)
8
+ Such.subclass(klass.name.sub(/^.*::/,'').to_sym, klass, include: Such::Thing)
9
+ end
10
+
11
+ def self.in(superklass)
12
+ Things.list(superklass).each do |klass|
9
13
  begin
10
- Such.subclass(clss.name.sub(/^.*::/, ''))
11
- rescue Exception
12
- $stderr.puts "#{$!.class}:\t#{clss}" if $VERBOSE
14
+ Things.subclass(klass)
15
+ rescue
16
+ $stderr.puts "#{$!.class}:\t#{superklass}" if $VERBOSE
13
17
  end
14
18
  end
15
19
  end
16
-
17
- def self.gtk_widget
18
- Things.in(Gtk::Widget)
19
- end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,27 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: such
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.210117
5
5
  platform: ruby
6
6
  authors:
7
7
  - carlosjhr64
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-31 00:00:00.000000000 Z
11
+ date: 2021-01-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Wraps widgets with an alternate constructor
15
15
  which factors out the configuration and assembly procedures into metadata.
16
16
  Can be used to wrap any class with the alternate constructor,
17
- although currently only Gtk3 widgets is supported.
17
+ although targeted only Gtk3 widgets.
18
18
  email: carlosjhr64@gmail.com
19
19
  executables: []
20
20
  extensions: []
21
- extra_rdoc_files:
22
- - README.rdoc
21
+ extra_rdoc_files: []
23
22
  files:
24
- - README.rdoc
23
+ - README.md
25
24
  - lib/such.rb
26
25
  - lib/such/part.rb
27
26
  - lib/such/parts.rb
@@ -32,10 +31,8 @@ homepage: https://github.com/carlosjhr64/such
32
31
  licenses:
33
32
  - MIT
34
33
  metadata: {}
35
- post_install_message:
36
- rdoc_options:
37
- - "--main"
38
- - README.rdoc
34
+ post_install_message:
35
+ rdoc_options: []
39
36
  require_paths:
40
37
  - lib
41
38
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -49,12 +46,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
46
  - !ruby/object:Gem::Version
50
47
  version: '0'
51
48
  requirements:
52
- - 'ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]'
53
- rubyforge_project:
54
- rubygems_version: 2.6.11
55
- signing_key:
49
+ - 'ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]'
50
+ rubygems_version: 3.2.3
51
+ signing_key:
56
52
  specification_version: 4
57
53
  summary: Wraps widgets with an alternate constructor which factors out the configuration
58
54
  and assembly procedures into metadata. Can be used to wrap any class with the alternate
59
- constructor, although currently only Gtk3 widgets is supported.
55
+ constructor, although targeted only Gtk3 widgets.
60
56
  test_files: []