Module: GoogleSpreadsheets::Enhanced::NamespacePreservable

Extended by:
ActiveSupport::Concern
Included in:
Row, Spreadsheet, Worksheet
Defined in:
lib/google_spreadsheets/enhanced/namespace_preservable.rb

Defined Under Namespace

Modules: ClassMethods Classes: Format

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *arguments) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 113

def method_missing(method_symbol, *arguments)
  method_name = method_symbol.to_s

  if (matches = method_name.match(/(=)$/)) && attributes.include?("gsx:#{matches.pre_match}")
    attributes["gsx:#{matches.pre_match}"] = arguments.first
  elsif (matches = method_name.match(/(\?)$/)) && attributes.include?("gsx:#{matches.pre_match}")
    attributes["gsx:#{matches.pre_match}"]
  elsif attributes.include?("gsx:#{method_name}")
    attributes["gsx:#{method_name}"]
  else
    super
  end
end

Instance Method Details

#aliased_attributes ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 94

def aliased_attributes
  aliased = _attr_aliases.invert
  gsx_attributes = self.attributes.keys.map do |attr|
    if matches = attr.match(/^(gsx:)/)
      (aliased[matches.post_match] || matches.post_match).to_s
    else
      nil
    end
  end.compact
  (self.class.known_attributes + gsx_attributes).uniq
end

#respond_to?(method, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
110
111
# File 'lib/google_spreadsheets/enhanced/namespace_preservable.rb', line 106

def respond_to?(method, include_priv = false)
  method_name = method.to_s
  ((matches = method_name.match(/(=|\?)$/)) && attributes.include?("gsx:#{matches.pre_match}")) ||
  attributes.include?("gsx:#{method_name}") ||
  super
end