Class: GMaps
- Inherits:
-
Object
- Object
- GMaps
- Defined in:
- lib/gmaps.rb,
lib/gmaps/js.rb,
lib/gmaps/rails.rb,
lib/gmaps/rails/engine.rb,
lib/gmaps/rails/railtie.rb,
lib/gmaps/rails/version.rb,
lib/gmaps/rails/view_helpers.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#directives ⇒ Object
Returns the value of attribute directives.
-
#map ⇒ Object
Returns the value of attribute map.
- #name ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GMaps
constructor
A new instance of GMaps.
- #method_missing(m, *args) ⇒ Object
- #to_js ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GMaps
Returns a new instance of GMaps.
14 15 16 17 |
# File 'lib/gmaps.rb', line 14 def initialize(={}) @map = @directives = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
19 20 21 |
# File 'lib/gmaps.rb', line 19 def method_missing(m, *args) @directives << {name: m, args: args} end |
Instance Attribute Details
#directives ⇒ Object
Returns the value of attribute directives.
12 13 14 |
# File 'lib/gmaps.rb', line 12 def directives @directives end |
#map ⇒ Object
Returns the value of attribute map.
12 13 14 |
# File 'lib/gmaps.rb', line 12 def map @map end |
#name ⇒ Object
23 24 25 |
# File 'lib/gmaps.rb', line 23 def name @name ||= @map[:div] ? @map[:div].gsub(/[#\.]/, '') : 'map' end |
Class Method Details
Instance Method Details
#to_js ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/gmaps.rb', line 28 def to_js ("var #{name} = GMaps(#{{div: '#map'}.merge!(@map)._to_s19});\n" + @directives.map{ |directive| func = directive[:name] args = directive[:args] "#{name}.#{func}(#{args.map{|e| e._to_s19}.join(', ')})" }.join(";\n")).html_safe end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/gmaps.rb', line 37 def to_s {map: @map, directives: @directives}._to_s19 end |