Module: Gamifier
- Defined in:
- lib/gamifier.rb,
lib/gamifier/dsl.rb,
lib/gamifier/model.rb,
lib/gamifier/engine.rb,
lib/gamifier/errors.rb,
lib/gamifier/version.rb,
lib/gamifier/dsl/site.rb,
lib/gamifier/collection.rb,
lib/gamifier/dsl/api_key.rb,
lib/gamifier/dsl/network.rb,
lib/gamifier/models/site.rb,
lib/gamifier/models/unit.rb,
lib/gamifier/models/user.rb,
lib/gamifier/models/group.rb,
lib/gamifier/models/track.rb,
lib/gamifier/models/player.rb,
lib/gamifier/models/reward.rb,
lib/gamifier/models/api_key.rb,
lib/gamifier/models/network.rb,
lib/gamifier/models/activity.rb,
lib/gamifier/models/reward_definition.rb,
lib/gamifier/models/activity_definition.rb
Defined Under Namespace
Modules: DSL Classes: Activity, ActivityDefinition, ApiKey, Collection, Engine, Error, Group, HTTPClientError, HTTPError, HTTPServerError, Model, Network, Player, Reward, RewardDefinition, Site, Track, Unit, User
Constant Summary collapse
- VERSION =
"1.1.3"
Class Attribute Summary collapse
Class Method Summary collapse
-
.config ⇒ Object
Returns the configuration Hash.
-
.dsl(&block) ⇒ Object
Creates and returns a new DSL::Network object.
-
.engine(&block) ⇒ Object
Returns the global Engine.
- .reset! ⇒ Object
-
.set(key, opts = nil) ⇒ Object
Sets a configuration option.
- .underscore(camel_cased_word) ⇒ Object
Class Attribute Details
.logger ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/gamifier.rb', line 51 def logger @logger ||= begin l = Logger.new(STDERR) l.level = Logger::WARN l end end |
Class Method Details
.config ⇒ Object
Returns the configuration Hash.
22 23 24 |
# File 'lib/gamifier.rb', line 22 def config @config ||= {} end |
.dsl(&block) ⇒ Object
Creates and returns a new DSL::Network object. The given block will be evaluated in the context of the network object.
Usage:
network = Gamifier.dsl do
site 'my-site' do
set :url, 'my-site.com'
...
end
end
46 47 48 49 |
# File 'lib/gamifier.rb', line 46 def dsl(&block) network = DSL::Network.new DSL.eval_with_context(network, &block) end |
.engine(&block) ⇒ Object
Returns the global Engine. If you need multiple engine with different API keys and/or URIs, you should create a new engine directly with Gamifier::Engine.new
29 30 31 32 33 |
# File 'lib/gamifier.rb', line 29 def engine(&block) @engine ||= Engine.new block.call(@engine) if block @engine end |
.reset! ⇒ Object
59 60 61 62 |
# File 'lib/gamifier.rb', line 59 def reset! @engine = nil config.clear end |
.set(key, opts = nil) ⇒ Object
Sets a configuration option. The keys will be symbolized.
11 12 13 14 15 16 17 18 19 |
# File 'lib/gamifier.rb', line 11 def set(key, opts = nil) if opts.nil? key.each do |k,v| config[k.to_sym] = v end else config[key.to_sym] = opts end end |
.underscore(camel_cased_word) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/gamifier.rb', line 64 def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/'). gsub("Gamifier/", ''). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |