Class: GMaps

Inherits:
Object
  • Object
show all
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

Modules: Rails Classes: JS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GMaps

Returns a new instance of GMaps.



14
15
16
17
# File 'lib/gmaps.rb', line 14

def initialize(options={})
  @map = options
  @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

#directivesObject

Returns the value of attribute directives.



12
13
14
# File 'lib/gmaps.rb', line 12

def directives
  @directives
end

#mapObject

Returns the value of attribute map.



12
13
14
# File 'lib/gmaps.rb', line 12

def map
  @map
end

#nameObject



23
24
25
# File 'lib/gmaps.rb', line 23

def name
  @name ||= @map[:div] ? @map[:div].gsub(/[#\.]/, '') : 'map'
end

Class Method Details

.[](*args) ⇒ Object



7
8
9
# File 'lib/gmaps.rb', line 7

def [](*args)
  GMaps.new(*args)
end

Instance Method Details

#to_jsObject



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_sObject



37
38
39
# File 'lib/gmaps.rb', line 37

def to_s
  {map: @map, directives: @directives}._to_s19
end