Using Virtus or SmartProperty as outlets?
I've done a bit of Googling, but couldn't find anything on this. I'd like to use something like SmartProperties (for lightweight situations) or Virtus (when I absolutely must have industrial-strength validations, etc) as outlets. My experiments, such as they are, aren't helping me any! What, if anything, am I doing wrong? My experiments are basically: require 'virtue' class TestClass attribute :test_attr, String end And then I try to "wire" up a text field from IB to the attribute; the result? Nothing happens. Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings. But sometimes I'd like the "defaults" capability of Virtus & SmartProperty, and I'd definitely like the industrial-strength validations of Virtus when I'm working against the database. In MacRuby terms, am I addressing the right problem!? Did I miss something in my Googling? Thanks in advance! Carolyn
Hi Carolyn, I can't help with Virtus or SmartProperty, but I think for MacRuby to recognise an outlet in your code you need to use 'attr_accessor', not 'attribute'. Maybe you could use the various types of input fields to ensure the values are numbers or strings, and then query their stringValue or integerValue. Hope that helps. -- Stephen Horne On 21/11/2012, at 20:04, Carolyn Ann Grant <carolyn.ann.grant@gmail.com> wrote:
I've done a bit of Googling, but couldn't find anything on this. I'd like to use something like SmartProperties (for lightweight situations) or Virtus (when I absolutely must have industrial-strength validations, etc) as outlets. My experiments, such as they are, aren't helping me any! What, if anything, am I doing wrong?
My experiments are basically:
require 'virtue'
class TestClass attribute :test_attr, String end
And then I try to "wire" up a text field from IB to the attribute; the result? Nothing happens.
Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings. But sometimes I'd like the "defaults" capability of Virtus & SmartProperty, and I'd definitely like the industrial-strength validations of Virtus when I'm working against the database.
In MacRuby terms, am I addressing the right problem!? Did I miss something in my Googling?
Thanks in advance! Carolyn
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
Sorry - I didn't make that clear! You're right, Stephen: I'd like to Virtus' "attribute" or SmartProperty's "property" *instead* of attr_accessor. I can roll my own solution, but I'd like to not have to! (Besides laziness, and the strong possibility of introducing bugs into any solution I come up with, I really like the strong validations and coercions of Virtus - and it's useful for database entries. And it's already written and mostly debugged.) Thanks, Carolyn On Nov 21, 2012, at 6:46 PM, stephen horne <fatste@gmail.com> wrote:
Hi Carolyn,
I can't help with Virtus or SmartProperty, but I think for MacRuby to recognise an outlet in your code you need to use 'attr_accessor', not 'attribute'.
Maybe you could use the various types of input fields to ensure the values are numbers or strings, and then query their stringValue or integerValue.
Hope that helps. -- Stephen Horne
On 21/11/2012, at 20:04, Carolyn Ann Grant <carolyn.ann.grant@gmail.com> wrote:
I've done a bit of Googling, but couldn't find anything on this. I'd like to use something like SmartProperties (for lightweight situations) or Virtus (when I absolutely must have industrial-strength validations, etc) as outlets. My experiments, such as they are, aren't helping me any! What, if anything, am I doing wrong?
My experiments are basically:
require 'virtue'
class TestClass attribute :test_attr, String end
And then I try to "wire" up a text field from IB to the attribute; the result? Nothing happens.
Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings. But sometimes I'd like the "defaults" capability of Virtus & SmartProperty, and I'd definitely like the industrial-strength validations of Virtus when I'm working against the database.
In MacRuby terms, am I addressing the right problem!? Did I miss something in my Googling?
Thanks in advance! Carolyn
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
"Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings." Can't you use Ruby services like is_a? to force it ? Thanks, David Kramf On Nov 21, 2012, at 10:04 PM, Carolyn Ann Grant wrote:
Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings.
What happens if you use BOTH attr_accessor and attribute - the first for the IB outlet, and the other for validation. Just a thought. On Nov 21, 2012, at 11:08 PM, david kramf <dakr.012@gmail.com> wrote:
"Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings." Can't you use Ruby services like is_a? to force it ? Thanks, David Kramf On Nov 21, 2012, at 10:04 PM, Carolyn Ann Grant wrote:
Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings.
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
I think that discussions about validation of user entered data need to consider how you provide feedback to the user on what happened. Have you thought about how validation errors are integrated with Cocoa frameworks? I don't know anything about Virtus or SmartProperties but I would be surprised if they buy you anything when used in conjunction with a Cocoa user interface. Cocoa provides formatters. Take a look at "Text Field with Number Formatter" in the Xcode controls. Steve On 22 Nov 2012, at 06:47, Colin Thomas-Arnold <colinta@gmail.com> wrote:
What happens if you use BOTH attr_accessor and attribute - the first for the IB outlet, and the other for validation. Just a thought.
On Nov 21, 2012, at 11:08 PM, david kramf <dakr.012@gmail.com> wrote:
"Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings." Can't you use Ruby services like is_a? to force it ? Thanks, David Kramf On Nov 21, 2012, at 10:04 PM, Carolyn Ann Grant wrote:
Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings.
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
Hmm… I didn't think of either of those. I knew I was missing something obvious! A case of missing the wood for the trees, I think. :-) Thanks, Colin and Steve! /Carolyn On Nov 22, 2012, at 4:51 AM, Steve Clarke <steve@sclarkes.me.uk> wrote:
I think that discussions about validation of user entered data need to consider how you provide feedback to the user on what happened.
Have you thought about how validation errors are integrated with Cocoa frameworks? I don't know anything about Virtus or SmartProperties but I would be surprised if they buy you anything when used in conjunction with a Cocoa user interface. Cocoa provides formatters. Take a look at "Text Field with Number Formatter" in the Xcode controls.
Steve
On 22 Nov 2012, at 06:47, Colin Thomas-Arnold <colinta@gmail.com> wrote:
What happens if you use BOTH attr_accessor and attribute - the first for the IB outlet, and the other for validation. Just a thought.
On Nov 21, 2012, at 11:08 PM, david kramf <dakr.012@gmail.com> wrote:
"Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings." Can't you use Ruby services like is_a? to force it ? Thanks, David Kramf On Nov 21, 2012, at 10:04 PM, Carolyn Ann Grant wrote:
Basically, I need to make sure that when I ask for an integer, I get an integer. And when I want a string - I can reject anything but strings.
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
participants (5)
-
Carolyn Ann Grant
-
Colin Thomas-Arnold
-
david kramf
-
stephen horne
-
Steve Clarke