Class: Rodsec::RuleSet

Inherits:
Object
  • Object
show all
Includes:
StringPointers
Defined in:
lib/rodsec/rule_set.rb

Constant Summary

Constants included from StringPointers

StringPointers::EMPTY_STRING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringPointers

#strptr

Constructor Details

#initialize(tag: nil) ⇒ RuleSet

Returns a new instance of RuleSet.



8
9
10
11
12
13
14
15
16
# File 'lib/rodsec/rule_set.rb', line 8

def initialize tag: nil
  @tag = tag

  @rules_ptr = Wrapper.msc_create_rules_set
  @rules_ptr.free = Wrapper['msc_rules_cleanup']

  # just mirroring the c-api, not sure if it's actually useful
  @rule_count = 0
end

Instance Attribute Details

#rule_countObject (readonly)

Returns the value of attribute rule_count.



21
22
23
# File 'lib/rodsec/rule_set.rb', line 21

def rule_count
  @rule_count
end

#rules_ptrObject (readonly)

srsly, don’t mess with this



19
20
21
# File 'lib/rodsec/rule_set.rb', line 19

def rules_ptr
  @rules_ptr
end

#tagObject (readonly)

Returns the value of attribute tag.



21
22
23
# File 'lib/rodsec/rule_set.rb', line 21

def tag
  @tag
end

Instance Method Details

#add(rules_text) ⇒ Object

Raises:



43
44
45
46
47
48
49
# File 'lib/rodsec/rule_set.rb', line 43

def add rules_text
  err = Fiddle::Pointer[0]
  rv = Wrapper.msc_rules_add rules_ptr, (strptr rules_text.to_s), err.ref
  raise Error, err.to_s if rv < 0
  @rule_count += rv
  self
end

#add_file(conf_pathname) ⇒ Object

add rules from the given file return number of rules added? I think?

Raises:



27
28
29
30
31
32
33
34
35
# File 'lib/rodsec/rule_set.rb', line 27

def add_file conf_pathname
  conf_pathname = Pathname conf_pathname
  err = Fiddle::Pointer[0]
  rv = Wrapper.msc_rules_add_file rules_ptr, (strptr conf_pathname.realpath.to_s), err.ref

  raise Error, [conf_pathname, err.to_s] if rv < 0
  @rule_count += rv
  self
end

#add_url(key, url) ⇒ Object

Raises:



51
52
53
54
55
56
57
# File 'lib/rodsec/rule_set.rb', line 51

def add_url key, url
  err = Fiddle::Pointer[0]
  rv = Wrapper.msc_rules_add_remote rules_ptr, (strptr key), (strptr uri), err.ref
  raise Error, err.to_s if rv < 0
  @rule_count += rv
  self
end

#dumpObject

dump rules to stdout. No way to redirect that, from what I can see.



38
39
40
41
# File 'lib/rodsec/rule_set.rb', line 38

def dump
  Wrapper.msc_rules_dump rules_ptr
  self
end

#merge(other) ⇒ Object

merge other rules with self

Raises:



60
61
62
63
64
65
66
67
# File 'lib/rodsec/rule_set.rb', line 60

def merge other
  raise "must be a #{self.class.name}" unless self.class === other
  err = Fiddle::Pointer[0]
  rv = Wrapper.msc_rules_merge rules_ptr, other.rules_ptr, err.ref
  @rule_count += rv
  raise Error, err.to_s if rv < 0
  self
end