glimmer 2.5.3 → 2.5.4

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
2
  SHA256:
3
- metadata.gz: 3f5103731be03f760a5835564ba6f3be84d2861b9a9c0c6f82fb854070ae3075
4
- data.tar.gz: fce2ab6404b29c93cb068a7e779c32c3a2d4f6abc209468c536acb1413e8cd39
3
+ metadata.gz: 8767081e5092e2238c10506725c9b552975128f7b463ec8d6d522a7b763cfcf9
4
+ data.tar.gz: df300e488e8094dc16293e3ab45a06b58a51e6620d3d744040dec2da4bdf09e7
5
5
  SHA512:
6
- metadata.gz: 67bb9d8b80194ec1004c137bc9d5b87525428b64c94063e512a3bb9291f67694440974c496785184d0b62f0d3abac62de6a662ecdff102df17009edb7bac1dd3
7
- data.tar.gz: 767ffd76f607076b4fce5edb70f130da7d777453ca1d94a79e39f5be3c1596b28b11dc29c6e3e98c9f4d2a1133e9ff70678c52cb18805b6e898c8d0d6ec02266
6
+ metadata.gz: 7b9aea718ba6d0e39860bbcf3f24f428dff3e0138ec26244676c9fab419a08a28fc39d4cd9db912b4a224a97016133d79efbf3e8321c4828f5fd66a36ad4b436
7
+ data.tar.gz: 8aa24fa09f117a33b276174c6631d7aecc940ff63346204c65711e2a5e4a064550bd7417d8c9aee4a539b26707c046b4afe7b9f989dea7bf372bb199328539bc
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  Related Change Logs:
4
4
  - [glimmer-dsl-swt/CHANGELOG.md](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/CHANGELOG.md)
5
5
 
6
+ ### 2.5.4
7
+
8
+ - `Glimmer::DataBinding::ObservableModel` support for observing model attributes with specified `:attribute_writer_type` option (default: `:attribute=`), which can be a single symbol or an array (e.g. `attribute_writer_type: [:attribute=, :set_attribute]`). Glimmer automatches attribute name and automatically generates observer notification attribute writer methods.
9
+
6
10
  ### 2.5.3
7
11
 
8
12
  - Provide `Observer#observe` option to tolerate not being able to extend an object for observation by silently not observing such object
data/README.md CHANGED
@@ -230,7 +230,7 @@ end
230
230
  ### Setup
231
231
 
