Class: Cubicle::Member
- Inherits:
-
Object
- Object
- Cubicle::Member
- Defined in:
- lib/cubicle/member.rb
Instance Attribute Summary collapse
-
#alias_list ⇒ Object
Returns the value of attribute alias_list.
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#expression_type ⇒ Object
Returns the value of attribute expression_type.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options(*args) ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #included_in?(list_of_member_names) ⇒ Boolean
-
#initialize(*args) ⇒ Member
constructor
A new instance of Member.
- #matches(member_name) ⇒ Object
- #to_js_keys ⇒ Object
- #to_js_value ⇒ Object
Constructor Details
#initialize(*args) ⇒ Member
Returns a new instance of Member.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cubicle/member.rb', line 10 def initialize(*args) opts = args. @name = args.shift.to_sym if args[0].is_a?(String) or args[0].is_a?(Symbol) self. = (opts || {}).symbolize_keys if (@expression = self..delete(:field_name)) @expression_type = :field_name elsif (@expression = self..delete(:expression)) @expression_type = :javascript else @expression = @name @expression_type = :field_name end member_alias = self.[:alias] if (member_alias) member_alias = [member_alias] unless member_alias.is_a?(Array) @alias_list = member_alias.map{|a|a.to_s} end end |
Instance Attribute Details
#alias_list ⇒ Object
Returns the value of attribute alias_list.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def alias_list @alias_list end |
#expression ⇒ Object
Returns the value of attribute expression.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def expression @expression end |
#expression_type ⇒ Object
Returns the value of attribute expression_type.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def expression_type @expression_type end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def name @name end |
#options(*args) ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/cubicle/member.rb', line 4 def @options end |
Instance Method Details
#included_in?(list_of_member_names) ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/cubicle/member.rb', line 42 def included_in?(list_of_member_names) list_of_member_names.each do |member_name| return true if matches(member_name) end false end |
#matches(member_name) ⇒ Object
38 39 40 |
# File 'lib/cubicle/member.rb', line 38 def matches(member_name) return name.to_s == member_name.to_s || (@alias_list||=[]).include?(member_name.to_s) end |
#to_js_keys ⇒ Object
49 50 51 |
# File 'lib/cubicle/member.rb', line 49 def to_js_keys ["#{name}:#{to_js_value}"] end |
#to_js_value ⇒ Object
53 54 55 56 |
# File 'lib/cubicle/member.rb', line 53 def to_js_value prefix, suffix = expression_type == :field_name ? ['this.',''] : ['(',')'] "#{prefix}#{expression}#{suffix}" end |