Module: Dataclips

Defined in:
lib/dataclips.rb,
lib/dataclips/engine.rb,
lib/dataclips/version.rb,
app/models/dataclips/clip.rb,
app/models/dataclips/insight.rb,
app/models/dataclips/sql_query.rb,
app/helpers/dataclips/application_helper.rb,
app/controllers/dataclips/clips_controller.rb,
app/controllers/dataclips/insights_controller.rb,
app/controllers/dataclips/application_controller.rb
more...

Defined Under Namespace

Modules: ApplicationHelper Classes: ApplicationController, Clip, ClipsController, Engine, Insight, InsightsController, SQLQuery

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.hashidsObject

[View source]

42
43
44
# File 'lib/dataclips.rb', line 42

def hashids
  @hashids ||= Hashids.new(Dataclips::Engine.config.salt, 8)
end

.reload!Object

[View source]

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dataclips.rb', line 16

def reload!
  Dir.glob("#{Dataclips::Engine.config.path}/*.sql") do |clip_path|
    clip_id = clip_path.match(/(\w+).sql/)[1]
    Rails.logger.debug "reloading: #{clip_id}"

    remove_const(clip_id.camelize) if const_defined?(clip_id.camelize)

    sql = SQLQuery.new File.read(clip_path)

    klass = Class.new(Clip) do
      @template  = sql.template
      @schema    = sql.schema
      @per_page  = sql.options["per_page"]
      @variables = sql.variables

      attr_accessor *sql.variables.keys

      sql.variables.each do |key, options|
        validates key, date: options[:type] == "date"
      end
    end

    const_set(clip_id.camelize, klass)
  end
end