232
232
  Follow these steps to author a [Glimmer](https://rubygems.org/gems/glimmer) DSL:
233
- - Add `gem 'glimmer', '~> 2.5.3'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.5.3` and add `require 'glimmer'`
233
+ - Add `gem 'glimmer', '~> 2.5.4'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.5.4` and add `require 'glimmer'`
234
234
  - Create `glimmer/dsl/[dsl_name]/dsl.rb`, which requires and adds all dynamic expressions for the [dsl_name] Glimmer DSL module as per the code shown in the previous section (or [Official DSLs](#official-dsls) as examples)
235
235
  - Create `glimmer/dsl/[dsl_name]/[expresion_name]_expresion.rb` for every [expresion_name] expression needed, whether dynamic or static
236
236
 
@@ -1187,7 +1187,7 @@ This relies mainly on the Observer Design Pattern and the MVP (Model-View-Presen
1187
1187
  These are the main classes concerning data-binding:
1188
1188
  - `Glimmer::DataBinding::Observer`: Provides general observer support including unique registration and deregistration for cleanup and prevention of memory leaks. Main methods concerned are: `call`, `register` (alias: `observe`), and `unregister` (alias: `unobserve` or `deregister`). Passing the option `ignore_frozen: true` at the end of the args of `register` (alias: `observe`) method results in silently ignoring any passed frozen observable without raising an error (it raises an error otherwise for frozen/immutable objects).
1189
1189
  - `Glimmer::DataBinding::Observable`: General super-module for all observables. Main methods concerned are: `add_observer` and `remove_observer`
1190
- - `Glimmer::DataBinding::ObservableModel`: Mixin module for any observable model (`Object`, `Struct` or `OpenStruct`) with observable attributes (observes attribute writers and `Struct`/`OpenStruct` `:[]=` method). In addition to `Observable` methods, it has a `notify_observers` method to be called when changes occur. It automatically enhances all attribute setters (ending with `=`) to notify observers on changes. Also, it automatically handles observing array attributes using `ObservableArray` appropriately so they would notify observers upon array mutation changes.
1190
+ - `Glimmer::DataBinding::ObservableModel`: Mixin module for any observable model (`Object`, `Struct` or `OpenStruct`) with observable attributes (observes attribute writers and `Struct`/`OpenStruct` `:[]=` method). In addition to `Observable` methods, it has a `notify_observers` method to be called when changes occur. It automatically enhances all attribute setters (ending with `=`) to notify observers on changes. Also, it automatically handles observing array attributes using `ObservableArray` appropriately so they would notify observers upon array mutation changes. `:attribute_writer_type` option can be specified (default: `:attribute=`) to observe different attribute styles (e.g. `attribute_writer_type: [:attribute=, :set_attribute]`).
1191
1191
  - `Glimmer::DataBinding::ObservableArray`: Mixin module for any observable array collection that automatically handles notifying observers upon performing array mutation operations (e.g. `push`, `select!`, or `delete`) recursively (meaning if an array contained arrays and they changed, observers are notified). Accepts `recursive: true` option in `add_observer` method to recursively observe nested arrays all the way down. Alternatively, pass `recursive: [integer]` to limit recursion in `Array` observation to a specific number of levels beyond the first level (which is always included).
1192
1192
  - `Glimmer::DataBinding::ObservableHash`: Mixin module for any observable hash that automatically handles notifying observers upon performing hash mutation operations (e.g. `hash[key]=value`, `select!`, `merge!`). Also, it automatically handles observing array values using `ObservableArray` appropriately so they would notify observers upon array mutation changes.
1193
1193
  - `Glimmer::DataBinding::ModelBinding`: a higher-level abstraction that relies on all the other observer/observable classes to support basic data-binding, nested data-binding, and computed data-binding
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.4
data/glimmer.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer 2.5.3 ruby lib
5
+ # stub: glimmer 2.5.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer".freeze
9
- s.version = "2.5.3"
9
+ s.version = "2.5.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2021-12-07"
14
+ s.date = "2021-12-08"
15
15
  s.description = "Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and an Observable / Observer / Data-Binding Library (including Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps), Glimmer DSL for Tk (Ruby Desktop Development GUI Library), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -40,8 +40,7 @@ module Glimmer
40
40
  end
41
41
  end
42
42
 
43
- PROPERTY_WRITER_FACTORY = lambda do |property_name, options|
44
- property_writer_name = "#{property_name}="
43
+ PROPERTY_WRITER_FACTORY = lambda do |property_name, property_writer_name, options|
45
44
  lambda do |value|
46
45
  old_value = self.send(property_name)
47
46
  unregister_dependent_observers(property_name, old_value) # remove dependent observers previously installed in ensure_array_object_observer
@@ -52,6 +51,7 @@ module Glimmer
52
51
  end
53
52
 
54
53
  def add_observer(observer, property_name, options = {})
54
+ initialize_observer_options(options)
55
55
  return observer if has_observer?(observer, property_name)
56
56
  property_observer_list(property_name) << observer
57
57
  add_property_writer_observers(property_name, options)
@@ -113,20 +113,24 @@ module Glimmer
113
113
  end
114
114
 
115
115
  def add_property_writer_observers(property_name, options)
116
- property_writer_name = "#{property_name}="
117
- method(property_writer_name)
118
- ensure_array_object_observer(property_name, send(property_name), nil, options)
119
- begin
120
- method("__original__#{property_writer_name}")
121
- rescue
122
- define_singleton_method("__original__#{property_writer_name}", property_writer_method(property_writer_name))
123
- # Note the limitation that the first observe call options apply to all subsequent observations meaning even if unobserve was called, options do not change from initial ones
124
- # It is good enough for now. If there is a need to address this in the future, this is where to start the work
125
- define_singleton_method(property_writer_name, &PROPERTY_WRITER_FACTORY.call(property_name, options))
116
+ options[:attribute_writer_type].each do |attribute_writer_type|
117
+ begin
118
+ property_writer_name = attribute_writer_type.to_s.gsub('attribute', property_name.to_s)
119
+ method(property_writer_name)
120
+ ensure_array_object_observer(property_name, send(property_name), nil, options)
121
+ begin
122
+ method("__original__#{property_writer_name}")
123
+ rescue
124
+ define_singleton_method("__original__#{property_writer_name}", property_writer_method(property_writer_name))
125
+ # Note the limitation that the first observe call options apply to all subsequent observations meaning even if unobserve was called, options do not change from initial ones
126
+ # It is good enough for now. If there is a need to address this in the future, this is where to start the work
127
+ define_singleton_method(property_writer_name, &PROPERTY_WRITER_FACTORY.call(property_name, property_writer_name, options))
128
+ end
129
+ rescue => e
130
+ #ignore writing if no property writer exists
131
+ Glimmer::Config.logger.debug {"No need to observe property writer: #{property_writer_name}\n#{e.message}\n#{e.backtrace.join("\n")}"}
132
+ end
126
133
  end
127
- rescue => e
128
- #ignore writing if no property writer exists
129
- Glimmer::Config.logger.debug {"No need to observe property writer: #{property_writer_name}\n#{e.message}\n#{e.backtrace.join("\n")}"}
130
134
  end
131
135
 
132
136
  def property_writer_method(property_writer_name)
@@ -157,6 +161,11 @@ module Glimmer
157
161
  @array_object_observers[property_name] = Notifier.new(self, property_name) unless @array_object_observers.has_key?(property_name)
158
162
  @array_object_observers[property_name]
159
163
  end
164
+
165
+ def initialize_observer_options(options)
166
+ options[:attribute_writer_type] ||= [:attribute=]
167
+ options[:attribute_writer_type] = [options[:attribute_writer_type]] if !options[:attribute_writer_type].is_a?(Array)
168
+ end
160
169
  end
161
170
  end
162
171
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-07 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: array_include_methods